@wonderwhy-er/desktop-commander 0.2.52 → 0.3.1-alpha.1

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 (137) 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.d.ts +7 -2
  5. package/dist/command-manager.js +16 -11
  6. package/dist/config-field-definitions.js +0 -0
  7. package/dist/config-manager.d.ts +55 -3
  8. package/dist/config-manager.js +329 -87
  9. package/dist/config-recovery.d.ts +28 -0
  10. package/dist/config-recovery.js +81 -0
  11. package/dist/config.d.ts +1 -0
  12. package/dist/config.js +9 -0
  13. package/dist/custom-stdio.js +0 -0
  14. package/dist/data/onboarding-prompts.json +70 -70
  15. package/dist/error-handlers.js +0 -0
  16. package/dist/handlers/filesystem-handlers.d.ts +1 -1
  17. package/dist/handlers/filesystem-handlers.js +28 -18
  18. package/dist/handlers/search-answers.d.ts +58 -0
  19. package/dist/handlers/search-answers.js +172 -0
  20. package/dist/handlers/search-handlers.js +4 -92
  21. package/dist/index.js +14 -7
  22. package/dist/npm-scripts/remote.js +36 -22
  23. package/dist/remote-device/desktop-commander-integration.js +19 -25
  24. package/dist/remote-device/device.d.ts +14 -0
  25. package/dist/remote-device/device.js +137 -30
  26. package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
  27. package/dist/remote-device/diagnostics/device-log.js +219 -0
  28. package/dist/remote-device/diagnostics/redact.d.ts +1 -0
  29. package/dist/remote-device/diagnostics/redact.js +76 -0
  30. package/dist/remote-device/diagnostics/report.d.ts +118 -0
  31. package/dist/remote-device/diagnostics/report.js +748 -0
  32. package/dist/remote-device/diagnostics/upload.d.ts +11 -0
  33. package/dist/remote-device/diagnostics/upload.js +59 -0
  34. package/dist/remote-device/remote-channel.d.ts +12 -0
  35. package/dist/remote-device/remote-channel.js +55 -8
  36. package/dist/remote-device/scripts/blocking-offline-update.js +133 -96
  37. package/dist/remote-device/transport-telemetry.d.ts +32 -0
  38. package/dist/remote-device/transport-telemetry.js +48 -0
  39. package/dist/search-manager.d.ts +239 -27
  40. package/dist/search-manager.js +746 -312
  41. package/dist/server.js +654 -621
  42. package/dist/setup-claude-server.js +942 -942
  43. package/dist/terminal-manager.d.ts +138 -21
  44. package/dist/terminal-manager.js +300 -215
  45. package/dist/tools/config.d.ts +1 -1
  46. package/dist/tools/config.js +21 -70
  47. package/dist/tools/edit.js +14 -6
  48. package/dist/tools/filesystem.d.ts +30 -6
  49. package/dist/tools/filesystem.js +246 -140
  50. package/dist/tools/fuzzySearch.js +9 -9
  51. package/dist/tools/improved-process-tools.d.ts +9 -3
  52. package/dist/tools/improved-process-tools.js +181 -78
  53. package/dist/tools/pdf/extract-images.d.ts +2 -0
  54. package/dist/tools/pdf/extract-images.js +4 -1
  55. package/dist/tools/pdf/index.d.ts +5 -3
  56. package/dist/tools/pdf/index.js +4 -3
  57. package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
  58. package/dist/tools/pdf/lib/pdf2md.js +12 -5
  59. package/dist/tools/pdf/manipulations.d.ts +12 -1
  60. package/dist/tools/pdf/manipulations.js +17 -4
  61. package/dist/tools/pdf/markdown.d.ts +96 -0
  62. package/dist/tools/pdf/markdown.js +485 -20
  63. package/dist/tools/pdf/utils.d.ts +2 -2
  64. package/dist/tools/pdf/utils.js +4 -4
  65. package/dist/tools/process.js +8 -5
  66. package/dist/tools/prompts.js +1 -1
  67. package/dist/tools/schemas.d.ts +1 -1
  68. package/dist/tools/schemas.js +15 -6
  69. package/dist/track-installation.js +387 -387
  70. package/dist/types.d.ts +1 -1
  71. package/dist/types.js +0 -0
  72. package/dist/ui/config-editor/config-editor-runtime.js +6 -6
  73. package/dist/ui/config-editor/index.html +13 -13
  74. package/dist/ui/config-editor/src/app.js +32 -45
  75. package/dist/ui/config-editor/src/array-modal.js +32 -32
  76. package/dist/ui/config-editor/styles.css +586 -586
  77. package/dist/ui/file-preview/index.html +16 -16
  78. package/dist/ui/file-preview/src/app.js +8 -8
  79. package/dist/ui/file-preview/src/document-layout.js +31 -31
  80. package/dist/ui/file-preview/src/document-outline.js +8 -8
  81. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
  82. package/dist/ui/file-preview/src/markdown/controller.js +9 -9
  83. package/dist/ui/file-preview/src/markdown/editor.js +31 -31
  84. package/dist/ui/file-preview/styles.css +1630 -1630
  85. package/dist/uninstall-claude-server.js +745 -745
  86. package/dist/utils/ab-test.js +27 -9
  87. package/dist/utils/atomic-write.d.ts +14 -0
  88. package/dist/utils/atomic-write.js +80 -0
  89. package/dist/utils/capture.d.ts +17 -1
  90. package/dist/utils/capture.js +177 -68
  91. package/dist/utils/exit-process.d.ts +24 -0
  92. package/dist/utils/exit-process.js +31 -0
  93. package/dist/utils/feature-flags.js +2 -1
  94. package/dist/utils/files/base.d.ts +3 -1
  95. package/dist/utils/files/binary.js +4 -4
  96. package/dist/utils/files/docx.d.ts +3 -0
  97. package/dist/utils/files/docx.js +24 -9
  98. package/dist/utils/files/excel.d.ts +10 -0
  99. package/dist/utils/files/excel.js +96 -36
  100. package/dist/utils/files/factory.d.ts +22 -1
  101. package/dist/utils/files/factory.js +59 -4
  102. package/dist/utils/files/image.d.ts +12 -4
  103. package/dist/utils/files/image.js +19 -8
  104. package/dist/utils/files/index.d.ts +5 -3
  105. package/dist/utils/files/index.js +4 -3
  106. package/dist/utils/files/pdf.js +18 -36
  107. package/dist/utils/files/text.d.ts +21 -5
  108. package/dist/utils/files/text.js +90 -86
  109. package/dist/utils/internal-facts.d.ts +3 -0
  110. package/dist/utils/internal-facts.js +23 -0
  111. package/dist/utils/lazy-package.d.ts +23 -0
  112. package/dist/utils/lazy-package.js +42 -0
  113. package/dist/utils/open-browser.js +2 -1
  114. package/dist/utils/process-detection.d.ts +24 -5
  115. package/dist/utils/process-detection.js +199 -89
  116. package/dist/utils/process-tree.d.ts +14 -0
  117. package/dist/utils/process-tree.js +223 -0
  118. package/dist/utils/rename.d.ts +9 -0
  119. package/dist/utils/rename.js +74 -0
  120. package/dist/utils/ripgrep-resolver.js +9 -14
  121. package/dist/utils/shell.d.ts +42 -0
  122. package/dist/utils/shell.js +187 -0
  123. package/dist/utils/system-info.js +99 -97
  124. package/dist/utils/trackTools.js +2 -1
  125. package/dist/utils/usageTracker.js +49 -49
  126. package/dist/version.d.ts +1 -1
  127. package/dist/version.js +1 -1
  128. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
  129. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
  130. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
  131. package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
  132. package/package.json +10 -3
  133. package/vendor/telemetry-contract/README.md +56 -0
  134. package/vendor/telemetry-contract/package.json +32 -0
  135. package/vendor/telemetry-contract/transport.d.ts +38 -0
  136. package/vendor/telemetry-contract/transport.js +164 -0
  137. package/vendor/telemetry-contract/transport.test.js +39 -0
@@ -1,7 +1,7 @@
1
- import { execSync } from 'child_process';
2
1
  import { existsSync, chmodSync } from 'fs';
3
2
  import path from 'path';
4
3
  import os from 'os';
4
+ import { resolveShellPath } from './shell.js';
5
5
  let cachedRgPath = null;
6
6
  /**
7
7
  * Resolve ripgrep binary path with multiple fallback strategies
@@ -31,23 +31,18 @@ export async function getRipgrepPath() {
31
31
  catch (e) {
32
32
  // @vscode/ripgrep import or binary resolution failed, continue to fallbacks
33
33
  }
34
- // Strategy 2: Try system ripgrep using 'which' (Unix) or 'where' (Windows)
35
- try {
36
- const systemRg = process.platform === 'win32' ? 'rg.exe' : 'rg';
37
- const whichCmd = process.platform === 'win32' ? 'where' : 'which';
38
- const result = execSync(`${whichCmd} ${systemRg}`, { encoding: 'utf-8' }).trim().split(/\r?\n/)[0];
39
- if (result && existsSync(result)) {
40
- cachedRgPath = result;
41
- return result;
42
- }
43
- }
44
- catch (e) {
45
- // System rg not found via which
34
+ // Strategy 2: system ripgrep on PATH (never the working folder, which
35
+ // 'where' searched first on Windows)
36
+ const systemRg = resolveShellPath(process.platform === 'win32' ? 'rg.exe' : 'rg');
37
+ if (systemRg) {
38
+ cachedRgPath = systemRg;
39
+ return systemRg;
46
40
  }
47
41
  // Strategy 3: Try common installation paths
48
42
  const commonPaths = [];
49
43
  if (process.platform === 'win32') {
50
- commonPaths.push('C:\\Program Files\\Ripgrep\\rg.exe', 'C:\\Program Files (x86)\\Ripgrep\\rg.exe', path.join(os.homedir(), 'scoop', 'apps', 'ripgrep', 'current', 'rg.exe'), path.join(os.homedir(), '.cargo', 'bin', 'rg.exe'));
44
+ // Windows' own Program Files folders, which aren't always on C:
45
+ commonPaths.push(path.join(process.env.ProgramFiles ?? 'C:\\Program Files', 'Ripgrep', 'rg.exe'), path.join(process.env['ProgramFiles(x86)'] ?? 'C:\\Program Files (x86)', 'Ripgrep', 'rg.exe'), path.join(os.homedir(), 'scoop', 'apps', 'ripgrep', 'current', 'rg.exe'), path.join(os.homedir(), '.cargo', 'bin', 'rg.exe'));
51
46
  }
52
47
  else {
53
48
  commonPaths.push('/usr/local/bin/rg', '/usr/bin/rg', path.join(os.homedir(), '.cargo', 'bin', 'rg'), '/opt/homebrew/bin/rg' // Apple Silicon Homebrew
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Resolves a shell or other program name ("pwsh", "bash.exe", "where") or path
3
+ * ("/bin/zsh") to an executable file. Bare names are searched in PATH's
4
+ * folders only, never the working folder. Returns null when it can't be found.
5
+ */
6
+ export declare function resolveShellPath(shell: string): string | null;
7
+ export declare function isShellAvailable(shell: string): boolean;
8
+ /**
9
+ * The full path to start a program by: the one found on PATH. Windows looks
10
+ * for a bare name ("powershell.exe", "cmd", "tasklist") in the working folder
11
+ * before PATH, so a file of that name there would run instead; every program
12
+ * Desktop Commander starts by name goes through here. On Windows a bare name
13
+ * not found on PATH is an error rather than a name Windows would look up in
14
+ * the working folder. A path (absolute, or with a folder in it) is kept as
15
+ * given, and so is a bare name elsewhere, where the working folder isn't searched.
16
+ */
17
+ export declare function resolveProgramPath(program: string): string;
18
+ /**
19
+ * The shell used when the user hasn't configured one.
20
+ * Windows: Windows PowerShell, falling back to %ComSpec%.
21
+ * macOS/Linux: $SHELL, falling back to the OS default shell.
22
+ */
23
+ export declare function getDefaultShell(): string;
24
+ /**
25
+ * Shells installed on this machine, default shell first. Only shells that
26
+ * resolve to an executable are returned.
27
+ */
28
+ export declare function detectAvailableShells(): string[];
29
+ /**
30
+ * Configuration for spawning a shell with appropriate flags
31
+ */
32
+ export interface ShellSpawnConfig {
33
+ executable: string;
34
+ args: string[];
35
+ useShellOption: string | boolean;
36
+ windowsVerbatim?: boolean;
37
+ }
38
+ /**
39
+ * Get the appropriate spawn configuration for a given shell
40
+ * This handles login shell flags for different shell types
41
+ */
42
+ export declare function getShellSpawnArgs(shellPath: string, command: string): ShellSpawnConfig;
@@ -0,0 +1,187 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ /**
5
+ * Single source of truth for shells: which shell is the default on this
6
+ * machine, which shells are installed, and how to invoke each of them.
7
+ * Config defaults, system info, process tools, the terminal manager and the
8
+ * config editor all derive their shell choices from here.
9
+ */
10
+ // Shell executables Windows can host. Which of them exist is resolved on PATH.
11
+ const WINDOWS_SHELLS = ['powershell.exe', 'pwsh.exe', 'cmd.exe', 'bash.exe'];
12
+ function isWindows() {
13
+ return os.platform() === 'win32';
14
+ }
15
+ function isExecutableFile(filePath) {
16
+ try {
17
+ fs.accessSync(filePath, isWindows() ? fs.constants.F_OK : fs.constants.X_OK);
18
+ return fs.statSync(filePath).isFile();
19
+ }
20
+ catch {
21
+ // Missing or not executable: this candidate isn't a usable shell, the next one is tried
22
+ return false;
23
+ }
24
+ }
25
+ function windowsExecutableExtensions() {
26
+ const fromEnv = (process.env.PATHEXT ?? '').split(';').map((ext) => ext.trim()).filter(Boolean);
27
+ return [...new Set(['.EXE', ...fromEnv])];
28
+ }
29
+ /**
30
+ * Resolves a shell or other program name ("pwsh", "bash.exe", "where") or path
31
+ * ("/bin/zsh") to an executable file. Bare names are searched in PATH's
32
+ * folders only, never the working folder. Returns null when it can't be found.
33
+ */
34
+ export function resolveShellPath(shell) {
35
+ const name = shell.trim();
36
+ if (!name)
37
+ return null;
38
+ if (path.isAbsolute(name) || name.includes('/') || name.includes('\\')) {
39
+ return isExecutableFile(name) ? name : null;
40
+ }
41
+ const extensions = isWindows() && !path.extname(name) ? windowsExecutableExtensions() : [''];
42
+ const pathDirs = (process.env.PATH ?? '').split(path.delimiter)
43
+ .map((dir) => dir.trim().replace(/^"(.*)"$/, '$1'))
44
+ .filter(Boolean);
45
+ for (const dir of pathDirs) {
46
+ for (const ext of extensions) {
47
+ const candidate = path.join(dir, name + ext);
48
+ if (isExecutableFile(candidate))
49
+ return candidate;
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+ export function isShellAvailable(shell) {
55
+ return resolveShellPath(shell) !== null;
56
+ }
57
+ /**
58
+ * The full path to start a program by: the one found on PATH. Windows looks
59
+ * for a bare name ("powershell.exe", "cmd", "tasklist") in the working folder
60
+ * before PATH, so a file of that name there would run instead; every program
61
+ * Desktop Commander starts by name goes through here. On Windows a bare name
62
+ * not found on PATH is an error rather than a name Windows would look up in
63
+ * the working folder. A path (absolute, or with a folder in it) is kept as
64
+ * given, and so is a bare name elsewhere, where the working folder isn't searched.
65
+ */
66
+ export function resolveProgramPath(program) {
67
+ const resolved = resolveShellPath(program);
68
+ if (resolved)
69
+ return resolved;
70
+ const name = program.trim();
71
+ if (isWindows() && !name.includes('/') && !name.includes('\\')) {
72
+ throw new Error(`${name} was not found on PATH`);
73
+ }
74
+ return program;
75
+ }
76
+ /**
77
+ * The shell used when the user hasn't configured one.
78
+ * Windows: Windows PowerShell, falling back to %ComSpec%.
79
+ * macOS/Linux: $SHELL, falling back to the OS default shell.
80
+ */
81
+ export function getDefaultShell() {
82
+ if (isWindows()) {
83
+ if (isShellAvailable('powershell.exe'))
84
+ return 'powershell.exe';
85
+ return process.env.ComSpec || 'cmd.exe';
86
+ }
87
+ const userShell = process.env.SHELL;
88
+ if (userShell && isShellAvailable(userShell))
89
+ return userShell;
90
+ // $SHELL may be unset when launched from a GUI app such as Claude Desktop.
91
+ // zsh is the macOS default since Catalina; /bin/sh is guaranteed by POSIX.
92
+ return os.platform() === 'darwin' ? '/bin/zsh' : '/bin/sh';
93
+ }
94
+ // Login programs /etc/shells can list that don't run a command given with -c,
95
+ // the way every command here starts: terminal multiplexers (screen, tmux),
96
+ // git-shell (git commands only), and programs that refuse a login
97
+ const NOT_COMMAND_SHELLS = new Set(['nologin', 'false', 'true', 'sync', 'git-shell', 'screen', 'tmux']);
98
+ function readEtcShells() {
99
+ try {
100
+ return fs.readFileSync('/etc/shells', 'utf8')
101
+ .split(/\r?\n/)
102
+ .map((line) => line.trim())
103
+ .filter((line) => line.length > 0 && !line.startsWith('#'))
104
+ .filter((line) => !NOT_COMMAND_SHELLS.has(path.basename(line)));
105
+ }
106
+ catch {
107
+ // Best-effort discovery only: no readable /etc/shells means no extra shells to list
108
+ return [];
109
+ }
110
+ }
111
+ /**
112
+ * Shells installed on this machine, default shell first. Only shells that
113
+ * resolve to an executable are returned.
114
+ */
115
+ export function detectAvailableShells() {
116
+ const shells = new Set();
117
+ const add = (shell) => {
118
+ const value = shell?.trim();
119
+ if (value && isShellAvailable(value))
120
+ shells.add(value);
121
+ };
122
+ add(getDefaultShell());
123
+ if (isWindows()) {
124
+ WINDOWS_SHELLS.forEach(add);
125
+ }
126
+ else {
127
+ add(process.env.SHELL);
128
+ readEtcShells().forEach(add);
129
+ }
130
+ return [...shells];
131
+ }
132
+ /**
133
+ * Get the appropriate spawn configuration for a given shell
134
+ * This handles login shell flags for different shell types
135
+ */
136
+ export function getShellSpawnArgs(shellPath, command) {
137
+ const shellName = path.basename(shellPath).toLowerCase();
138
+ const executable = resolveProgramPath(shellPath);
139
+ // Unix shells with login flag support
140
+ if (shellName.includes('bash') || shellName.includes('zsh')) {
141
+ return {
142
+ executable,
143
+ args: ['-l', '-c', command],
144
+ useShellOption: false
145
+ };
146
+ }
147
+ // PowerShell Core (cross-platform, supports -Login)
148
+ if (shellName === 'pwsh' || shellName === 'pwsh.exe') {
149
+ return {
150
+ executable,
151
+ args: ['-Login', '-Command', command],
152
+ useShellOption: false
153
+ };
154
+ }
155
+ // Windows PowerShell 5.1 (no login flag support)
156
+ if (shellName === 'powershell' || shellName === 'powershell.exe') {
157
+ return {
158
+ executable,
159
+ args: ['-Command', command],
160
+ useShellOption: false
161
+ };
162
+ }
163
+ // CMD
164
+ if (shellName === 'cmd' || shellName === 'cmd.exe') {
165
+ return {
166
+ executable,
167
+ args: ['/c', command],
168
+ windowsVerbatim: true,
169
+ useShellOption: false
170
+ };
171
+ }
172
+ // Fish shell (uses -l for login, -c for command)
173
+ if (shellName.includes('fish')) {
174
+ return {
175
+ executable,
176
+ args: ['-l', '-c', command],
177
+ useShellOption: false
178
+ };
179
+ }
180
+ // Unknown/other shells - use shell option for safety
181
+ // This provides a fallback for shells we don't explicitly handle
182
+ return {
183
+ executable: command,
184
+ args: [],
185
+ useShellOption: executable
186
+ };
187
+ }
@@ -1,7 +1,8 @@
1
1
  import os from 'os';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
- import { execSync } from 'child_process';
4
+ import { execFileSync } from 'child_process';
5
+ import { getDefaultShell, resolveShellPath } from './shell.js';
5
6
  /**
6
7
  * Detect container environment and type
7
8
  */
@@ -370,8 +371,13 @@ function detectPythonInfo() {
370
371
  ? ['python', 'python3', 'py'] // Windows: 'python' is common, 'py' launcher
371
372
  : ['python3', 'python']; // Unix: prefer python3
372
373
  for (const cmd of pythonCommands) {
374
+ // The python on PATH, never one in the working folder (which Windows
375
+ // searches first for a bare name); not on PATH means not available
376
+ const program = resolveShellPath(cmd);
377
+ if (!program)
378
+ continue;
373
379
  try {
374
- const version = execSync(`${cmd} --version`, {
380
+ const version = execFileSync(program, ['--version'], {
375
381
  encoding: 'utf8',
376
382
  timeout: 5000,
377
383
  stdio: ['pipe', 'pipe', 'pipe']
@@ -403,12 +409,11 @@ export function getSystemInfo() {
403
409
  const containerDetection = detectContainerEnvironment();
404
410
  const mountPoints = containerDetection.isContainer ? discoverContainerMounts(containerDetection.isContainer) : [];
405
411
  let platformName;
406
- let defaultShell;
412
+ const defaultShell = getDefaultShell();
407
413
  let pathSeparator;
408
414
  let examplePaths;
409
415
  if (isWindows) {
410
416
  platformName = 'Windows';
411
- defaultShell = 'powershell.exe';
412
417
  pathSeparator = '\\';
413
418
  examplePaths = {
414
419
  home: 'C:\\Users\\username',
@@ -418,7 +423,6 @@ export function getSystemInfo() {
418
423
  }
419
424
  else if (isMacOS) {
420
425
  platformName = 'macOS';
421
- defaultShell = 'zsh';
422
426
  pathSeparator = '/';
423
427
  examplePaths = {
424
428
  home: '/Users/username',
@@ -428,7 +432,6 @@ export function getSystemInfo() {
428
432
  }
429
433
  else if (isLinux) {
430
434
  platformName = 'Linux';
431
- defaultShell = 'bash';
432
435
  pathSeparator = '/';
433
436
  examplePaths = {
434
437
  home: '/home/username',
@@ -439,7 +442,6 @@ export function getSystemInfo() {
439
442
  else {
440
443
  // Fallback for other Unix-like systems
441
444
  platformName = 'Unix';
442
- defaultShell = 'bash';
443
445
  pathSeparator = '/';
444
446
  examplePaths = {
445
447
  home: '/home/username',
@@ -533,28 +535,28 @@ export function getOSSpecificGuidance(systemInfo) {
533
535
  docker.containerType === 'lxc' ? 'LXC CONTAINER' :
534
536
  docker.containerType === 'systemd-nspawn' ? 'SYSTEMD-NSPAWN CONTAINER' :
535
537
  'CONTAINER';
536
- guidance += `
537
-
538
+ guidance += `
539
+
538
540
  🐳 ${containerTypeLabel} ENVIRONMENT DETECTED:`;
539
541
  if (docker.containerType === 'kubernetes') {
540
- guidance += `
542
+ guidance += `
541
543
  This Desktop Commander instance is running inside a Kubernetes pod.`;
542
544
  // Add Kubernetes-specific info
543
545
  if (docker.containerEnvironment?.kubernetesNamespace) {
544
- guidance += `
546
+ guidance += `
545
547
  Namespace: ${docker.containerEnvironment.kubernetesNamespace}`;
546
548
  }
547
549
  if (docker.containerEnvironment?.kubernetesPod) {
548
- guidance += `
550
+ guidance += `
549
551
  Pod: ${docker.containerEnvironment.kubernetesPod}`;
550
552
  }
551
553
  if (docker.containerEnvironment?.kubernetesNode) {
552
- guidance += `
554
+ guidance += `
553
555
  Node: ${docker.containerEnvironment.kubernetesNode}`;
554
556
  }
555
557
  }
556
558
  else if (docker.containerType === 'docker') {
557
- guidance += `
559
+ guidance += `
558
560
  This Desktop Commander instance is running inside a Docker container.`;
559
561
  if (docker.orchestrator === 'docker-compose') {
560
562
  guidance += ` (Docker Compose)`;
@@ -564,80 +566,80 @@ This Desktop Commander instance is running inside a Docker container.`;
564
566
  }
565
567
  }
566
568
  else {
567
- guidance += `
569
+ guidance += `
568
570
  This Desktop Commander instance is running inside a ${docker.containerType || 'container'} environment.`;
569
571
  }
570
572
  if (docker.mountPoints.length > 0) {
571
- guidance += `
572
-
573
+ guidance += `
574
+
573
575
  AVAILABLE MOUNTED DIRECTORIES:`;
574
576
  for (const mount of docker.mountPoints) {
575
577
  const access = mount.readOnly ? '(read-only)' : '(read-write)';
576
- guidance += `
578
+ guidance += `
577
579
  - ${mount.containerPath} ${access} - ${mount.description}`;
578
580
  }
579
- guidance += `
580
-
581
- IMPORTANT: When users ask about files, FIRST check mounted directories above.
582
- Files outside these paths will be lost when the container stops.
583
- Always suggest using mounted directories for file operations.
584
-
585
- PATH TRANSLATION IN DOCKER:
586
- When users provide host paths, translate to container paths:
587
-
588
- Windows: "C:\\projects\\data\\file.txt" → "/home/projects/data/file.txt"
589
- Linux/Mac: "/Users/john/projects/data/file.txt" → "/home/projects/data/file.txt"
590
-
591
- Rules: Remove drive letter/user prefix, keep full folder structure, mount to /home/
592
-
581
+ guidance += `
582
+
583
+ IMPORTANT: When users ask about files, FIRST check mounted directories above.
584
+ Files outside these paths will be lost when the container stops.
585
+ Always suggest using mounted directories for file operations.
586
+
587
+ PATH TRANSLATION IN DOCKER:
588
+ When users provide host paths, translate to container paths:
589
+
590
+ Windows: "C:\\projects\\data\\file.txt" → "/home/projects/data/file.txt"
591
+ Linux/Mac: "/Users/john/projects/data/file.txt" → "/home/projects/data/file.txt"
592
+
593
+ Rules: Remove drive letter/user prefix, keep full folder structure, mount to /home/
594
+
593
595
  NOTE: Desktop Commander Docker installer mounts host folders to /home/[folder-name].`;
594
596
  }
595
597
  else {
596
- guidance += `
597
-
598
- ⚠️ WARNING: No mounted directories detected.
599
- Files created outside mounted volumes will be lost when the container stops.
600
- Suggest user remount directories using Docker installer or -v flag when running Docker.
598
+ guidance += `
599
+
600
+ ⚠️ WARNING: No mounted directories detected.
601
+ Files created outside mounted volumes will be lost when the container stops.
602
+ Suggest user remount directories using Docker installer or -v flag when running Docker.
601
603
  Desktop Commander Docker installer typically mounts folders to /home/[folder-name].`;
602
604
  }
603
605
  if (docker.containerEnvironment?.containerName) {
604
- guidance += `
606
+ guidance += `
605
607
  Container: ${docker.containerEnvironment.containerName}`;
606
608
  }
607
609
  }
608
610
  if (isWindows) {
609
- guidance += `
610
-
611
- WINDOWS-SPECIFIC TROUBLESHOOTING:
612
- - If Node.js/Python commands fail with "not recognized" errors:
613
- * Try different shells: specify shell parameter as "cmd" or "powershell.exe"
614
- * PowerShell may have execution policy restrictions for some tools
615
- * CMD typically has better compatibility with development tools
616
- * Use set_config_value to change defaultShell if needed
617
- - Windows services and processes use different commands (Get-Process vs ps)
618
- - Package managers: choco, winget, scoop instead of apt/brew
619
- - Environment variables: $env:VAR instead of $VAR
611
+ guidance += `
612
+
613
+ WINDOWS-SPECIFIC TROUBLESHOOTING:
614
+ - If Node.js/Python commands fail with "not recognized" errors:
615
+ * Try different shells: specify shell parameter as "cmd" or "powershell.exe"
616
+ * PowerShell may have execution policy restrictions for some tools
617
+ * CMD typically has better compatibility with development tools
618
+ * Use set_config_value to change defaultShell if needed
619
+ - Windows services and processes use different commands (Get-Process vs ps)
620
+ - Package managers: choco, winget, scoop instead of apt/brew
621
+ - Environment variables: $env:VAR instead of $VAR
620
622
  - File permissions work differently than Unix systems`;
621
623
  }
622
624
  else if (systemInfo.isMacOS) {
623
- guidance += `
624
-
625
- MACOS-SPECIFIC NOTES:
626
- - Package manager: brew (Homebrew) is commonly used
627
- - Python 3 might be 'python3' command, not 'python'
628
- - Some GNU tools have different names (e.g., gsed instead of sed)
629
- - System Integrity Protection (SIP) may block certain operations
630
- - Use 'open' command to open files/applications from terminal
625
+ guidance += `
626
+
627
+ MACOS-SPECIFIC NOTES:
628
+ - Package manager: brew (Homebrew) is commonly used
629
+ - Python 3 might be 'python3' command, not 'python'
630
+ - Some GNU tools have different names (e.g., gsed instead of sed)
631
+ - System Integrity Protection (SIP) may block certain operations
632
+ - Use 'open' command to open files/applications from terminal
631
633
  - For file search: Use mdfind (Spotlight) for fastest exact filename searches`;
632
634
  }
633
635
  else {
634
- guidance += `
635
-
636
- LINUX-SPECIFIC NOTES:
637
- - Package managers vary by distro: apt, yum, dnf, pacman, zypper
638
- - Python 3 might be 'python3' command, not 'python'
639
- - Standard Unix shell tools available (grep, awk, sed, etc.)
640
- - File permissions and ownership important for many operations
636
+ guidance += `
637
+
638
+ LINUX-SPECIFIC NOTES:
639
+ - Package managers vary by distro: apt, yum, dnf, pacman, zypper
640
+ - Python 3 might be 'python3' command, not 'python'
641
+ - Standard Unix shell tools available (grep, awk, sed, etc.)
642
+ - File permissions and ownership important for many operations
641
643
  - Systemd services common on modern distributions`;
642
644
  }
643
645
  return guidance;
@@ -652,44 +654,44 @@ export function getDevelopmentToolGuidance(systemInfo) {
652
654
  ? `Node.js: v${nodeInfo.version} (${nodeInfo.path})${nodeInfo.npmVersion ? ` | npm: v${nodeInfo.npmVersion}` : ''}`
653
655
  : 'Node.js: Not detected';
654
656
  // Add process environment info
655
- const envInfo = `
656
- Current Process Environment:
657
- - Node: v${processInfo.versions.node}
658
- - V8: v${processInfo.versions.v8}
659
- - Architecture: ${processInfo.arch}
660
- - Platform: ${processInfo.platform}
657
+ const envInfo = `
658
+ Current Process Environment:
659
+ - Node: v${processInfo.versions.node}
660
+ - V8: v${processInfo.versions.v8}
661
+ - Architecture: ${processInfo.arch}
662
+ - Platform: ${processInfo.platform}
661
663
  - Process ID: ${processInfo.pid}`;
662
664
  if (isWindows) {
663
- return `
664
- COMMON WINDOWS DEVELOPMENT TOOLS:
665
- - ${nodeGuidance}
666
- - Python: May be 'python' or 'py' command, check both
667
- - Git: Git Bash provides Unix-like environment
668
- - WSL: Windows Subsystem for Linux available for Unix tools
669
- - Visual Studio tools: cl, msbuild for C++ compilation
670
-
665
+ return `
666
+ COMMON WINDOWS DEVELOPMENT TOOLS:
667
+ - ${nodeGuidance}
668
+ - Python: May be 'python' or 'py' command, check both
669
+ - Git: Git Bash provides Unix-like environment
670
+ - WSL: Windows Subsystem for Linux available for Unix tools
671
+ - Visual Studio tools: cl, msbuild for C++ compilation
672
+
671
673
  ${envInfo}`;
672
674
  }
673
675
  else if (isMacOS) {
674
- return `
675
- COMMON MACOS DEVELOPMENT TOOLS:
676
- - Xcode Command Line Tools: Required for many development tools
677
- - Homebrew: Primary package manager for development tools
678
- - ${nodeGuidance}
679
- - Python: Usually python3, check if python points to Python 2
680
- - Ruby: System Ruby available, rbenv/rvm for version management
681
-
676
+ return `
677
+ COMMON MACOS DEVELOPMENT TOOLS:
678
+ - Xcode Command Line Tools: Required for many development tools
679
+ - Homebrew: Primary package manager for development tools
680
+ - ${nodeGuidance}
681
+ - Python: Usually python3, check if python points to Python 2
682
+ - Ruby: System Ruby available, rbenv/rvm for version management
683
+
682
684
  ${envInfo}`;
683
685
  }
684
686
  else {
685
- return `
686
- COMMON LINUX DEVELOPMENT TOOLS:
687
- - Package managers: Install tools via distribution package manager
688
- - Python: Usually python3, python may point to Python 2
689
- - ${nodeGuidance}
690
- - Build tools: gcc, make typically available or easily installed
691
- - Container tools: docker, podman common for development
692
-
687
+ return `
688
+ COMMON LINUX DEVELOPMENT TOOLS:
689
+ - Package managers: Install tools via distribution package manager
690
+ - Python: Usually python3, python may point to Python 2
691
+ - ${nodeGuidance}
692
+ - Build tools: gcc, make typically available or easily installed
693
+ - Container tools: docker, podman common for development
694
+
693
695
  ${envInfo}`;
694
696
  }
695
697
  }
@@ -703,9 +705,9 @@ export function getPathGuidance(systemInfo) {
703
705
  systemInfo.docker.containerType === 'docker' ? 'DOCKER' :
704
706
  systemInfo.docker.containerType === 'podman' ? 'PODMAN' :
705
707
  'CONTAINER';
706
- guidance += `
707
-
708
- 🐳 ${containerLabel}: Prefer paths within mounted directories: ${systemInfo.docker.mountPoints.map(m => m.containerPath).join(', ')}.
708
+ guidance += `
709
+
710
+ 🐳 ${containerLabel}: Prefer paths within mounted directories: ${systemInfo.docker.mountPoints.map(m => m.containerPath).join(', ')}.
709
711
  When users ask about file locations, check these mounted paths first.`;
710
712
  }
711
713
  return guidance;
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { TOOL_CALL_FILE, TOOL_CALL_FILE_MAX_SIZE } from '../config.js';
4
+ import { renameWithRetry } from './rename.js';
4
5
  // Ensure the directory for the log file exists
5
6
  const logDir = path.dirname(TOOL_CALL_FILE);
6
7
  await fs.promises.mkdir(logDir, { recursive: true });
@@ -34,7 +35,7 @@ export async function trackToolCall(toolName, args) {
34
35
  const rotateTimestamp = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}_${String(date.getHours()).padStart(2, '0')}-${String(date.getMinutes()).padStart(2, '0')}-${String(date.getSeconds()).padStart(2, '0')}`;
35
36
  const newFileName = path.join(dirName, `${fileBase}_${rotateTimestamp}${fileExt}`);
36
37
  // Rename the current file
37
- await fs.promises.rename(TOOL_CALL_FILE, newFileName);
38
+ await renameWithRetry(TOOL_CALL_FILE, newFileName);
38
39
  }
39
40
  // Append to log file (if file was renamed, this will create a new file)
40
41
  await fs.promises.appendFile(TOOL_CALL_FILE, logEntry, 'utf8');