@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.
- package/LICENSE +20 -20
- package/README.md +1152 -1152
- package/dist/bootstrap.js +0 -0
- package/dist/command-manager.js +0 -0
- package/dist/config-field-definitions.js +0 -0
- package/dist/config-manager.d.ts +6 -0
- package/dist/config-manager.js +1 -1
- package/dist/config-recovery.js +0 -0
- package/dist/config.js +0 -0
- package/dist/custom-stdio.js +0 -0
- package/dist/data/onboarding-prompts.json +70 -70
- package/dist/error-handlers.js +0 -0
- package/dist/handlers/filesystem-handlers.js +2 -2
- package/dist/index.js +0 -0
- package/dist/npm-scripts/remote.js +34 -19
- package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
- package/dist/remote-device/diagnostics/device-log.js +219 -0
- package/dist/remote-device/diagnostics/redact.d.ts +1 -0
- package/dist/remote-device/diagnostics/redact.js +76 -0
- package/dist/remote-device/diagnostics/report.d.ts +118 -0
- package/dist/remote-device/diagnostics/report.js +748 -0
- package/dist/remote-device/diagnostics/upload.d.ts +11 -0
- package/dist/remote-device/diagnostics/upload.js +59 -0
- package/dist/remote-device/scripts/blocking-offline-update.js +133 -133
- package/dist/search-manager.js +0 -0
- package/dist/server.js +610 -610
- package/dist/setup-claude-server.js +942 -942
- package/dist/terminal-manager.js +0 -0
- package/dist/tools/edit.js +2 -2
- package/dist/tools/fuzzySearch.js +9 -9
- package/dist/tools/improved-process-tools.js +10 -10
- package/dist/tools/pdf/extract-images.js +1 -1
- package/dist/tools/prompts.js +1 -1
- package/dist/track-installation.js +387 -387
- package/dist/types.js +0 -0
- package/dist/ui/config-editor/index.html +13 -13
- package/dist/ui/config-editor/src/app.js +30 -30
- package/dist/ui/config-editor/src/array-modal.js +32 -32
- package/dist/ui/config-editor/styles.css +586 -586
- package/dist/ui/file-preview/index.html +16 -16
- package/dist/ui/file-preview/src/app.js +8 -8
- package/dist/ui/file-preview/src/document-layout.js +31 -31
- package/dist/ui/file-preview/src/document-outline.js +8 -8
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
- package/dist/ui/file-preview/src/markdown/controller.js +9 -9
- package/dist/ui/file-preview/src/markdown/editor.js +31 -31
- package/dist/ui/file-preview/styles.css +1630 -1630
- package/dist/uninstall-claude-server.js +745 -745
- package/dist/utils/files/binary.js +4 -4
- package/dist/utils/files/excel.js +3 -3
- package/dist/utils/lazy-package.d.ts +5 -3
- package/dist/utils/lazy-package.js +6 -4
- package/dist/utils/system-info.js +90 -90
- package/dist/utils/usageTracker.js +49 -49
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -56
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -32
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -38
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -164
- package/package.json +29 -15
- package/vendor/telemetry-contract/README.md +56 -56
- package/vendor/telemetry-contract/package.json +32 -32
- package/vendor/telemetry-contract/transport.d.ts +38 -38
- package/vendor/telemetry-contract/transport.js +164 -164
- package/vendor/telemetry-contract/transport.test.js +39 -39
- package/dist/remote-device/broadcast-analytics.d.ts +0 -28
- package/dist/remote-device/broadcast-analytics.js +0 -41
- package/dist/remote-device/mqtt-enrollment.d.ts +0 -16
- package/dist/remote-device/mqtt-enrollment.js +0 -162
- package/dist/remote-device/mqtt-transport.d.ts +0 -44
- package/dist/remote-device/mqtt-transport.js +0 -197
- package/dist/remote-device/transport-analytics.d.ts +0 -29
- package/dist/remote-device/transport-analytics.js +0 -44
- package/dist/tools/search.d.ts +0 -32
- package/dist/tools/search.js +0 -202
package/dist/bootstrap.js
CHANGED
|
File without changes
|
package/dist/command-manager.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/config-manager.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export interface ClientInfo {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function normalizeTelemetryEnabledValue(value: unknown): unknown;
|
|
17
17
|
export declare function isTelemetryDisabledValue(value: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Parses config.json's text. Editors saving "UTF-8 with BOM" (Notepad,
|
|
20
|
+
* PowerShell 5's Set-Content -Encoding UTF8) put U+FEFF first, which
|
|
21
|
+
* JSON.parse rejects although the config is complete.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseConfig(text: string): ServerConfig;
|
|
18
24
|
/**
|
|
19
25
|
* Singleton config manager for the server
|
|
20
26
|
*/
|
package/dist/config-manager.js
CHANGED
|
@@ -50,7 +50,7 @@ export function isTelemetryDisabledValue(value) {
|
|
|
50
50
|
* PowerShell 5's Set-Content -Encoding UTF8) put U+FEFF first, which
|
|
51
51
|
* JSON.parse rejects although the config is complete.
|
|
52
52
|
*/
|
|
53
|
-
function parseConfig(text) {
|
|
53
|
+
export function parseConfig(text) {
|
|
54
54
|
return JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
|
|
55
55
|
}
|
|
56
56
|
/** Marks a config written before the welcome page existed as an existing install, which never gets it */
|
package/dist/config-recovery.js
CHANGED
|
File without changes
|
package/dist/config.js
CHANGED
|
File without changes
|
package/dist/custom-stdio.js
CHANGED
|
File without changes
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "2.0.0",
|
|
3
|
-
"description": "Desktop Commander onboarding prompts - V2 simplified (5 prompts only)",
|
|
4
|
-
"prompts": [
|
|
5
|
-
{
|
|
6
|
-
"id": "onb2_01",
|
|
7
|
-
"title": "Organize my Downloads folder",
|
|
8
|
-
"description": "Clean up and organize your messy Downloads folder into relevant subfolders automatically.",
|
|
9
|
-
"prompt": "Let's organize your Downloads folder! \n\nFirst, let me check what we're working with. I'll look at your Downloads folder to see how many files are there and what types.\n\nShould I start by analyzing your Downloads folder?",
|
|
10
|
-
"categories": ["onboarding"],
|
|
11
|
-
"secondaryTag": "Quick Start",
|
|
12
|
-
"votes": 0,
|
|
13
|
-
"gaClicks": 0,
|
|
14
|
-
"icon": "FolderOpen",
|
|
15
|
-
"author": "DC team",
|
|
16
|
-
"verified": true
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"id": "onb2_02",
|
|
20
|
-
"title": "Explain codebase or repository to me",
|
|
21
|
-
"description": "Analyze and explain any codebase - local project or GitHub repository - including architecture, dependencies, and how it works.",
|
|
22
|
-
"prompt": "I'll analyze and explain any codebase for you! 🔍\n\n**What should I analyze?**\n\n*Local project:* `~/work/my-project` (replace with your path)\n*GitHub repo:* `https://github.com/user/repo`\n\nI'll break down the architecture, dependencies, and how everything works together!",
|
|
23
|
-
"categories": ["onboarding"], "secondaryTag": "Code Analysis",
|
|
24
|
-
"votes": 0,
|
|
25
|
-
"gaClicks": 0,
|
|
26
|
-
"icon": "Code",
|
|
27
|
-
"author": "DC team",
|
|
28
|
-
"verified": true
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"id": "onb2_03",
|
|
32
|
-
"title": "Create organized knowledge/documents folder",
|
|
33
|
-
"description": "Set up a well-structured knowledge base or document organization system with templates and suggested categories.",
|
|
34
|
-
"prompt": "Let's create an organized knowledge base! 📚\n\n**Where should I set it up?**\n\n*I suggest: `~/Documents/Knowledge-Base` (replace with your path) or give me a different location.*\n\nI'll create a clean folder structure with templates and organize any existing documents you have!",
|
|
35
|
-
"categories": ["onboarding"],
|
|
36
|
-
"secondaryTag": "Quick Start",
|
|
37
|
-
"votes": 0,
|
|
38
|
-
"gaClicks": 0,
|
|
39
|
-
"icon": "BookOpen",
|
|
40
|
-
"author": "DC team",
|
|
41
|
-
"verified": true
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"id": "onb2_04",
|
|
45
|
-
"title": "Analyze my data file",
|
|
46
|
-
"description": "Upload or point to any data file (CSV, JSON, Excel, etc.) and get comprehensive analysis including patterns, insights, and summary reports.",
|
|
47
|
-
"prompt": "I'll help you analyze your data file! \n\nWhat's the path to your data file? (e.g., `/Users/yourname/data.csv`)\n\nOnce you give me the path, I'll start by checking what type of file it is and show you a quick preview, then we can dive deeper step by step.",
|
|
48
|
-
"categories": ["onboarding"],
|
|
49
|
-
"secondaryTag": "Quick Start",
|
|
50
|
-
"votes": 0,
|
|
51
|
-
"gaClicks": 0,
|
|
52
|
-
"icon": "BarChart3",
|
|
53
|
-
"author": "DC team",
|
|
54
|
-
"verified": true
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"id": "onb2_05",
|
|
58
|
-
"title": "Check system health and resources",
|
|
59
|
-
"description": "Analyze your system's health, resource usage, running processes, and generate a comprehensive system status report.",
|
|
60
|
-
"prompt": "Let me check your system health and resources!\n\nI'll start by looking at your CPU, memory, and disk usage, then check for any performance issues.\n\nShould I begin the system analysis?",
|
|
61
|
-
"categories": ["onboarding"],
|
|
62
|
-
"secondaryTag": "Quick Start",
|
|
63
|
-
"votes": 0,
|
|
64
|
-
"gaClicks": 0,
|
|
65
|
-
"icon": "Activity",
|
|
66
|
-
"author": "DC team",
|
|
67
|
-
"verified": true
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"description": "Desktop Commander onboarding prompts - V2 simplified (5 prompts only)",
|
|
4
|
+
"prompts": [
|
|
5
|
+
{
|
|
6
|
+
"id": "onb2_01",
|
|
7
|
+
"title": "Organize my Downloads folder",
|
|
8
|
+
"description": "Clean up and organize your messy Downloads folder into relevant subfolders automatically.",
|
|
9
|
+
"prompt": "Let's organize your Downloads folder! \n\nFirst, let me check what we're working with. I'll look at your Downloads folder to see how many files are there and what types.\n\nShould I start by analyzing your Downloads folder?",
|
|
10
|
+
"categories": ["onboarding"],
|
|
11
|
+
"secondaryTag": "Quick Start",
|
|
12
|
+
"votes": 0,
|
|
13
|
+
"gaClicks": 0,
|
|
14
|
+
"icon": "FolderOpen",
|
|
15
|
+
"author": "DC team",
|
|
16
|
+
"verified": true
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "onb2_02",
|
|
20
|
+
"title": "Explain codebase or repository to me",
|
|
21
|
+
"description": "Analyze and explain any codebase - local project or GitHub repository - including architecture, dependencies, and how it works.",
|
|
22
|
+
"prompt": "I'll analyze and explain any codebase for you! 🔍\n\n**What should I analyze?**\n\n*Local project:* `~/work/my-project` (replace with your path)\n*GitHub repo:* `https://github.com/user/repo`\n\nI'll break down the architecture, dependencies, and how everything works together!",
|
|
23
|
+
"categories": ["onboarding"], "secondaryTag": "Code Analysis",
|
|
24
|
+
"votes": 0,
|
|
25
|
+
"gaClicks": 0,
|
|
26
|
+
"icon": "Code",
|
|
27
|
+
"author": "DC team",
|
|
28
|
+
"verified": true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "onb2_03",
|
|
32
|
+
"title": "Create organized knowledge/documents folder",
|
|
33
|
+
"description": "Set up a well-structured knowledge base or document organization system with templates and suggested categories.",
|
|
34
|
+
"prompt": "Let's create an organized knowledge base! 📚\n\n**Where should I set it up?**\n\n*I suggest: `~/Documents/Knowledge-Base` (replace with your path) or give me a different location.*\n\nI'll create a clean folder structure with templates and organize any existing documents you have!",
|
|
35
|
+
"categories": ["onboarding"],
|
|
36
|
+
"secondaryTag": "Quick Start",
|
|
37
|
+
"votes": 0,
|
|
38
|
+
"gaClicks": 0,
|
|
39
|
+
"icon": "BookOpen",
|
|
40
|
+
"author": "DC team",
|
|
41
|
+
"verified": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "onb2_04",
|
|
45
|
+
"title": "Analyze my data file",
|
|
46
|
+
"description": "Upload or point to any data file (CSV, JSON, Excel, etc.) and get comprehensive analysis including patterns, insights, and summary reports.",
|
|
47
|
+
"prompt": "I'll help you analyze your data file! \n\nWhat's the path to your data file? (e.g., `/Users/yourname/data.csv`)\n\nOnce you give me the path, I'll start by checking what type of file it is and show you a quick preview, then we can dive deeper step by step.",
|
|
48
|
+
"categories": ["onboarding"],
|
|
49
|
+
"secondaryTag": "Quick Start",
|
|
50
|
+
"votes": 0,
|
|
51
|
+
"gaClicks": 0,
|
|
52
|
+
"icon": "BarChart3",
|
|
53
|
+
"author": "DC team",
|
|
54
|
+
"verified": true
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "onb2_05",
|
|
58
|
+
"title": "Check system health and resources",
|
|
59
|
+
"description": "Analyze your system's health, resource usage, running processes, and generate a comprehensive system status report.",
|
|
60
|
+
"prompt": "Let me check your system health and resources!\n\nI'll start by looking at your CPU, memory, and disk usage, then check for any performance issues.\n\nShould I begin the system analysis?",
|
|
61
|
+
"categories": ["onboarding"],
|
|
62
|
+
"secondaryTag": "Quick Start",
|
|
63
|
+
"votes": 0,
|
|
64
|
+
"gaClicks": 0,
|
|
65
|
+
"icon": "Activity",
|
|
66
|
+
"author": "DC team",
|
|
67
|
+
"verified": true
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
package/dist/error-handlers.js
CHANGED
|
File without changes
|
|
@@ -297,8 +297,8 @@ export async function handleWriteFile(args) {
|
|
|
297
297
|
const lineCount = TextFileHandler.countLines(parsed.content);
|
|
298
298
|
let errorMessage = "";
|
|
299
299
|
if (lineCount > MAX_LINES) {
|
|
300
|
-
errorMessage = `✅ File written successfully! (${lineCount} lines)
|
|
301
|
-
|
|
300
|
+
errorMessage = `✅ File written successfully! (${lineCount} lines)
|
|
301
|
+
|
|
302
302
|
💡 Performance tip: For optimal speed, consider chunking files into ≤30 line pieces in future operations.`;
|
|
303
303
|
}
|
|
304
304
|
// Pass the mode parameter to writeFile
|
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MCPDevice, getRemoteDeviceConfigPath, removeRemoteDeviceConfig } from '../remote-device/device.js';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import { captureRemote } from '../utils/capture.js';
|
|
4
|
+
import { startDeviceLog } from '../remote-device/diagnostics/device-log.js';
|
|
4
5
|
const BLUE = '\x1b[34m';
|
|
5
6
|
const RESET = '\x1b[0m';
|
|
6
7
|
function printRemoteHeader() {
|
|
@@ -17,25 +18,29 @@ function printRemoteHeader() {
|
|
|
17
18
|
}
|
|
18
19
|
export async function runRemote() {
|
|
19
20
|
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
20
|
-
console.log(`Desktop Commander Remote MCP device
|
|
21
|
-
|
|
22
|
-
Usage:
|
|
23
|
-
desktop-commander remote [options]
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--logout Remove saved local Remote MCP credentials and exit
|
|
27
|
-
--
|
|
28
|
-
|
|
29
|
-
--
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
console.log(`Desktop Commander Remote MCP device
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
desktop-commander remote [options]
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--logout Remove saved local Remote MCP credentials and exit
|
|
28
|
+
--report Save a diagnostics zip for support, send it, and exit
|
|
29
|
+
(the device doesn't start and nothing signs in)
|
|
30
|
+
--no-upload With --report: only save the zip, don't send it
|
|
31
|
+
--no-persist-session Do not reuse or save authentication for this run
|
|
32
|
+
--disable-no-sleep Do not prevent sleep while the remote device is running
|
|
33
|
+
--debug Enable verbose debug logging
|
|
34
|
+
-h, --help Show this help
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
npx @wonderwhy-er/desktop-commander@latest remote
|
|
38
|
+
npx @wonderwhy-er/desktop-commander@latest remote --debug
|
|
39
|
+
npx @wonderwhy-er/desktop-commander@latest remote --logout
|
|
40
|
+
npx @wonderwhy-er/desktop-commander@latest remote --report
|
|
41
|
+
|
|
42
|
+
Note:
|
|
43
|
+
--logout removes local credentials only. Revoke the device in the Remote MCP
|
|
39
44
|
dashboard if you also want to invalidate its server-side authorization.`);
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
@@ -52,6 +57,12 @@ Note:
|
|
|
52
57
|
}
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
60
|
+
if (process.argv.includes('--report')) {
|
|
61
|
+
// Before the device: the report works when sign-in is broken, and never opens it
|
|
62
|
+
const { runReport } = await import('../remote-device/diagnostics/report.js');
|
|
63
|
+
await runReport();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
55
66
|
printRemoteHeader();
|
|
56
67
|
// --persist-session is kept as an accepted no-op so existing invocations
|
|
57
68
|
// and docs keep working; --no-persist-session opts back out.
|
|
@@ -67,6 +78,10 @@ Note:
|
|
|
67
78
|
if (!verbose) {
|
|
68
79
|
console.debug = () => { };
|
|
69
80
|
}
|
|
81
|
+
// The device's status history for `remote --report`. Wraps the console as
|
|
82
|
+
// it is now, so the terminal stays the same, but debug status lines are
|
|
83
|
+
// kept even without --debug.
|
|
84
|
+
startDeviceLog();
|
|
70
85
|
console.debug('[DEBUG] Platform:', os.platform());
|
|
71
86
|
await captureRemote('remote_device_command_started', {
|
|
72
87
|
node_version: process.version,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The remote device log: ~/.desktop-commander-device/remote-<day>.log, the
|
|
3
|
+
* device's history that `remote --report` packs for support.
|
|
4
|
+
*
|
|
5
|
+
* `remote` passes the device's console output through startDeviceLog(). Every
|
|
6
|
+
* line is written, masked by redact() and timestamped in UTC; only the private
|
|
7
|
+
* kinds below are dropped. Each UTC weekday has its own files: remote-mon.log
|
|
8
|
+
* rotates at 1 MB into remote-mon.1.log and remote-mon.2.log. The first write
|
|
9
|
+
* on a weekday whose file is over a day old (last week's) removes that day's
|
|
10
|
+
* files first, so the log keeps at most 7 days × 3 files, 21 MB.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEVICE_LOG_MAX_BYTES: number;
|
|
13
|
+
/** How many files the log keeps per day: remote-<day>.log and its rotated older copies. */
|
|
14
|
+
export declare const DEVICE_LOG_FILES = 3;
|
|
15
|
+
/** remote-mon.log, then remote-mon.1.log, remote-mon.2.log (older); `day` is the UTC weekday, 0 = Sunday. */
|
|
16
|
+
export declare const deviceLogName: (day: number, i: number) => string;
|
|
17
|
+
/** Every name the log can use: 7 days × DEVICE_LOG_FILES. */
|
|
18
|
+
export declare const deviceLogNames: () => string[];
|
|
19
|
+
export declare function getDeviceLogDir(): string;
|
|
20
|
+
/**
|
|
21
|
+
* One line as the log keeps it: masked, or null for a private one. The report
|
|
22
|
+
* runs every stored line through this again.
|
|
23
|
+
*/
|
|
24
|
+
export declare function cleanLine(line: string): string | null;
|
|
25
|
+
export interface DeviceLogOptions {
|
|
26
|
+
/** The folder for the log files; ~/.desktop-commander-device by default. */
|
|
27
|
+
dir?: string;
|
|
28
|
+
/** The clock (ms), for the timestamps and the day; Date.now by default. Tests set it. */
|
|
29
|
+
now?: () => number;
|
|
30
|
+
/** The size at which a file rotates; DEVICE_LOG_MAX_BYTES by default. Tests set it. */
|
|
31
|
+
maxBytes?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare class DeviceLog {
|
|
34
|
+
private readonly dir;
|
|
35
|
+
private readonly now;
|
|
36
|
+
private readonly maxBytes;
|
|
37
|
+
/** The UTC weekday being written; -1 before the first write. */
|
|
38
|
+
private day;
|
|
39
|
+
private size;
|
|
40
|
+
private failures;
|
|
41
|
+
/** The next printed line is the sign-in link or code. */
|
|
42
|
+
private skipNextLine;
|
|
43
|
+
constructor(options?: DeviceLogOptions);
|
|
44
|
+
private file;
|
|
45
|
+
/** One console call's arguments: each of its lines, cleaned. */
|
|
46
|
+
record(args: unknown[]): void;
|
|
47
|
+
/** Appends one line as is: callers pass text that is already masked. */
|
|
48
|
+
write(text: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* The first write of a UTC weekday: if that weekday's file is over a day
|
|
51
|
+
* old, it is last week's, and its files go before today's lines start.
|
|
52
|
+
*/
|
|
53
|
+
private startDay;
|
|
54
|
+
/** Drops the day's oldest file and moves each other one a step older: remote-mon.log becomes remote-mon.1.log. */
|
|
55
|
+
private rotate;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Passes console output through the device log for this `remote` run. Each
|
|
59
|
+
* method still does what it did (so a console.debug that `remote` silenced
|
|
60
|
+
* stays silent), then the log records the call. Returns a function that puts
|
|
61
|
+
* the console back.
|
|
62
|
+
*/
|
|
63
|
+
export declare function startDeviceLog(options?: DeviceLogOptions): () => void;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { format } from 'util';
|
|
5
|
+
import { VERSION } from '../../version.js';
|
|
6
|
+
import { redact } from './redact.js';
|
|
7
|
+
/**
|
|
8
|
+
* The remote device log: ~/.desktop-commander-device/remote-<day>.log, the
|
|
9
|
+
* device's history that `remote --report` packs for support.
|
|
10
|
+
*
|
|
11
|
+
* `remote` passes the device's console output through startDeviceLog(). Every
|
|
12
|
+
* line is written, masked by redact() and timestamped in UTC; only the private
|
|
13
|
+
* kinds below are dropped. Each UTC weekday has its own files: remote-mon.log
|
|
14
|
+
* rotates at 1 MB into remote-mon.1.log and remote-mon.2.log. The first write
|
|
15
|
+
* on a weekday whose file is over a day old (last week's) removes that day's
|
|
16
|
+
* files first, so the log keeps at most 7 days × 3 files, 21 MB.
|
|
17
|
+
*/
|
|
18
|
+
export const DEVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
19
|
+
/** How many files the log keeps per day: remote-<day>.log and its rotated older copies. */
|
|
20
|
+
export const DEVICE_LOG_FILES = 3;
|
|
21
|
+
/** The UTC weekdays as the file names spell them; Date.getUTCDay() indexes it. */
|
|
22
|
+
const DAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
23
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
24
|
+
/** remote-mon.log, then remote-mon.1.log, remote-mon.2.log (older); `day` is the UTC weekday, 0 = Sunday. */
|
|
25
|
+
export const deviceLogName = (day, i) => `remote-${DAYS[day]}${i === 0 ? '' : `.${i}`}.log`;
|
|
26
|
+
/** Every name the log can use: 7 days × DEVICE_LOG_FILES. */
|
|
27
|
+
export const deviceLogNames = () => DAYS.flatMap((_, day) => Array.from({ length: DEVICE_LOG_FILES }, (_, i) => deviceLogName(day, i)));
|
|
28
|
+
const MAX_LINE_CHARS = 1000;
|
|
29
|
+
/** A multi-line print (a stack, a config dump) is cut after this many lines. */
|
|
30
|
+
const MAX_LINES_PER_CALL = 40;
|
|
31
|
+
/** Consecutive write failures after which the log gives up for this run. */
|
|
32
|
+
const MAX_WRITE_FAILURES = 5;
|
|
33
|
+
export function getDeviceLogDir() {
|
|
34
|
+
return path.join(os.homedir(), '.desktop-commander-device');
|
|
35
|
+
}
|
|
36
|
+
// --- the private kinds: the only lines that don't reach the log as printed -------------------
|
|
37
|
+
/** " name" when there is one: an empty name, or one that isn't a name, is left out. */
|
|
38
|
+
function toolName(name) {
|
|
39
|
+
const trimmed = (name ?? '').trim();
|
|
40
|
+
return trimmed ? ` ${trimmed}` : '';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tool calls keep the tool's name and the outcome; their arguments, metadata,
|
|
44
|
+
* results and error details go. Matched on a print's first line by its fixed
|
|
45
|
+
* words only, so an empty name, or one with a space, can't make a print slip
|
|
46
|
+
* past (device.ts prints whatever name it gets). The whole print becomes this
|
|
47
|
+
* one line, so a result's own lines never reach the log. null: the print goes
|
|
48
|
+
* entirely.
|
|
49
|
+
*/
|
|
50
|
+
const TOOL_CALLS = [
|
|
51
|
+
// "Received tool call <id>: <name> <args JSON> metadata: <JSON>": the name is
|
|
52
|
+
// kept only if it looks like one, never the JSON that follows an empty name
|
|
53
|
+
[/^Received tool call (\S*):(?: ([\w.-]+)(?=\s|$))?/, (m) => `Received tool call ${m[1]}:${toolName(m[2])}`],
|
|
54
|
+
// Anchored on the words after the name, so any name (with a colon, too) is taken whole
|
|
55
|
+
[/^Tool call (.*?) ?completed:?$/, (m) => `Tool call${toolName(m[1])} completed`],
|
|
56
|
+
[/^Tool call (.*?) ?failed:/, (m) => `Tool call${toolName(m[1])} failed`],
|
|
57
|
+
[/^Calling MCP tool: ?(.*?) ?args:/, (m) => `Calling MCP tool${m[1] ? `:${toolName(m[1])}` : ''}`],
|
|
58
|
+
[/^Calling MCP tool:/, () => 'Calling MCP tool'],
|
|
59
|
+
[/^Error executing tool ?([^:]*?):/, (m) => `Error executing tool${toolName(m[1])}`],
|
|
60
|
+
[/^Tool call error details/, null],
|
|
61
|
+
];
|
|
62
|
+
/** The ready block's "User: <email>", and the sign-in link in "Please visit: <link>". */
|
|
63
|
+
const PRIVATE_LINES = [/^User:\s/, /^Please visit:/];
|
|
64
|
+
/** The sign-in link and the code are each printed alone, on the line after these. */
|
|
65
|
+
const BEFORE_PRIVATE_LINE = [/Verify this device in your browser:$/, /Make sure the code matches:$/];
|
|
66
|
+
/**
|
|
67
|
+
* Error objects are written as their name and message only. Printed whole they
|
|
68
|
+
* carry their properties: a spawn error's `spawnargs` hold the session tokens
|
|
69
|
+
* of the offline update script.
|
|
70
|
+
*/
|
|
71
|
+
function plain(arg) {
|
|
72
|
+
return arg instanceof Error ? `${arg.name}: ${arg.message}` : arg;
|
|
73
|
+
}
|
|
74
|
+
/** Whitespace, bullets, arrows, check marks, emoji and "[DEBUG]" before the text. */
|
|
75
|
+
const LEADING = /^(?:\s|\[DEBUG\]|[-–•→✓✗]|\p{Extended_Pictographic}|️|)+/u;
|
|
76
|
+
function toolCall(text) {
|
|
77
|
+
for (const [pattern, keep] of TOOL_CALLS) {
|
|
78
|
+
const match = text.match(pattern);
|
|
79
|
+
if (match)
|
|
80
|
+
return { line: keep ? redact(keep(match)).slice(0, MAX_LINE_CHARS) : null };
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* One line as the log keeps it: masked, or null for a private one. The report
|
|
86
|
+
* runs every stored line through this again.
|
|
87
|
+
*/
|
|
88
|
+
export function cleanLine(line) {
|
|
89
|
+
const text = line.replace(LEADING, '').trimEnd();
|
|
90
|
+
if (!text)
|
|
91
|
+
return null;
|
|
92
|
+
const tool = toolCall(text);
|
|
93
|
+
if (tool)
|
|
94
|
+
return tool.line;
|
|
95
|
+
if (PRIVATE_LINES.some((pattern) => pattern.test(text)))
|
|
96
|
+
return null;
|
|
97
|
+
return redact(text).slice(0, MAX_LINE_CHARS);
|
|
98
|
+
}
|
|
99
|
+
export class DeviceLog {
|
|
100
|
+
constructor(options = {}) {
|
|
101
|
+
/** The UTC weekday being written; -1 before the first write. */
|
|
102
|
+
this.day = -1;
|
|
103
|
+
this.size = -1;
|
|
104
|
+
this.failures = 0;
|
|
105
|
+
/** The next printed line is the sign-in link or code. */
|
|
106
|
+
this.skipNextLine = false;
|
|
107
|
+
this.dir = options.dir ?? getDeviceLogDir();
|
|
108
|
+
this.now = options.now ?? Date.now;
|
|
109
|
+
this.maxBytes = options.maxBytes ?? DEVICE_LOG_MAX_BYTES;
|
|
110
|
+
}
|
|
111
|
+
file(i) {
|
|
112
|
+
return path.join(this.dir, deviceLogName(this.day, i));
|
|
113
|
+
}
|
|
114
|
+
/** One console call's arguments: each of its lines, cleaned. */
|
|
115
|
+
record(args) {
|
|
116
|
+
if (this.failures >= MAX_WRITE_FAILURES)
|
|
117
|
+
return;
|
|
118
|
+
let lines;
|
|
119
|
+
try {
|
|
120
|
+
const [first, ...rest] = args.map(plain);
|
|
121
|
+
lines = format(first, ...rest).split(/\r?\n/).filter((line) => line.trim() !== '');
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (lines.length === 0)
|
|
127
|
+
return;
|
|
128
|
+
const tool = toolCall(lines[0].replace(LEADING, '').trimEnd());
|
|
129
|
+
if (tool) {
|
|
130
|
+
if (tool.line)
|
|
131
|
+
this.write(tool.line);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const line of lines.slice(0, MAX_LINES_PER_CALL)) {
|
|
135
|
+
if (this.skipNextLine) {
|
|
136
|
+
this.skipNextLine = false;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const text = cleanLine(line);
|
|
140
|
+
if (text === null)
|
|
141
|
+
continue;
|
|
142
|
+
if (BEFORE_PRIVATE_LINE.some((pattern) => pattern.test(text)))
|
|
143
|
+
this.skipNextLine = true;
|
|
144
|
+
this.write(text);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Appends one line as is: callers pass text that is already masked. */
|
|
148
|
+
write(text) {
|
|
149
|
+
if (this.failures >= MAX_WRITE_FAILURES)
|
|
150
|
+
return;
|
|
151
|
+
const now = this.now();
|
|
152
|
+
const line = `${new Date(now).toISOString().replace(/\.\d{3}Z$/, 'Z')} ${text}\n`;
|
|
153
|
+
const bytes = Buffer.byteLength(line);
|
|
154
|
+
try {
|
|
155
|
+
const day = new Date(now).getUTCDay();
|
|
156
|
+
if (day !== this.day)
|
|
157
|
+
this.startDay(day, now);
|
|
158
|
+
if (this.size < 0) {
|
|
159
|
+
fs.mkdirSync(this.dir, { recursive: true });
|
|
160
|
+
this.size = fs.existsSync(this.file(0)) ? fs.statSync(this.file(0)).size : 0;
|
|
161
|
+
}
|
|
162
|
+
if (this.size > 0 && this.size + bytes > this.maxBytes) {
|
|
163
|
+
this.rotate();
|
|
164
|
+
this.size = 0;
|
|
165
|
+
}
|
|
166
|
+
fs.appendFileSync(this.file(0), line, { mode: 0o600 });
|
|
167
|
+
this.size += bytes;
|
|
168
|
+
this.failures = 0;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// The log must never break the device: skip the line, give up after a few in a row
|
|
172
|
+
this.failures++;
|
|
173
|
+
this.size = -1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The first write of a UTC weekday: if that weekday's file is over a day
|
|
178
|
+
* old, it is last week's, and its files go before today's lines start.
|
|
179
|
+
*/
|
|
180
|
+
startDay(day, now) {
|
|
181
|
+
const today = path.join(this.dir, deviceLogName(day, 0));
|
|
182
|
+
if (fs.existsSync(today) && now - fs.statSync(today).mtimeMs > DAY_MS) {
|
|
183
|
+
for (let i = 0; i < DEVICE_LOG_FILES; i++)
|
|
184
|
+
fs.rmSync(path.join(this.dir, deviceLogName(day, i)), { force: true });
|
|
185
|
+
}
|
|
186
|
+
this.day = day;
|
|
187
|
+
this.size = -1;
|
|
188
|
+
}
|
|
189
|
+
/** Drops the day's oldest file and moves each other one a step older: remote-mon.log becomes remote-mon.1.log. */
|
|
190
|
+
rotate() {
|
|
191
|
+
fs.rmSync(this.file(DEVICE_LOG_FILES - 1), { force: true });
|
|
192
|
+
for (let i = DEVICE_LOG_FILES - 2; i >= 0; i--) {
|
|
193
|
+
if (fs.existsSync(this.file(i)))
|
|
194
|
+
fs.renameSync(this.file(i), this.file(i + 1));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const CONSOLE_METHODS = ['log', 'info', 'warn', 'error', 'debug'];
|
|
199
|
+
/**
|
|
200
|
+
* Passes console output through the device log for this `remote` run. Each
|
|
201
|
+
* method still does what it did (so a console.debug that `remote` silenced
|
|
202
|
+
* stays silent), then the log records the call. Returns a function that puts
|
|
203
|
+
* the console back.
|
|
204
|
+
*/
|
|
205
|
+
export function startDeviceLog(options = {}) {
|
|
206
|
+
const log = new DeviceLog(options);
|
|
207
|
+
const originals = CONSOLE_METHODS.map((method) => [method, console[method]]);
|
|
208
|
+
for (const [method, original] of originals) {
|
|
209
|
+
console[method] = (...args) => {
|
|
210
|
+
original.apply(console, args);
|
|
211
|
+
log.record(args);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
log.write(`Remote started (Desktop Commander ${VERSION}, Node ${process.versions.node}, ${process.platform})`);
|
|
215
|
+
return () => {
|
|
216
|
+
for (const [method, original] of originals)
|
|
217
|
+
console[method] = original;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function redact(text: string): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
/**
|
|
4
|
+
* The one masker for the remote diagnostics: every line the device log keeps
|
|
5
|
+
* and everything `remote --report` writes from free text passes through here.
|
|
6
|
+
*
|
|
7
|
+
* Masks JWTs, `access_token` / `refresh_token` / `apikey` / `password` values
|
|
8
|
+
* after `=` or `:`, `Bearer …` values, emails, UUIDs (device and user ids),
|
|
9
|
+
* the home folder (→ `~`), the user name and the host name.
|
|
10
|
+
*/
|
|
11
|
+
const SECRET_KEYS = 'access_token|refresh_token|provider_token|provider_refresh_token|apikey|api_key|password|passwd|secret|client_secret';
|
|
12
|
+
/** `key=value`, `key: value`, `"key":"value"` — the key stays, the value goes. */
|
|
13
|
+
const KEY_VALUE = new RegExp(`(["']?)\\b(${SECRET_KEYS})\\1(\\s*[:=]\\s*)(["']?)[^"'\\s&,;}]+`, 'gi');
|
|
14
|
+
const BEARER = /\b(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi;
|
|
15
|
+
const JWT = /\beyJ[A-Za-z0-9_-]*(?:\.[A-Za-z0-9_-]*){0,2}/g;
|
|
16
|
+
const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
17
|
+
const UUID = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
|
|
18
|
+
function escapeRegExp(text) {
|
|
19
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The home folder as it may appear: as is and as its real path (on macOS a
|
|
23
|
+
* temp folder sits under the /var -> /private/var symlink, and execPath is the
|
|
24
|
+
* real one), each with forward slashes and JSON-escaped. Only a whole path
|
|
25
|
+
* matches: not "/backup/Users/x" nor "/Users/xy" for "/Users/x".
|
|
26
|
+
*/
|
|
27
|
+
function homePattern(home) {
|
|
28
|
+
if (home.length < 2)
|
|
29
|
+
return null;
|
|
30
|
+
const roots = [home];
|
|
31
|
+
try {
|
|
32
|
+
roots.push(fs.realpathSync.native(home));
|
|
33
|
+
}
|
|
34
|
+
catch { /* no such folder: the plain form only */ }
|
|
35
|
+
const forms = new Set(roots.flatMap((root) => [root, root.replace(/\\/g, '/'), root.replace(/\\/g, '\\\\')]));
|
|
36
|
+
// Longest first, so the JSON-escaped and real forms are not half-matched by a shorter one
|
|
37
|
+
const alternatives = [...forms].sort((a, b) => b.length - a.length).map(escapeRegExp);
|
|
38
|
+
const pathChar = '[A-Za-z0-9_.-]';
|
|
39
|
+
return new RegExp(`(?<!${pathChar})(?:${alternatives.join('|')})(?!${pathChar})`, process.platform === 'win32' ? 'gi' : 'g');
|
|
40
|
+
}
|
|
41
|
+
/** A name as a whole word: "alice" in "C:/x/alice/y", not in "aliceb". */
|
|
42
|
+
function wordPattern(word) {
|
|
43
|
+
if (word.length < 3)
|
|
44
|
+
return null;
|
|
45
|
+
return new RegExp(`(?<![A-Za-z0-9])${escapeRegExp(word)}(?![A-Za-z0-9])`, 'gi');
|
|
46
|
+
}
|
|
47
|
+
function safeUserName() {
|
|
48
|
+
try {
|
|
49
|
+
return os.userInfo().username;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function redact(text) {
|
|
56
|
+
let out = text;
|
|
57
|
+
const home = homePattern(os.homedir());
|
|
58
|
+
if (home)
|
|
59
|
+
out = out.replace(home, '~');
|
|
60
|
+
out = out.replace(KEY_VALUE, '$1$2$1$3$4<redacted>');
|
|
61
|
+
out = out.replace(BEARER, '$1<redacted>');
|
|
62
|
+
out = out.replace(JWT, '<jwt>');
|
|
63
|
+
out = out.replace(EMAIL, '<email>');
|
|
64
|
+
out = out.replace(UUID, '<id>');
|
|
65
|
+
// "name.local" and the bare "name" a Mac also goes by
|
|
66
|
+
const hostname = os.hostname();
|
|
67
|
+
for (const name of new Set([hostname, hostname.split('.')[0]])) {
|
|
68
|
+
const host = wordPattern(name);
|
|
69
|
+
if (host)
|
|
70
|
+
out = out.replace(host, '<host>');
|
|
71
|
+
}
|
|
72
|
+
const user = wordPattern(safeUserName());
|
|
73
|
+
if (user)
|
|
74
|
+
out = out.replace(user, '<user>');
|
|
75
|
+
return out;
|
|
76
|
+
}
|