@wonderwhy-er/desktop-commander 0.3.2-alpha.1 → 0.3.2-alpha.3

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 (56) hide show
  1. package/dist/bootstrap.js +7 -7
  2. package/dist/command-manager.d.ts +98 -1
  3. package/dist/command-manager.js +200 -16
  4. package/dist/remote-device/desktop-commander-integration.js +3 -1
  5. package/dist/remote-device/diagnostics/redact.js +30 -8
  6. package/dist/remote-device/diagnostics/report.js +30 -13
  7. package/dist/remote-device/mqtt/mqtt-enrollment.js +1 -1
  8. package/dist/remote-device/mqtt/mqtt-transport.js +2 -2
  9. package/dist/remote-device/remote-channel.d.ts +1 -1
  10. package/dist/remote-device/remote-channel.js +1 -1
  11. package/dist/remote-device/transport-telemetry.js +5 -4
  12. package/dist/server.js +2 -0
  13. package/dist/terminal-manager.js +4 -6
  14. package/dist/tools/improved-process-tools.d.ts +2 -0
  15. package/dist/tools/improved-process-tools.js +68 -40
  16. package/dist/tools/pdf/markdown.js +7 -3
  17. package/dist/tools/process.js +10 -2
  18. package/dist/track-installation.js +2 -2
  19. package/dist/ui/file-preview/preview-runtime.js +145 -138
  20. package/dist/utils/brace-expansion.d.ts +25 -0
  21. package/dist/utils/brace-expansion.js +171 -0
  22. package/dist/utils/capture.d.ts +8 -2
  23. package/dist/utils/capture.js +1 -1
  24. package/dist/utils/cmd-commands.d.ts +3 -0
  25. package/dist/utils/cmd-commands.js +322 -0
  26. package/dist/utils/command-reading.d.ts +78 -0
  27. package/dist/utils/command-reading.js +7 -0
  28. package/dist/utils/command-wrappers.d.ts +45 -0
  29. package/dist/utils/command-wrappers.js +941 -0
  30. package/dist/utils/inline-shells.d.ts +64 -0
  31. package/dist/utils/inline-shells.js +290 -0
  32. package/dist/utils/posix-commands.d.ts +3 -0
  33. package/dist/utils/posix-commands.js +201 -0
  34. package/dist/utils/powershell-commands.d.ts +60 -0
  35. package/dist/utils/powershell-commands.js +420 -0
  36. package/dist/utils/process-tree.js +4 -4
  37. package/dist/utils/shell-script-files.d.ts +4 -0
  38. package/dist/utils/shell-script-files.js +121 -0
  39. package/dist/utils/shell.d.ts +36 -0
  40. package/dist/utils/shell.js +69 -0
  41. package/dist/utils/system-info.d.ts +2 -0
  42. package/dist/utils/system-info.js +5 -1
  43. package/dist/utils/threadpool-size.d.ts +36 -0
  44. package/dist/utils/threadpool-size.js +143 -0
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.js +1 -1
  47. package/package.json +11 -9
  48. package/node_modules/@desktop-commander/telemetry-contract/README.md +0 -56
  49. package/node_modules/@desktop-commander/telemetry-contract/package.json +0 -32
  50. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +0 -39
  51. package/node_modules/@desktop-commander/telemetry-contract/transport.js +0 -167
  52. package/vendor/telemetry-contract/README.md +0 -56
  53. package/vendor/telemetry-contract/package.json +0 -32
  54. package/vendor/telemetry-contract/transport.d.ts +0 -38
  55. package/vendor/telemetry-contract/transport.js +0 -164
  56. package/vendor/telemetry-contract/transport.test.js +0 -39
@@ -123,6 +123,14 @@ export function getCommandEnvironment() {
123
123
  }
124
124
  return env;
125
125
  }
126
+ /**
127
+ * The environment of the shell start_process runs a command in: the
128
+ * command environment, with TERM for better terminal compatibility. The
129
+ * PowerShell helper starts with it too, so the user's profile sees the same.
130
+ */
131
+ export function getShellEnvironment() {
132
+ return { ...getCommandEnvironment(), TERM: 'xterm-256color' };
133
+ }
126
134
  /**
127
135
  * The shell used when the user hasn't configured one.
128
136
  * Windows: Windows PowerShell, falling back to %ComSpec%.
@@ -179,6 +187,67 @@ export function detectAvailableShells() {
179
187
  }
180
188
  return [...shells];
181
189
  }
190
+ // WSL's entry in binfmt_misc that lets Linux run Windows programs. Distros that run systemd get it late, under the second name
191
+ const WSL_INTEROP_ENTRIES = ['/proc/sys/fs/binfmt_misc/WSLInterop', '/proc/sys/fs/binfmt_misc/WSLInterop-late'];
192
+ let wslInterop = false; // true once the entry was found
193
+ /**
194
+ * Whether this is WSL, which runs Windows programs from Linux. WSL sets
195
+ * WSL_DISTRO_NAME for what it starts. What runs without it, through sudo
196
+ * (which clears the environment) or as a service, is known by WSL's interop
197
+ * entry. Once found it is remembered; while missing it is looked for again,
198
+ * since WSL can register it again after it was gone. A Docker container on
199
+ * WSL's kernel has no such entry and can't run Windows programs.
200
+ */
201
+ function isWsl() {
202
+ if (process.env.WSL_DISTRO_NAME)
203
+ return true;
204
+ wslInterop || (wslInterop = WSL_INTEROP_ENTRIES.some((entry) => fs.existsSync(entry)));
205
+ return wslInterop;
206
+ }
207
+ /**
208
+ * A program's name without its folder or extension, lowercased:
209
+ * C:\Windows\System32\NET.EXE is "net". The folder goes as Windows writes it
210
+ * (\ or /, or a drive, as in C:sc.exe). POSIX shells outside Windows use
211
+ * only / as a folder separator. The extension is .ps1
212
+ * (PowerShell runs deploy.ps1 for deploy), or on Windows one of PATHEXT's as
213
+ * commands run with it (repaired, #481). WSL runs Windows programs from Linux
214
+ * (sc.exe stop Spooler), so there too. The command check compares the names it
215
+ * finds and the blockedCommands entries in this form. POSIX shells on
216
+ * Windows still accept Windows paths, as Git Bash does.
217
+ */
218
+ export function programName(name, shellType) {
219
+ const paths = shellType === 'posix' && !isWindows() ? path.posix : path.win32;
220
+ const program = paths.basename(name).toLowerCase();
221
+ const extensions = ['.ps1', ...(isWindows() || isWsl() ? getRepairedPathExt().split(';') : [])]
222
+ .map((ext) => ext.trim().toLowerCase());
223
+ const extension = paths.extname(program);
224
+ return extension && extensions.includes(extension) ? program.slice(0, -extension.length) : program;
225
+ }
226
+ /**
227
+ * Which kind of shell a shell program is, by its name without folder and
228
+ * lowercased, as getShellSpawnArgs() reads it: pwsh and powershell (with or
229
+ * without .exe) are PowerShell, cmd and cmd.exe are cmd, and every other shell
230
+ * (bash, zsh, sh, dash, ksh, fish) is POSIX. getShellSpawnArgs() starts each
231
+ * kind its own way.
232
+ */
233
+ export function getShellType(shell) {
234
+ const name = path.basename(shell).toLowerCase();
235
+ if (['pwsh', 'pwsh.exe', 'powershell', 'powershell.exe'].includes(name))
236
+ return 'powershell';
237
+ if (name === 'cmd' || name === 'cmd.exe')
238
+ return 'cmd';
239
+ return 'posix';
240
+ }
241
+ /** The POSIX shells (and fish) by programName(): each runs a script file it's given (bash deploy.sh) */
242
+ export const POSIX_SHELLS = new Set(['bash', 'sh', 'dash', 'zsh', 'ksh', 'ksh93', 'mksh', 'ash', 'fish']);
243
+ /**
244
+ * The shell start_process runs a command in: the one asked for, else the
245
+ * defaultShell setting, else this machine's default. The command check reads
246
+ * the command with the same shell.
247
+ */
248
+ export function getCommandShell(shell, defaultShell) {
249
+ return shell || defaultShell || getDefaultShell();
250
+ }
182
251
  /**
183
252
  * Get the appropriate spawn configuration for a given shell
184
253
  * This handles login shell flags for different shell types
@@ -54,6 +54,8 @@ export interface SystemInfo {
54
54
  accessible?: string[];
55
55
  };
56
56
  }
57
+ /** True in Desktop Commander's Docker image, whose Dockerfile sets MCP_CLIENT_DOCKER=true */
58
+ export declare function isDockerImage(): boolean;
57
59
  /**
58
60
  * Get comprehensive system information for tool prompts
59
61
  */
@@ -3,13 +3,17 @@ import fs from 'fs';
3
3
  import path from 'path';
4
4
  import { execFileSync } from 'child_process';
5
5
  import { getDefaultShell, resolveShellPath } from './shell.js';
6
+ /** True in Desktop Commander's Docker image, whose Dockerfile sets MCP_CLIENT_DOCKER=true */
7
+ export function isDockerImage() {
8
+ return process.env.MCP_CLIENT_DOCKER === 'true';
9
+ }
6
10
  /**
7
11
  * Detect container environment and type
8
12
  */
9
13
  function detectContainerEnvironment() {
10
14
  // Method 1: Check environment variables first (most reliable when set)
11
15
  // Docker-specific
12
- if (process.env.MCP_CLIENT_DOCKER === 'true') {
16
+ if (isDockerImage()) {
13
17
  return { isContainer: true, containerType: 'docker', orchestrator: null };
14
18
  }
15
19
  // Kubernetes detection
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Sizing libuv's thread pool from inside the process.
3
+ *
4
+ * libuv reads UV_THREADPOOL_SIZE once, when the pool starts (on the first
5
+ * submitted work). Up to libuv 1.51 (Node 22) it reads it with the C runtime's
6
+ * getenv(). On Windows the C runtime keeps its own copy of the environment,
7
+ * taken when the process started, and process.env changes the process's
8
+ * environment, not that copy: libuv never sees the new value and starts its
9
+ * default 4 threads. libuv 1.52 (Node 24) reads the process's environment
10
+ * (uv_os_getenv), and on macOS and Linux getenv() always does.
11
+ *
12
+ * Where libuv can't see process.env, the only way to size the pool is to start
13
+ * the process again with the variable in its environment.
14
+ */
15
+ /** In the copy that setThreadpoolSize() starts: the process ID of the process that started it */
16
+ export declare const LAUNCHER_PID_VARIABLE = "DESKTOP_COMMANDER_THREADPOOL_LAUNCHER_PID";
17
+ /** Kept in the OS command line so diagnostics can distinguish a copy from an independent nested server. */
18
+ export declare const LAUNCHER_PID_ARGUMENT = "--desktop-commander-threadpool-launcher-pid=";
19
+ /** Whether libuv sees a UV_THREADPOOL_SIZE set in process.env: everywhere but on Windows with a libuv before 1.52 */
20
+ export declare function processEnvReachesThreadpool(platform?: string, uvVersion?: string): boolean;
21
+ /**
22
+ * Gives libuv's thread pool `size` threads (a UV_THREADPOOL_SIZE value). Call
23
+ * it before any thread-pool work, before anything else sets the variable.
24
+ *
25
+ * - If process.env already has this value, it was there when Node started,
26
+ * and libuv reads it: nothing to do.
27
+ * - Where libuv sees process.env (`envReachesThreadpool`), it sets the variable there.
28
+ * - Elsewhere it runs this process again: the same Node, options, script and
29
+ * arguments, stdin, stdout and stderr, with the variable in the copy's
30
+ * environment. It waits for the copy and exits with the copy's exit code, so
31
+ * this process runs none of the code after the call. If the copy can't
32
+ * start, it returns, and the pool keeps libuv's default size.
33
+ * - In that copy, it only makes sure the copy ends when the process that
34
+ * started it is gone.
35
+ */
36
+ export declare function setThreadpoolSize(size: string, envReachesThreadpool?: boolean): void;
@@ -0,0 +1,143 @@
1
+ import { spawnSync } from 'child_process';
2
+ import { createConnection, createServer } from 'net';
3
+ import { randomUUID } from 'crypto';
4
+ import { unlinkSync } from 'fs';
5
+ import { tmpdir } from 'os';
6
+ import { join, dirname, basename } from 'path';
7
+ import { exitProcess } from './exit-process.js';
8
+ /**
9
+ * Sizing libuv's thread pool from inside the process.
10
+ *
11
+ * libuv reads UV_THREADPOOL_SIZE once, when the pool starts (on the first
12
+ * submitted work). Up to libuv 1.51 (Node 22) it reads it with the C runtime's
13
+ * getenv(). On Windows the C runtime keeps its own copy of the environment,
14
+ * taken when the process started, and process.env changes the process's
15
+ * environment, not that copy: libuv never sees the new value and starts its
16
+ * default 4 threads. libuv 1.52 (Node 24) reads the process's environment
17
+ * (uv_os_getenv), and on macOS and Linux getenv() always does.
18
+ *
19
+ * Where libuv can't see process.env, the only way to size the pool is to start
20
+ * the process again with the variable in its environment.
21
+ */
22
+ /** In the copy that setThreadpoolSize() starts: the process ID of the process that started it */
23
+ export const LAUNCHER_PID_VARIABLE = 'DESKTOP_COMMANDER_THREADPOOL_LAUNCHER_PID';
24
+ /** Kept in the OS command line so diagnostics can distinguish a copy from an independent nested server. */
25
+ export const LAUNCHER_PID_ARGUMENT = '--desktop-commander-threadpool-launcher-pid=';
26
+ /** A unique OS endpoint belongs to the original launcher, even if its PID is reused. */
27
+ const LAUNCHER_CHANNEL_VARIABLE = 'DESKTOP_COMMANDER_THREADPOOL_LAUNCHER_CHANNEL';
28
+ /** Whether libuv sees a UV_THREADPOOL_SIZE set in process.env: everywhere but on Windows with a libuv before 1.52 */
29
+ export function processEnvReachesThreadpool(platform = process.platform, uvVersion = process.versions.uv) {
30
+ if (platform !== 'win32')
31
+ return true;
32
+ const [major, minor] = uvVersion.split('.').map(Number);
33
+ return major > 1 || (major === 1 && minor >= 52);
34
+ }
35
+ /**
36
+ * Gives libuv's thread pool `size` threads (a UV_THREADPOOL_SIZE value). Call
37
+ * it before any thread-pool work, before anything else sets the variable.
38
+ *
39
+ * - If process.env already has this value, it was there when Node started,
40
+ * and libuv reads it: nothing to do.
41
+ * - Where libuv sees process.env (`envReachesThreadpool`), it sets the variable there.
42
+ * - Elsewhere it runs this process again: the same Node, options, script and
43
+ * arguments, stdin, stdout and stderr, with the variable in the copy's
44
+ * environment. It waits for the copy and exits with the copy's exit code, so
45
+ * this process runs none of the code after the call. If the copy can't
46
+ * start, it returns, and the pool keeps libuv's default size.
47
+ * - In that copy, it only makes sure the copy ends when the process that
48
+ * started it is gone.
49
+ */
50
+ export function setThreadpoolSize(size, envReachesThreadpool = processEnvReachesThreadpool()) {
51
+ const launcherPid = process.env[LAUNCHER_PID_VARIABLE];
52
+ const launcherChannel = process.env[LAUNCHER_CHANNEL_VARIABLE];
53
+ // A complete private channel/argument pair survives reparenting; PID-only inherited markers still need our parent.
54
+ delete process.env[LAUNCHER_PID_VARIABLE];
55
+ delete process.env[LAUNCHER_CHANNEL_VARIABLE];
56
+ if (launcherPid && process.argv.at(-1) === `${LAUNCHER_PID_ARGUMENT}${launcherPid}` &&
57
+ (launcherPid === String(process.ppid) || launcherChannel)) {
58
+ process.argv.pop();
59
+ exitWithLauncher(launcherChannel);
60
+ return;
61
+ }
62
+ if (process.env.UV_THREADPOOL_SIZE === size)
63
+ return;
64
+ process.env.UV_THREADPOOL_SIZE = size;
65
+ // A debugger stays on the process Node started, which would only wait for the
66
+ // copy, and the copy couldn't open the same inspector port
67
+ const debugging = [...process.execArgv, process.env.NODE_OPTIONS ?? ''].some((option) => option.includes('--inspect'));
68
+ if (envReachesThreadpool || debugging)
69
+ return;
70
+ const lifetime = launcherLifetime();
71
+ if (!lifetime)
72
+ return;
73
+ const copyArgs = [...process.execArgv, ...process.argv.slice(1), `${LAUNCHER_PID_ARGUMENT}${process.pid}`];
74
+ const copy = spawnSync(process.execPath, copyArgs, {
75
+ stdio: 'inherit',
76
+ env: {
77
+ ...process.env,
78
+ [LAUNCHER_PID_VARIABLE]: String(process.pid),
79
+ [LAUNCHER_CHANNEL_VARIABLE]: lifetime.endpoint,
80
+ },
81
+ });
82
+ lifetime.close();
83
+ if (copy.error)
84
+ return;
85
+ // process.exit(), not exitProcess(): this process must stop here, without
86
+ // running the rest of its code; the copy has run it
87
+ process.exit(copy.status ?? 1);
88
+ }
89
+ /**
90
+ * Ends the copy once the process that started it is gone. A client stops a
91
+ * server by ending the process it started; without this, the copy, which does
92
+ * the server's work, would keep running.
93
+ */
94
+ function exitWithLauncher(endpoint) {
95
+ if (!endpoint) {
96
+ exitProcess(1);
97
+ return;
98
+ }
99
+ const channel = createConnection(endpoint);
100
+ let ended = false;
101
+ const finish = () => {
102
+ if (ended)
103
+ return;
104
+ ended = true;
105
+ channel.destroy();
106
+ removeLifetimeEndpoint(endpoint);
107
+ exitProcess(1);
108
+ };
109
+ channel.once('end', finish);
110
+ channel.once('error', finish);
111
+ channel.unref();
112
+ channel.resume();
113
+ }
114
+ /** Binding happens before spawnSync blocks; the OS closes this endpoint when its owner dies. */
115
+ function launcherLifetime() {
116
+ const name = `dc-tp-${randomUUID()}`;
117
+ const endpoint = process.platform === 'win32' ? `\\\\.\\pipe\\${name}` : join(tmpdir(), name);
118
+ const server = createServer();
119
+ // A failed bind falls back without a copy; no asynchronous error may crash that fallback.
120
+ server.on('error', () => { });
121
+ server.listen(endpoint);
122
+ const close = () => {
123
+ server.close();
124
+ removeLifetimeEndpoint(endpoint);
125
+ };
126
+ if (!server.listening) {
127
+ close();
128
+ return undefined;
129
+ }
130
+ return { endpoint, close };
131
+ }
132
+ /** A killed Unix launcher cannot unlink its socket; its copy removes only our temporary socket name. */
133
+ function removeLifetimeEndpoint(endpoint) {
134
+ if (process.platform === 'win32' || dirname(endpoint) !== tmpdir() ||
135
+ !/^dc-tp-[0-9a-f-]{36}$/.test(basename(endpoint)))
136
+ return;
137
+ try {
138
+ unlinkSync(endpoint);
139
+ }
140
+ catch {
141
+ // The launcher may already have removed it; cleanup must not prevent the copy from exiting.
142
+ }
143
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.3.2-alpha.1";
1
+ export declare const VERSION = "0.3.2-alpha.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.3.2-alpha.1';
1
+ export const VERSION = '0.3.2-alpha.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wonderwhy-er/desktop-commander",
3
- "version": "0.3.2-alpha.1",
3
+ "version": "0.3.2-alpha.3",
4
4
  "description": "MCP server for terminal operations and file editing",
5
5
  "mcpName": "io.github.wonderwhy-er/desktop-commander",
6
6
  "license": "MIT",
@@ -23,8 +23,7 @@
23
23
  "files": [
24
24
  "dist",
25
25
  "logo.png",
26
- "testemonials",
27
- "vendor/telemetry-contract"
26
+ "testemonials"
28
27
  ],
29
28
  "scripts": {
30
29
  "postinstall": "node dist/track-installation.js && node dist/npm-scripts/verify-ripgrep.js || node -e \"process.exit(0)\"",
@@ -32,7 +31,6 @@
32
31
  "device:install": "cd src/remote-device && npm install",
33
32
  "device:start": "tsx src/remote-device/device.ts",
34
33
  "device:start:dev": "nodemon --watch src/remote-device --exec tsx src/remote-device/device.ts",
35
- "device:start:local": "npm run build && DC_ENV=development MCP_SERVER_URL=http://mcp.localhost:3007 npm run device:start:dev",
36
34
  "sync-version": "node scripts/sync-version.js",
37
35
  "bump": "node scripts/sync-version.js --bump",
38
36
  "bump:minor": "node scripts/sync-version.js --bump --minor",
@@ -47,9 +45,14 @@
47
45
  "prepare": "npm run build",
48
46
  "clean": "shx rm -rf dist",
49
47
  "test": "npm run build && node test/run-all-tests.js",
48
+ "test:changed": "npm run build && node test/run-all-tests.js --no-build --changed",
49
+ "test:ci": "npm run build && node test/run-ci.js",
50
+ "build:coverage": "npm run build && tsc -p tsconfig.coverage.json && node test/map-copied-scripts.js",
51
+ "test:coverage": "npm run build:coverage && node test/run-coverage.js",
50
52
  "test:integration": "npm run build && node test/integration/run-all-integration-tests.js",
51
53
  "test:transport:telemetry": "npm run build && node test/test-transport-telemetry.js",
52
54
  "test:debug": "node --inspect test/run-all-tests.js",
55
+ "review": "node test/ci-review.js run",
53
56
  "validate:tools": "npm run build && node scripts/validate-tools-sync.js",
54
57
  "link:local": "npm run build && npm link",
55
58
  "unlink:local": "npm unlink",
@@ -66,7 +69,8 @@
66
69
  "logs:clear": "npm run build && node scripts/clear-fuzzy-logs.js",
67
70
  "logs:export": "npm run build && node scripts/export-fuzzy-logs.js",
68
71
  "count-tokens": "npm run build && node scripts/count-tokens.js",
69
- "count-tokens:json": "npm run build && node scripts/count-tokens.js --json"
72
+ "count-tokens:json": "npm run build && node scripts/count-tokens.js --json",
73
+ "device:start:local": "npm run build && DC_ENV=development MCP_SERVER_URL=http://mcp.localhost:3007 npm run device:start:dev"
70
74
  },
71
75
  "publishConfig": {
72
76
  "access": "public"
@@ -91,7 +95,6 @@
91
95
  "file-operations"
92
96
  ],
93
97
  "dependencies": {
94
- "@desktop-commander/telemetry-contract": "file:vendor/telemetry-contract",
95
98
  "@modelcontextprotocol/sdk": "^1.32.1",
96
99
  "@opendocsg/pdf2md": "0.3.4",
97
100
  "@supabase/supabase-js": "^2.89.0",
@@ -123,14 +126,12 @@
123
126
  "remark-parse": "^11.0.0",
124
127
  "sharp": "^0.35.5",
125
128
  "tiptap-markdown": "^0.9.0",
129
+ "unbash": "6.0.1",
126
130
  "unified": "^11.0.5",
127
131
  "unpdf": "~1.8.1",
128
132
  "zod": "^3.24.1",
129
133
  "zod-to-json-schema": "^3.23.5"
130
134
  },
131
- "bundleDependencies": [
132
- "@desktop-commander/telemetry-contract"
133
- ],
134
135
  "optionalDependencies": {
135
136
  "caffeinate": "^1.0.1"
136
137
  },
@@ -141,6 +142,7 @@
141
142
  "@types/node-forge": "1.3.14",
142
143
  "@types/proper-lockfile": "^4.1.4",
143
144
  "aedes": "0.51.3",
145
+ "c8": "^12.0.0",
144
146
  "commander": "^13.1.0",
145
147
  "esbuild": "^0.27.2",
146
148
  "js-tiktoken": "^1.0.21",
@@ -1,56 +0,0 @@
1
- # @desktop-commander/telemetry-contract
2
-
3
- Transport observation request contract shared by telemetry-proxy and Remote MCP.
4
- Import it as `@desktop-commander/telemetry-contract/transport`.
5
-
6
- `parseRemoteTransportPayload(body)` validates 1–10 transport events for authenticated
7
- `/remote/collect` requests with a top-level `user_id`.
8
- `parseDeviceTransportPayload(body)` validates the same event shape for `/mp/collect`
9
- with a top-level `client_id` and an event `device_id`. It assigns `source=device`.
10
-
11
- Both functions return normalized events or throw before admitting any event. Event
12
- names may match `params.stage` or `params.transport`, preserving older transport-named
13
- events. Unknown and invalid optional parameters are removed. TypeScript declarations
14
- describe the transport payloads; ordinary device and command telemetry are outside
15
- this package.
16
-
17
- ## Make a contract change
18
-
19
- Edit `transport.js` and its matching `transport.d.ts` types, then update
20
- `transport.test.js`. Keep changes to ordinary device and command telemetry out
21
- of this package. From the telemetry-proxy root, run `npm test`, then commit and
22
- push the change for review.
23
-
24
- ## Publish a version
25
-
26
- 1. On a clean branch containing the reviewed changes, run this from the
27
- telemetry-proxy root for a compatible fix:
28
-
29
- ```sh
30
- cd packages/telemetry-contract
31
- npm version patch
32
- ```
33
-
34
- `preversion` checks for tracked changes and runs the contract test.
35
- `npm version` bumps `package.json`; the `version` script commits it and
36
- creates the tag using the prefix in this package's `.npmrc`. `postversion`
37
- pushes the commit and tag to `origin` together. If that push fails, fix the
38
- cause and push the existing commit and tag; do not run `npm version` again.
39
- Use `minor` for compatible additions or coordinate breaking changes with
40
- consumers before a `major` release.
41
-
42
- 2. Check the **Publish telemetry contract** GitHub Actions run. It verifies that
43
- the tag matches `package.json`, runs the package test, and publishes to
44
- GitHub Packages as `@desktop-commander/telemetry-contract@0.1.1`. Published
45
- versions cannot be overwritten; bump the version for another release.
46
- 3. In Remote MCP, with `GITHUB_PACKAGES_TOKEN` available to npm, update the
47
- pinned dependency and lockfile, then run its tests:
48
-
49
- ```sh
50
- npm install --save-exact @desktop-commander/telemetry-contract@0.1.1
51
- npm test
52
- ```
53
-
54
- Commit `package.json` and `package-lock.json` together. Remote MCP's Cloud
55
- Build uses `MCP_REMOTE_GITHUB_PACKAGES_TOKEN` from Secret Manager to install
56
- the private package. No tarball needs to be copied between repositories.
@@ -1,32 +0,0 @@
1
- {
2
- "name": "@desktop-commander/telemetry-contract",
3
- "version": "0.1.1",
4
- "type": "module",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/desktop-commander/telemetry-proxy.git",
8
- "directory": "packages/telemetry-contract"
9
- },
10
- "publishConfig": {
11
- "registry": "https://npm.pkg.github.com"
12
- },
13
- "exports": {
14
- "./transport": {
15
- "types": "./transport.d.ts",
16
- "default": "./transport.js"
17
- }
18
- },
19
- "files": [
20
- "transport.js",
21
- "transport.d.ts"
22
- ],
23
- "scripts": {
24
- "preversion": "git diff --quiet && git diff --cached --quiet && npm test",
25
- "version": "git add package.json && git commit -m \"chore: release telemetry contract v${npm_new_version}\" && git tag \"$(npm config get tag-version-prefix)${npm_new_version}\"",
26
- "postversion": "git push --atomic origin HEAD \"refs/tags/$(npm config get tag-version-prefix)${npm_new_version}\"",
27
- "test": "node transport.test.js"
28
- },
29
- "engines": {
30
- "node": ">=20"
31
- }
32
- }
@@ -1,39 +0,0 @@
1
- export interface TransportParams {
2
- call_id: string;
3
- stage: string;
4
- timestamp_utc: string;
5
- monotonic_ms?: number;
6
- transport?: 'mqtt' | 'broadcast';
7
- device_id?: string;
8
- IS_MQTT_EXECUTION_ENABLED?: boolean;
9
- [key: string]: unknown;
10
- }
11
-
12
- export interface TransportEvent {
13
- name: string;
14
- params: TransportParams;
15
- }
16
-
17
- export interface RemoteTransportPayload {
18
- user_id: string;
19
- timestamp_micros?: number;
20
- events: TransportEvent[];
21
- }
22
-
23
- export interface DeviceTransportPayload {
24
- client_id: string;
25
- timestamp_micros?: number;
26
- events: Array<{ name: string; params: TransportParams & { device_id: string } }>;
27
- }
28
-
29
- /** Identifies a transport batch before choosing the ordinary event path. */
30
- export function hasTransportEvents(payload: unknown): boolean;
31
-
32
- /** Validates one event and removes unknown or invalid optional fields. */
33
- export function sanitizeTransportEvent(eventName: string, params: unknown): TransportParams;
34
-
35
- /** Validates a 1–10 event authenticated backend batch. */
36
- export function parseRemoteTransportPayload(payload: unknown): RemoteTransportPayload;
37
-
38
- /** Validates a 1–10 event device batch and assigns source=device. */
39
- export function parseDeviceTransportPayload(payload: unknown): DeviceTransportPayload;