@wonderwhy-er/desktop-commander 0.2.52 → 0.3.0
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/command-manager.d.ts +7 -2
- package/dist/command-manager.js +16 -11
- package/dist/config-manager.d.ts +55 -3
- package/dist/config-manager.js +329 -87
- package/dist/config-recovery.d.ts +28 -0
- package/dist/config-recovery.js +81 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +9 -0
- package/dist/handlers/filesystem-handlers.d.ts +1 -1
- package/dist/handlers/filesystem-handlers.js +26 -16
- package/dist/handlers/search-answers.d.ts +58 -0
- package/dist/handlers/search-answers.js +172 -0
- package/dist/handlers/search-handlers.js +4 -92
- package/dist/index.js +14 -7
- package/dist/npm-scripts/remote.js +17 -3
- package/dist/remote-device/desktop-commander-integration.d.ts +1 -0
- package/dist/remote-device/desktop-commander-integration.js +19 -25
- package/dist/remote-device/device.d.ts +14 -0
- package/dist/remote-device/device.js +137 -30
- 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/realtime-health-telemetry.d.ts +35 -0
- package/dist/remote-device/realtime-health-telemetry.js +110 -0
- package/dist/remote-device/remote-channel.d.ts +36 -4
- package/dist/remote-device/remote-channel.js +230 -50
- package/dist/remote-device/scripts/blocking-offline-update.js +108 -69
- package/dist/remote-device/transport-telemetry.d.ts +32 -0
- package/dist/remote-device/transport-telemetry.js +48 -0
- package/dist/search-manager.d.ts +239 -27
- package/dist/search-manager.js +746 -312
- package/dist/server.js +124 -222
- package/dist/terminal-manager.d.ts +138 -21
- package/dist/terminal-manager.js +300 -215
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +21 -70
- package/dist/tools/edit.js +12 -4
- package/dist/tools/filesystem.d.ts +30 -6
- package/dist/tools/filesystem.js +246 -140
- package/dist/tools/improved-process-tools.d.ts +9 -3
- package/dist/tools/improved-process-tools.js +171 -68
- package/dist/tools/pdf/extract-images.d.ts +2 -0
- package/dist/tools/pdf/extract-images.js +4 -1
- package/dist/tools/pdf/index.d.ts +5 -3
- package/dist/tools/pdf/index.js +4 -3
- package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
- package/dist/tools/pdf/lib/pdf2md.js +12 -5
- package/dist/tools/pdf/manipulations.d.ts +12 -1
- package/dist/tools/pdf/manipulations.js +17 -4
- package/dist/tools/pdf/markdown.d.ts +96 -0
- package/dist/tools/pdf/markdown.js +485 -20
- package/dist/tools/pdf/utils.d.ts +2 -2
- package/dist/tools/pdf/utils.js +4 -4
- package/dist/tools/process.js +8 -5
- package/dist/tools/schemas.d.ts +1 -11
- package/dist/tools/schemas.js +15 -14
- package/dist/types.d.ts +1 -1
- package/dist/ui/config-editor/config-editor-runtime.js +53 -53
- package/dist/ui/config-editor/src/app.js +2 -15
- package/dist/ui/file-preview/preview-runtime.js +190 -182
- package/dist/utils/ab-test.js +27 -9
- package/dist/utils/atomic-write.d.ts +14 -0
- package/dist/utils/atomic-write.js +80 -0
- package/dist/utils/capture.d.ts +17 -1
- package/dist/utils/capture.js +177 -68
- package/dist/utils/exit-process.d.ts +24 -0
- package/dist/utils/exit-process.js +31 -0
- package/dist/utils/feature-flags.js +2 -1
- package/dist/utils/files/base.d.ts +3 -1
- package/dist/utils/files/docx.d.ts +3 -0
- package/dist/utils/files/docx.js +24 -9
- package/dist/utils/files/excel.d.ts +10 -0
- package/dist/utils/files/excel.js +93 -33
- package/dist/utils/files/factory.d.ts +22 -1
- package/dist/utils/files/factory.js +59 -4
- package/dist/utils/files/image.d.ts +12 -4
- package/dist/utils/files/image.js +19 -8
- package/dist/utils/files/index.d.ts +5 -3
- package/dist/utils/files/index.js +4 -3
- package/dist/utils/files/pdf.js +18 -36
- package/dist/utils/files/text.d.ts +21 -5
- package/dist/utils/files/text.js +90 -86
- package/dist/utils/internal-facts.d.ts +3 -0
- package/dist/utils/internal-facts.js +23 -0
- package/dist/utils/lazy-package.d.ts +25 -0
- package/dist/utils/lazy-package.js +44 -0
- package/dist/utils/open-browser.js +2 -1
- package/dist/utils/process-detection.d.ts +24 -5
- package/dist/utils/process-detection.js +199 -89
- package/dist/utils/process-tree.d.ts +14 -0
- package/dist/utils/process-tree.js +223 -0
- package/dist/utils/rename.d.ts +9 -0
- package/dist/utils/rename.js +74 -0
- package/dist/utils/ripgrep-resolver.js +9 -14
- package/dist/utils/shell.d.ts +42 -0
- package/dist/utils/shell.js +187 -0
- package/dist/utils/system-info.d.ts +1 -0
- package/dist/utils/system-info.js +40 -25
- package/dist/utils/trackTools.js +2 -1
- package/dist/utils/usageTracker.d.ts +0 -39
- package/dist/utils/usageTracker.js +1 -161
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
- package/package.json +32 -16
- package/vendor/telemetry-contract/README.md +56 -0
- package/vendor/telemetry-contract/package.json +32 -0
- package/vendor/telemetry-contract/transport.d.ts +38 -0
- package/vendor/telemetry-contract/transport.js +164 -0
- package/vendor/telemetry-contract/transport.test.js +39 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
type NodeKind = 'nvm' | 'fnm' | 'Volta' | 'asdf' | 'mise' | 'Homebrew' | "Claude Desktop's bundled Node" | 'global install' | 'unknown';
|
|
2
|
+
interface HostTiming {
|
|
3
|
+
host: string;
|
|
4
|
+
dnsMs?: number;
|
|
5
|
+
/** TLS handshake for https, TCP connect for http. */
|
|
6
|
+
connect?: {
|
|
7
|
+
kind: 'TLS' | 'TCP';
|
|
8
|
+
ms: number;
|
|
9
|
+
};
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface DiagnosticsReport {
|
|
13
|
+
format: 1;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
versions: {
|
|
16
|
+
desktopCommander: string;
|
|
17
|
+
node: string;
|
|
18
|
+
/** null: npm not found */
|
|
19
|
+
npm: string | null;
|
|
20
|
+
os: {
|
|
21
|
+
name: string;
|
|
22
|
+
release: string;
|
|
23
|
+
arch: string;
|
|
24
|
+
};
|
|
25
|
+
/** process.execPath, home folder as ~ */
|
|
26
|
+
nodePath: string;
|
|
27
|
+
nodeKind: NodeKind;
|
|
28
|
+
/** process.argv[1], home folder as ~ */
|
|
29
|
+
entryPath: string;
|
|
30
|
+
runKind: 'MCPB' | 'npx' | 'dev checkout' | 'global npm' | 'unknown';
|
|
31
|
+
};
|
|
32
|
+
clock: {
|
|
33
|
+
serverAheadSeconds: number | null;
|
|
34
|
+
error?: string;
|
|
35
|
+
};
|
|
36
|
+
network: {
|
|
37
|
+
server: HostTiming & {
|
|
38
|
+
mcpInfo: {
|
|
39
|
+
ms: number[];
|
|
40
|
+
statuses: number[];
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
supabase: (HostTiming & {
|
|
45
|
+
rest: {
|
|
46
|
+
status?: number;
|
|
47
|
+
ms?: number;
|
|
48
|
+
error?: string;
|
|
49
|
+
};
|
|
50
|
+
realtime: {
|
|
51
|
+
openedMs?: number;
|
|
52
|
+
heartbeat: boolean;
|
|
53
|
+
heartbeatMs?: number;
|
|
54
|
+
error?: string;
|
|
55
|
+
};
|
|
56
|
+
}) | {
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
59
|
+
proxy: {
|
|
60
|
+
httpsProxy: boolean;
|
|
61
|
+
httpProxy: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
device: {
|
|
65
|
+
deviceJson: boolean;
|
|
66
|
+
parses: boolean;
|
|
67
|
+
/** In full: support finds the device by it. null if missing or not id-shaped. */
|
|
68
|
+
id: string | null;
|
|
69
|
+
session: boolean;
|
|
70
|
+
accessToken: boolean;
|
|
71
|
+
refreshToken: boolean;
|
|
72
|
+
/** When device.json was last saved (its modification time), ISO in UTC. */
|
|
73
|
+
savedAt: string | null;
|
|
74
|
+
};
|
|
75
|
+
settings: {
|
|
76
|
+
telemetryEnabled: boolean | null;
|
|
77
|
+
clientId: string | null;
|
|
78
|
+
};
|
|
79
|
+
deviceLog: {
|
|
80
|
+
files: number;
|
|
81
|
+
lines: number;
|
|
82
|
+
first: string | null;
|
|
83
|
+
last: string | null;
|
|
84
|
+
lastText: string | null;
|
|
85
|
+
};
|
|
86
|
+
/** Copies of the MCP server running now, and the earliest start (ISO). null: the process list failed. */
|
|
87
|
+
desktopCommanderMcp: {
|
|
88
|
+
running: number | null;
|
|
89
|
+
since: string | null;
|
|
90
|
+
error?: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
interface LogPart {
|
|
94
|
+
name: string;
|
|
95
|
+
text: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Which installer the Node executable comes from, read from its path. A path
|
|
99
|
+
* none of these match is "unknown": the report shows the path itself anyway.
|
|
100
|
+
*/
|
|
101
|
+
export declare function nodeKind(execPath: string): NodeKind;
|
|
102
|
+
export declare function collectReport(): Promise<{
|
|
103
|
+
report: DiagnosticsReport;
|
|
104
|
+
logParts: LogPart[];
|
|
105
|
+
diagnosticsUrl: string | null;
|
|
106
|
+
}>;
|
|
107
|
+
export declare function formatReport(report: DiagnosticsReport): string;
|
|
108
|
+
/** Collects the report and writes the zip to the home folder; returns its bytes for the upload too. */
|
|
109
|
+
export declare function writeReport(): Promise<{
|
|
110
|
+
file: string;
|
|
111
|
+
bytes: number;
|
|
112
|
+
zip: Buffer;
|
|
113
|
+
report: DiagnosticsReport;
|
|
114
|
+
diagnosticsUrl: string | null;
|
|
115
|
+
}>;
|
|
116
|
+
/** `remote --report`: the terminal side. */
|
|
117
|
+
export declare function runReport(): Promise<void>;
|
|
118
|
+
export {};
|