@rse/claudex 1.0.13 → 1.0.15

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/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
  ChangeLog
3
3
  =========
4
4
 
5
+ 1.0.15 (2026-08-08)
6
+ -------------------
7
+
8
+ - IMPROVEMENT: support more package managers
9
+ - IMPROVEMENT: use package manager which was used to install a tool
10
+
11
+ 1.0.14 (2026-08-06)
12
+ -------------------
13
+
14
+ - BUGFIX: do not use sudo if not really required
15
+
5
16
  1.0.13 (2026-08-04)
6
17
  -------------------
7
18
 
package/claudex.js CHANGED
@@ -68,46 +68,88 @@ const isPsmux = () => {
68
68
  isPsmuxCached = process.platform === "win32" && findTool("psmux") !== null;
69
69
  return isPsmuxCached;
70
70
  };
71
+ /* the known package managers, in the order of their detection preference
72
+ (on Fedora "yum" is just an alias for "dnf", hence "dnf" comes first) */
73
+ const packageManagers = [
74
+ { name: "winget", plat: "win32", tool: "winget", key: "windows:winget" },
75
+ { name: "choco", plat: "win32", tool: "choco", key: "windows:choco" },
76
+ { name: "ports", plat: "darwin", tool: "port", key: "macos:ports" },
77
+ { name: "brew", plat: "darwin", tool: "brew", key: "macos:brew" },
78
+ { name: "apt", plat: "linux", tool: "apt", key: "linux:apt" },
79
+ { name: "dnf", plat: "linux", tool: "dnf", key: "linux:dnf" },
80
+ { name: "yum", plat: "linux", tool: "yum", key: "linux:yum" },
81
+ { name: "zypper", plat: "linux", tool: "zypper", key: "linux:zypper" },
82
+ { name: "pacman", plat: "linux", tool: "pacman", key: "linux:pacman" },
83
+ { name: "apk", plat: "linux", tool: "apk", key: "linux:apk" }
84
+ ];
71
85
  /* helper for detecting the platform and package manager combination */
72
86
  const detectPlatform = () => {
73
- /* helper function for finding a tool in PATH */
74
- const has = (tool) => findTool(tool) !== null;
75
87
  /* honor explicit override via CLAUDEX_PKG (e.g. "brew", "ports", "apt", ...)
76
88
  to disambiguate hosts where multiple package managers are installed */
77
89
  const override = process.env.CLAUDEX_PKG ?? "";
78
90
  if (override !== "") {
79
- const pm = {
80
- winget: { plat: "win32", tool: "winget", key: "windows:winget" },
81
- choco: { plat: "win32", tool: "choco", key: "windows:choco" },
82
- ports: { plat: "darwin", tool: "port", key: "macos:ports" },
83
- brew: { plat: "darwin", tool: "brew", key: "macos:brew" },
84
- apt: { plat: "linux", tool: "apt", key: "linux:apt" },
85
- apk: { plat: "linux", tool: "apk", key: "linux:apk" }
86
- };
87
- const entry = pm[override];
91
+ const entry = packageManagers.find((pm) => pm.name === override);
88
92
  if (entry === undefined)
89
93
  return fatal(`unknown CLAUDEX_PKG value "${override}" ` +
90
- `(allowed: ${Object.keys(pm).join(", ")})`);
94
+ `(allowed: ${packageManagers.map((pm) => pm.name).join(", ")})`);
91
95
  if (process.platform !== entry.plat)
92
96
  return fatal(`CLAUDEX_PKG="${override}" is not valid on platform "${process.platform}"`);
93
- if (!has(entry.tool))
97
+ if (findTool(entry.tool) === null)
94
98
  return fatal(`CLAUDEX_PKG="${override}" requested but tool "${entry.tool}" not found in $PATH`);
95
99
  return entry.key;
96
100
  }
97
- if (process.platform === "win32" && has("winget"))
98
- return "windows:winget";
99
- else if (process.platform === "win32" && has("choco"))
100
- return "windows:choco";
101
- else if (process.platform === "darwin" && has("port"))
102
- return "macos:ports";
103
- else if (process.platform === "darwin" && has("brew"))
104
- return "macos:brew";
105
- else if (process.platform === "linux" && has("apt"))
106
- return "linux:apt";
107
- else if (process.platform === "linux" && has("apk"))
108
- return "linux:apk";
109
- else
101
+ /* detect the first available package manager of the current platform */
102
+ const entry = packageManagers.find((pm) => pm.plat === process.platform && findTool(pm.tool) !== null);
103
+ if (entry === undefined)
110
104
  return fatal(`unsupported platform "${process.platform}" or no known package manager found`);
105
+ return entry.key;
106
+ };
107
+ /* helper for detecting the installation prefixes of the macOS package
108
+ managers, derived from the location of their own driver programs
109
+ (MacPorts: <prefix>/bin/port, Homebrew: <prefix>/bin/brew).
110
+ The result is cached after the first call. */
111
+ let macosPrefixesCached = null;
112
+ const macosPrefixes = () => {
113
+ if (macosPrefixesCached !== null)
114
+ return macosPrefixesCached;
115
+ macosPrefixesCached = [];
116
+ for (const pm of packageManagers.filter((pm) => pm.plat === "darwin")) {
117
+ const location = findTool(pm.tool);
118
+ if (location !== null)
119
+ macosPrefixesCached.push({ key: pm.key, prefix: path.dirname(path.dirname(location)) });
120
+ }
121
+ return macosPrefixesCached;
122
+ };
123
+ /* helper for detecting the package manager which provides an already
124
+ installed tool. On macOS, MacPorts and Homebrew can coexist and each
125
+ tool can originate from either of them, so the responsible manager is
126
+ determined by the installation prefix the tool resides in. On all
127
+ other platforms the single detected package manager applies. A "null"
128
+ result means the tool is not under control of a package manager. */
129
+ const detectPlatformForTool = (tool) => {
130
+ if (process.platform !== "darwin" || (process.env.CLAUDEX_PKG ?? "") !== "")
131
+ return detectPlatform();
132
+ const location = findTool(tool);
133
+ if (location === null)
134
+ return detectPlatform();
135
+ let target = location;
136
+ try {
137
+ target = fs.realpathSync(location);
138
+ }
139
+ catch (_e) {
140
+ /* intentionally ignored */
141
+ }
142
+ const below = (p, prefix) => p === prefix || p.startsWith(`${prefix}${path.sep}`);
143
+ for (const entry of macosPrefixes())
144
+ if (below(location, entry.prefix) || below(target, entry.prefix))
145
+ return entry.key;
146
+ /* the tool found in $PATH is none of the managed ones (it can be a
147
+ manually installed program or a wrapper shadowing the managed one),
148
+ so still check whether a package manager provides it, too */
149
+ for (const entry of macosPrefixes())
150
+ if (fs.existsSync(path.join(entry.prefix, "bin", tool)))
151
+ return entry.key;
152
+ return null;
111
153
  };
112
154
  /* helper to spawn a child synchronously inheriting stdio, then exit
113
155
  with its code (the closest equivalent of Bash "exec ...") */
@@ -121,10 +163,10 @@ const execInherit = (file, args, opts = {}) => {
121
163
  process.exit(r.exitCode ?? 0);
122
164
  };
123
165
  /* helper to execute a platform-specific command */
124
- const executeCommand = (config) => {
125
- const platform = detectPlatform();
166
+ const executeCommand = (config, platformOverride) => {
167
+ const platform = platformOverride ?? detectPlatform();
126
168
  const osName = platform.split(":")[0];
127
- const command = config[platform] ?? config[`${osName}:*`];
169
+ const command = config[platform] ?? config[`${osName}:*`] ?? config["*"];
128
170
  if (command === undefined)
129
171
  fatal(`no command configured for platform "${platform}"`);
130
172
  const cmd = command instanceof Array ? command : command.split(/\s+/);
@@ -137,6 +179,49 @@ const executeCommand = (config) => {
137
179
  });
138
180
  return result.exitCode;
139
181
  };
182
+ /* helper to update an externally managed tool with exactly the package
183
+ manager which actually provides it, instead of just the preferred one */
184
+ const updateTool = (tool, config) => {
185
+ const platform = detectPlatformForTool(tool);
186
+ if (platform === null) {
187
+ info(`skip update of "${tool}" (not provided by MacPorts or Homebrew)`);
188
+ return 0;
189
+ }
190
+ return executeCommand(config, platform);
191
+ };
192
+ /* helper to determine whether a global NPM installation requires sudo(8),
193
+ i.e., whether the target directories of the NPM global prefix are not
194
+ writable by us. The result is cached after the first call. */
195
+ let npmNeedsSudoCached = null;
196
+ const npmNeedsSudo = () => {
197
+ if (npmNeedsSudoCached !== null)
198
+ return npmNeedsSudoCached;
199
+ npmNeedsSudoCached = false;
200
+ if (process.platform === "win32" || (process.getuid?.() ?? 0) === 0 || findTool("sudo") === null)
201
+ return npmNeedsSudoCached;
202
+ const r = execaSync("npm", ["prefix", "-g"], { reject: false });
203
+ const prefix = (r.stdout ?? "").trim();
204
+ if ((r.exitCode ?? 1) !== 0 || prefix === "") {
205
+ /* on a failed detection stay with the conservative variant */
206
+ npmNeedsSudoCached = true;
207
+ return npmNeedsSudoCached;
208
+ }
209
+ npmNeedsSudoCached = ![path.join(prefix, "lib", "node_modules"), path.join(prefix, "bin")].every((dir) => {
210
+ /* fall back to the nearest already existing ancestor directory */
211
+ while (!fs.existsSync(dir) && path.dirname(dir) !== dir)
212
+ dir = path.dirname(dir);
213
+ try {
214
+ fs.accessSync(dir, fs.constants.W_OK);
215
+ return true;
216
+ }
217
+ catch (_e) {
218
+ return false;
219
+ }
220
+ });
221
+ return npmNeedsSudoCached;
222
+ };
223
+ /* helper to assemble a global NPM installation command */
224
+ const npmInstallGlobal = (...args) => `${npmNeedsSudo() ? "sudo " : ""}npm install -g ${args.join(" ")}`;
140
225
  /* helper to ensure a tool is available */
141
226
  const ensureTool = (tool, options = {}) => {
142
227
  const tools = typeof tool === "string" ? [tool] : tool;
@@ -295,6 +380,10 @@ const actionInstall = async (capsula) => {
295
380
  "macos:ports": "sudo port -N install tmux",
296
381
  "macos:brew": "brew install tmux",
297
382
  "linux:apt": "sudo apt install -y tmux",
383
+ "linux:dnf": "sudo dnf install -y tmux",
384
+ "linux:yum": "sudo yum install -y tmux",
385
+ "linux:zypper": "sudo zypper --non-interactive install tmux",
386
+ "linux:pacman": "sudo pacman -S --needed --noconfirm tmux",
298
387
  "linux:apk": "sudo apk add --no-interactive tmux"
299
388
  }
300
389
  });
@@ -308,6 +397,10 @@ const actionInstall = async (capsula) => {
308
397
  "macos:ports": "sudo port -N install lazygit",
309
398
  "macos:brew": "brew install lazygit",
310
399
  "linux:apt": "sudo apt install -y lazygit",
400
+ "linux:dnf": "sudo dnf install -y lazygit",
401
+ "linux:yum": "sudo yum install -y lazygit",
402
+ "linux:zypper": "sudo zypper --non-interactive install lazygit",
403
+ "linux:pacman": "sudo pacman -S --needed --noconfirm lazygit",
311
404
  "linux:apk": "sudo apk add --no-interactive lazygit"
312
405
  }
313
406
  });
@@ -321,6 +414,10 @@ const actionInstall = async (capsula) => {
321
414
  "macos:ports": "sudo port -N install git",
322
415
  "macos:brew": "brew install git",
323
416
  "linux:apt": "sudo apt install -y git",
417
+ "linux:dnf": "sudo dnf install -y git",
418
+ "linux:yum": "sudo yum install -y git",
419
+ "linux:zypper": "sudo zypper --non-interactive install git",
420
+ "linux:pacman": "sudo pacman -S --needed --noconfirm git",
324
421
  "linux:apk": "sudo apk add --no-interactive git"
325
422
  }
326
423
  });
@@ -333,6 +430,10 @@ const actionInstall = async (capsula) => {
333
430
  "macos:ports": "sudo port -N install nodejs26 npm11",
334
431
  "macos:brew": "brew install node",
335
432
  "linux:apt": "curl -fsSL https://deb.nodesource.com/setup_26.x | sudo -E bash - && sudo apt install -y nodejs",
433
+ "linux:dnf": "sudo dnf install -y nodejs npm",
434
+ "linux:yum": "sudo yum install -y nodejs npm",
435
+ "linux:zypper": "sudo zypper --non-interactive install nodejs npm",
436
+ "linux:pacman": "sudo pacman -S --needed --noconfirm nodejs npm",
336
437
  "linux:apk": "sudo apk add --no-interactive nodejs npm"
337
438
  }
338
439
  });
@@ -340,36 +441,28 @@ const actionInstall = async (capsula) => {
340
441
  ensureTool("ansi-recolor", {
341
442
  hint: "https://github.com/rse/ansi-recolor",
342
443
  install: {
343
- "windows:*": "npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
344
- "macos:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
345
- "linux:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor"
444
+ "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
346
445
  }
347
446
  });
348
447
  info("install TypeScript-Language-Server");
349
448
  ensureTool("typescript-language-server", {
350
449
  hint: "https://github.com/typescript-language-server/typescript-language-server",
351
450
  install: {
352
- "windows:*": "npm install -g typescript-language-server",
353
- "macos:*": "sudo npm install -g typescript-language-server",
354
- "linux:*": "sudo npm install -g typescript-language-server"
451
+ "*": npmInstallGlobal("typescript-language-server")
355
452
  }
356
453
  });
357
454
  info("install CodeBurn");
358
455
  ensureTool("codeburn", {
359
456
  hint: "https://www.npmjs.com/package/codeburn",
360
457
  install: {
361
- "windows:*": "npm install -g codeburn",
362
- "macos:*": "sudo npm install -g codeburn",
363
- "linux:*": "sudo npm install -g codeburn"
458
+ "*": npmInstallGlobal("codeburn")
364
459
  }
365
460
  });
366
461
  info("install ASE");
367
462
  ensureTool("ase", {
368
463
  hint: "https://ase.tools",
369
464
  install: {
370
- "windows:*": "npm install -g @rse/ase",
371
- "macos:*": "sudo npm install -g @rse/ase",
372
- "linux:*": "sudo npm install -g @rse/ase"
465
+ "*": npmInstallGlobal("@rse/ase")
373
466
  }
374
467
  });
375
468
  info("install Claude Code");
@@ -429,64 +522,72 @@ const actionUpdate = async (capsula) => {
429
522
  }
430
523
  else {
431
524
  info("update Tmux");
432
- executeCommand({
525
+ updateTool("tmux", {
433
526
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e psmux",
434
527
  "windows:choco": "choco upgrade -y --accept-license --no-progress psmux",
435
528
  "macos:ports": "sudo port -N upgrade tmux",
436
529
  "macos:brew": "brew upgrade tmux",
437
530
  "linux:apt": "sudo apt install --only-upgrade -y tmux",
531
+ "linux:dnf": "sudo dnf upgrade -y tmux",
532
+ "linux:yum": "sudo yum update -y tmux",
533
+ "linux:zypper": "sudo zypper --non-interactive update tmux",
534
+ "linux:pacman": "sudo pacman -S --noconfirm tmux",
438
535
  "linux:apk": "sudo apk upgrade --no-interactive tmux"
439
536
  });
440
537
  info("update LazyGit");
441
- executeCommand({
538
+ updateTool("lazygit", {
442
539
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
443
540
  "windows:choco": "choco upgrade -y --accept-license --no-progress lazygit",
444
541
  "macos:ports": "sudo port -N upgrade lazygit",
445
542
  "macos:brew": "brew upgrade lazygit",
446
543
  "linux:apt": "sudo apt install --only-upgrade -y lazygit",
544
+ "linux:dnf": "sudo dnf upgrade -y lazygit",
545
+ "linux:yum": "sudo yum update -y lazygit",
546
+ "linux:zypper": "sudo zypper --non-interactive update lazygit",
547
+ "linux:pacman": "sudo pacman -S --noconfirm lazygit",
447
548
  "linux:apk": "sudo apk upgrade --no-interactive lazygit"
448
549
  });
449
550
  info("update Git");
450
- executeCommand({
551
+ updateTool("git", {
451
552
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
452
553
  "windows:choco": "choco upgrade -y --accept-license --no-progress git",
453
554
  "macos:ports": "sudo port -N upgrade git",
454
555
  "macos:brew": "brew upgrade git",
455
556
  "linux:apt": "sudo apt install --only-upgrade -y git",
557
+ "linux:dnf": "sudo dnf upgrade -y git",
558
+ "linux:yum": "sudo yum update -y git",
559
+ "linux:zypper": "sudo zypper --non-interactive update git",
560
+ "linux:pacman": "sudo pacman -S --noconfirm git",
456
561
  "linux:apk": "sudo apk upgrade --no-interactive git"
457
562
  });
458
563
  info("update Node.js");
459
- executeCommand({
564
+ updateTool("node", {
460
565
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
461
566
  "windows:choco": "choco upgrade -y --accept-license --no-progress nodejs",
462
567
  "macos:ports": "sudo port -N upgrade nodejs26 npm11",
463
568
  "macos:brew": "brew upgrade node",
464
569
  "linux:apt": "sudo apt install --only-upgrade -y nodejs",
570
+ "linux:dnf": "sudo dnf upgrade -y nodejs npm",
571
+ "linux:yum": "sudo yum update -y nodejs npm",
572
+ "linux:zypper": "sudo zypper --non-interactive update nodejs npm",
573
+ "linux:pacman": "sudo pacman -S --noconfirm nodejs npm",
465
574
  "linux:apk": "sudo apk upgrade --no-interactive nodejs npm"
466
575
  });
467
576
  info("update ANSI-Recolor");
468
577
  executeCommand({
469
- "windows:*": "npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
470
- "macos:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
471
- "linux:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor"
578
+ "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
472
579
  });
473
580
  info("update TypeScript-Language-Server");
474
581
  executeCommand({
475
- "windows:*": "npm install -g typescript-language-server",
476
- "macos:*": "sudo npm install -g typescript-language-server",
477
- "linux:*": "sudo npm install -g typescript-language-server"
582
+ "*": npmInstallGlobal("typescript-language-server")
478
583
  });
479
584
  info("update CodeBurn");
480
585
  executeCommand({
481
- "windows:*": "npm install -g codeburn",
482
- "macos:*": "sudo npm install -g codeburn",
483
- "linux:*": "sudo npm install -g codeburn"
586
+ "*": npmInstallGlobal("codeburn")
484
587
  });
485
588
  info("update ASE");
486
589
  executeCommand({
487
- "windows:*": "npm install -g @rse/ase",
488
- "macos:*": "sudo npm install -g @rse/ase",
489
- "linux:*": "sudo npm install -g @rse/ase"
590
+ "*": npmInstallGlobal("@rse/ase")
490
591
  });
491
592
  info("update Claude Code");
492
593
  if (process.platform !== "win32") {
package/claudex.ts CHANGED
@@ -79,48 +79,95 @@ const isPsmux = (): boolean => {
79
79
  return isPsmuxCached
80
80
  }
81
81
 
82
+ /* the known package managers, in the order of their detection preference
83
+ (on Fedora "yum" is just an alias for "dnf", hence "dnf" comes first) */
84
+ const packageManagers: { name: string, plat: string, tool: string, key: string }[] = [
85
+ { name: "winget", plat: "win32", tool: "winget", key: "windows:winget" },
86
+ { name: "choco", plat: "win32", tool: "choco", key: "windows:choco" },
87
+ { name: "ports", plat: "darwin", tool: "port", key: "macos:ports" },
88
+ { name: "brew", plat: "darwin", tool: "brew", key: "macos:brew" },
89
+ { name: "apt", plat: "linux", tool: "apt", key: "linux:apt" },
90
+ { name: "dnf", plat: "linux", tool: "dnf", key: "linux:dnf" },
91
+ { name: "yum", plat: "linux", tool: "yum", key: "linux:yum" },
92
+ { name: "zypper", plat: "linux", tool: "zypper", key: "linux:zypper" },
93
+ { name: "pacman", plat: "linux", tool: "pacman", key: "linux:pacman" },
94
+ { name: "apk", plat: "linux", tool: "apk", key: "linux:apk" }
95
+ ]
96
+
82
97
  /* helper for detecting the platform and package manager combination */
83
98
  const detectPlatform = (): string => {
84
- /* helper function for finding a tool in PATH */
85
- const has = (tool: string): boolean =>
86
- findTool(tool) !== null
87
-
88
99
  /* honor explicit override via CLAUDEX_PKG (e.g. "brew", "ports", "apt", ...)
89
100
  to disambiguate hosts where multiple package managers are installed */
90
101
  const override = process.env.CLAUDEX_PKG ?? ""
91
102
  if (override !== "") {
92
- const pm: Record<string, { plat: string, tool: string, key: string }> = {
93
- winget: { plat: "win32", tool: "winget", key: "windows:winget" },
94
- choco: { plat: "win32", tool: "choco", key: "windows:choco" },
95
- ports: { plat: "darwin", tool: "port", key: "macos:ports" },
96
- brew: { plat: "darwin", tool: "brew", key: "macos:brew" },
97
- apt: { plat: "linux", tool: "apt", key: "linux:apt" },
98
- apk: { plat: "linux", tool: "apk", key: "linux:apk" }
99
- }
100
- const entry = pm[override]
103
+ const entry = packageManagers.find((pm) => pm.name === override)
101
104
  if (entry === undefined)
102
105
  return fatal(`unknown CLAUDEX_PKG value "${override}" ` +
103
- `(allowed: ${Object.keys(pm).join(", ")})`)
106
+ `(allowed: ${packageManagers.map((pm) => pm.name).join(", ")})`)
104
107
  if (process.platform !== entry.plat)
105
108
  return fatal(`CLAUDEX_PKG="${override}" is not valid on platform "${process.platform}"`)
106
- if (!has(entry.tool))
109
+ if (findTool(entry.tool) === null)
107
110
  return fatal(`CLAUDEX_PKG="${override}" requested but tool "${entry.tool}" not found in $PATH`)
108
111
  return entry.key
109
112
  }
110
- if (process.platform === "win32" && has("winget"))
111
- return "windows:winget"
112
- else if (process.platform === "win32" && has("choco"))
113
- return "windows:choco"
114
- else if (process.platform === "darwin" && has("port"))
115
- return "macos:ports"
116
- else if (process.platform === "darwin" && has("brew"))
117
- return "macos:brew"
118
- else if (process.platform === "linux" && has("apt"))
119
- return "linux:apt"
120
- else if (process.platform === "linux" && has("apk"))
121
- return "linux:apk"
122
- else
113
+
114
+ /* detect the first available package manager of the current platform */
115
+ const entry = packageManagers.find((pm) =>
116
+ pm.plat === process.platform && findTool(pm.tool) !== null)
117
+ if (entry === undefined)
123
118
  return fatal(`unsupported platform "${process.platform}" or no known package manager found`)
119
+ return entry.key
120
+ }
121
+
122
+ /* helper for detecting the installation prefixes of the macOS package
123
+ managers, derived from the location of their own driver programs
124
+ (MacPorts: <prefix>/bin/port, Homebrew: <prefix>/bin/brew).
125
+ The result is cached after the first call. */
126
+ let macosPrefixesCached: { key: string, prefix: string }[] | null = null
127
+ const macosPrefixes = (): { key: string, prefix: string }[] => {
128
+ if (macosPrefixesCached !== null)
129
+ return macosPrefixesCached
130
+ macosPrefixesCached = []
131
+ for (const pm of packageManagers.filter((pm) => pm.plat === "darwin")) {
132
+ const location = findTool(pm.tool)
133
+ if (location !== null)
134
+ macosPrefixesCached.push({ key: pm.key, prefix: path.dirname(path.dirname(location)) })
135
+ }
136
+ return macosPrefixesCached
137
+ }
138
+
139
+ /* helper for detecting the package manager which provides an already
140
+ installed tool. On macOS, MacPorts and Homebrew can coexist and each
141
+ tool can originate from either of them, so the responsible manager is
142
+ determined by the installation prefix the tool resides in. On all
143
+ other platforms the single detected package manager applies. A "null"
144
+ result means the tool is not under control of a package manager. */
145
+ const detectPlatformForTool = (tool: string): string | null => {
146
+ if (process.platform !== "darwin" || (process.env.CLAUDEX_PKG ?? "") !== "")
147
+ return detectPlatform()
148
+ const location = findTool(tool)
149
+ if (location === null)
150
+ return detectPlatform()
151
+ let target = location
152
+ try {
153
+ target = fs.realpathSync(location)
154
+ }
155
+ catch (_e) {
156
+ /* intentionally ignored */
157
+ }
158
+ const below = (p: string, prefix: string): boolean =>
159
+ p === prefix || p.startsWith(`${prefix}${path.sep}`)
160
+ for (const entry of macosPrefixes())
161
+ if (below(location, entry.prefix) || below(target, entry.prefix))
162
+ return entry.key
163
+
164
+ /* the tool found in $PATH is none of the managed ones (it can be a
165
+ manually installed program or a wrapper shadowing the managed one),
166
+ so still check whether a package manager provides it, too */
167
+ for (const entry of macosPrefixes())
168
+ if (fs.existsSync(path.join(entry.prefix, "bin", tool)))
169
+ return entry.key
170
+ return null
124
171
  }
125
172
 
126
173
  /* helper to spawn a child synchronously inheriting stdio, then exit
@@ -136,10 +183,10 @@ const execInherit = (file: string, args: string[], opts: { env?: Env } = {}): ne
136
183
  }
137
184
 
138
185
  /* helper to execute a platform-specific command */
139
- const executeCommand = (config: { [ platform: string ]: string[] | string }) => {
140
- const platform = detectPlatform()
186
+ const executeCommand = (config: { [ platform: string ]: string[] | string }, platformOverride?: string) => {
187
+ const platform = platformOverride ?? detectPlatform()
141
188
  const osName = platform.split(":")[0]
142
- const command = config[platform] ?? config[`${osName}:*`]
189
+ const command = config[platform] ?? config[`${osName}:*`] ?? config["*"]
143
190
  if (command === undefined)
144
191
  fatal(`no command configured for platform "${platform}"`)
145
192
  const cmd = command instanceof Array ? command : command.split(/\s+/)
@@ -153,6 +200,53 @@ const executeCommand = (config: { [ platform: string ]: string[] | string }) =>
153
200
  return result.exitCode
154
201
  }
155
202
 
203
+ /* helper to update an externally managed tool with exactly the package
204
+ manager which actually provides it, instead of just the preferred one */
205
+ const updateTool = (tool: string, config: { [ platform: string ]: string[] | string }) => {
206
+ const platform = detectPlatformForTool(tool)
207
+ if (platform === null) {
208
+ info(`skip update of "${tool}" (not provided by MacPorts or Homebrew)`)
209
+ return 0
210
+ }
211
+ return executeCommand(config, platform)
212
+ }
213
+
214
+ /* helper to determine whether a global NPM installation requires sudo(8),
215
+ i.e., whether the target directories of the NPM global prefix are not
216
+ writable by us. The result is cached after the first call. */
217
+ let npmNeedsSudoCached: boolean | null = null
218
+ const npmNeedsSudo = (): boolean => {
219
+ if (npmNeedsSudoCached !== null)
220
+ return npmNeedsSudoCached
221
+ npmNeedsSudoCached = false
222
+ if (process.platform === "win32" || (process.getuid?.() ?? 0) === 0 || findTool("sudo") === null)
223
+ return npmNeedsSudoCached
224
+ const r = execaSync("npm", [ "prefix", "-g" ], { reject: false })
225
+ const prefix = (r.stdout ?? "").trim()
226
+ if ((r.exitCode ?? 1) !== 0 || prefix === "") {
227
+ /* on a failed detection stay with the conservative variant */
228
+ npmNeedsSudoCached = true
229
+ return npmNeedsSudoCached
230
+ }
231
+ npmNeedsSudoCached = ![ path.join(prefix, "lib", "node_modules"), path.join(prefix, "bin") ].every((dir) => {
232
+ /* fall back to the nearest already existing ancestor directory */
233
+ while (!fs.existsSync(dir) && path.dirname(dir) !== dir)
234
+ dir = path.dirname(dir)
235
+ try {
236
+ fs.accessSync(dir, fs.constants.W_OK)
237
+ return true
238
+ }
239
+ catch (_e) {
240
+ return false
241
+ }
242
+ })
243
+ return npmNeedsSudoCached
244
+ }
245
+
246
+ /* helper to assemble a global NPM installation command */
247
+ const npmInstallGlobal = (...args: string[]): string =>
248
+ `${npmNeedsSudo() ? "sudo " : ""}npm install -g ${args.join(" ")}`
249
+
156
250
  /* helper to ensure a tool is available */
157
251
  const ensureTool = (tool: string | string[], options: {
158
252
  install?: { [ platform: string ]: string[] | string },
@@ -343,6 +437,10 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
343
437
  "macos:ports": "sudo port -N install tmux",
344
438
  "macos:brew": "brew install tmux",
345
439
  "linux:apt": "sudo apt install -y tmux",
440
+ "linux:dnf": "sudo dnf install -y tmux",
441
+ "linux:yum": "sudo yum install -y tmux",
442
+ "linux:zypper": "sudo zypper --non-interactive install tmux",
443
+ "linux:pacman": "sudo pacman -S --needed --noconfirm tmux",
346
444
  "linux:apk": "sudo apk add --no-interactive tmux"
347
445
  }
348
446
  })
@@ -357,6 +455,10 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
357
455
  "macos:ports": "sudo port -N install lazygit",
358
456
  "macos:brew": "brew install lazygit",
359
457
  "linux:apt": "sudo apt install -y lazygit",
458
+ "linux:dnf": "sudo dnf install -y lazygit",
459
+ "linux:yum": "sudo yum install -y lazygit",
460
+ "linux:zypper": "sudo zypper --non-interactive install lazygit",
461
+ "linux:pacman": "sudo pacman -S --needed --noconfirm lazygit",
360
462
  "linux:apk": "sudo apk add --no-interactive lazygit"
361
463
  }
362
464
  })
@@ -371,6 +473,10 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
371
473
  "macos:ports": "sudo port -N install git",
372
474
  "macos:brew": "brew install git",
373
475
  "linux:apt": "sudo apt install -y git",
476
+ "linux:dnf": "sudo dnf install -y git",
477
+ "linux:yum": "sudo yum install -y git",
478
+ "linux:zypper": "sudo zypper --non-interactive install git",
479
+ "linux:pacman": "sudo pacman -S --needed --noconfirm git",
374
480
  "linux:apk": "sudo apk add --no-interactive git"
375
481
  }
376
482
  })
@@ -384,6 +490,10 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
384
490
  "macos:ports": "sudo port -N install nodejs26 npm11",
385
491
  "macos:brew": "brew install node",
386
492
  "linux:apt": "curl -fsSL https://deb.nodesource.com/setup_26.x | sudo -E bash - && sudo apt install -y nodejs",
493
+ "linux:dnf": "sudo dnf install -y nodejs npm",
494
+ "linux:yum": "sudo yum install -y nodejs npm",
495
+ "linux:zypper": "sudo zypper --non-interactive install nodejs npm",
496
+ "linux:pacman": "sudo pacman -S --needed --noconfirm nodejs npm",
387
497
  "linux:apk": "sudo apk add --no-interactive nodejs npm"
388
498
  }
389
499
  })
@@ -392,9 +502,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
392
502
  ensureTool("ansi-recolor", {
393
503
  hint: "https://github.com/rse/ansi-recolor",
394
504
  install: {
395
- "windows:*": "npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
396
- "macos:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
397
- "linux:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor"
505
+ "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
398
506
  }
399
507
  })
400
508
 
@@ -402,9 +510,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
402
510
  ensureTool("typescript-language-server", {
403
511
  hint: "https://github.com/typescript-language-server/typescript-language-server",
404
512
  install: {
405
- "windows:*": "npm install -g typescript-language-server",
406
- "macos:*": "sudo npm install -g typescript-language-server",
407
- "linux:*": "sudo npm install -g typescript-language-server"
513
+ "*": npmInstallGlobal("typescript-language-server")
408
514
  }
409
515
  })
410
516
 
@@ -412,9 +518,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
412
518
  ensureTool("codeburn", {
413
519
  hint: "https://www.npmjs.com/package/codeburn",
414
520
  install: {
415
- "windows:*": "npm install -g codeburn",
416
- "macos:*": "sudo npm install -g codeburn",
417
- "linux:*": "sudo npm install -g codeburn"
521
+ "*": npmInstallGlobal("codeburn")
418
522
  }
419
523
  })
420
524
 
@@ -422,9 +526,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
422
526
  ensureTool("ase", {
423
527
  hint: "https://ase.tools",
424
528
  install: {
425
- "windows:*": "npm install -g @rse/ase",
426
- "macos:*": "sudo npm install -g @rse/ase",
427
- "linux:*": "sudo npm install -g @rse/ase"
529
+ "*": npmInstallGlobal("@rse/ase")
428
530
  }
429
531
  })
430
532
 
@@ -497,71 +599,79 @@ const actionUpdate = async (capsula: boolean): Promise<void> => {
497
599
  }
498
600
  else {
499
601
  info("update Tmux")
500
- executeCommand({
602
+ updateTool("tmux", {
501
603
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e psmux",
502
604
  "windows:choco": "choco upgrade -y --accept-license --no-progress psmux",
503
605
  "macos:ports": "sudo port -N upgrade tmux",
504
606
  "macos:brew": "brew upgrade tmux",
505
607
  "linux:apt": "sudo apt install --only-upgrade -y tmux",
608
+ "linux:dnf": "sudo dnf upgrade -y tmux",
609
+ "linux:yum": "sudo yum update -y tmux",
610
+ "linux:zypper": "sudo zypper --non-interactive update tmux",
611
+ "linux:pacman": "sudo pacman -S --noconfirm tmux",
506
612
  "linux:apk": "sudo apk upgrade --no-interactive tmux"
507
613
  })
508
614
 
509
615
  info("update LazyGit")
510
- executeCommand({
616
+ updateTool("lazygit", {
511
617
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
512
618
  "windows:choco": "choco upgrade -y --accept-license --no-progress lazygit",
513
619
  "macos:ports": "sudo port -N upgrade lazygit",
514
620
  "macos:brew": "brew upgrade lazygit",
515
621
  "linux:apt": "sudo apt install --only-upgrade -y lazygit",
622
+ "linux:dnf": "sudo dnf upgrade -y lazygit",
623
+ "linux:yum": "sudo yum update -y lazygit",
624
+ "linux:zypper": "sudo zypper --non-interactive update lazygit",
625
+ "linux:pacman": "sudo pacman -S --noconfirm lazygit",
516
626
  "linux:apk": "sudo apk upgrade --no-interactive lazygit"
517
627
  })
518
628
 
519
629
  info("update Git")
520
- executeCommand({
630
+ updateTool("git", {
521
631
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
522
632
  "windows:choco": "choco upgrade -y --accept-license --no-progress git",
523
633
  "macos:ports": "sudo port -N upgrade git",
524
634
  "macos:brew": "brew upgrade git",
525
635
  "linux:apt": "sudo apt install --only-upgrade -y git",
636
+ "linux:dnf": "sudo dnf upgrade -y git",
637
+ "linux:yum": "sudo yum update -y git",
638
+ "linux:zypper": "sudo zypper --non-interactive update git",
639
+ "linux:pacman": "sudo pacman -S --noconfirm git",
526
640
  "linux:apk": "sudo apk upgrade --no-interactive git"
527
641
  })
528
642
 
529
643
  info("update Node.js")
530
- executeCommand({
644
+ updateTool("node", {
531
645
  "windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
532
646
  "windows:choco": "choco upgrade -y --accept-license --no-progress nodejs",
533
647
  "macos:ports": "sudo port -N upgrade nodejs26 npm11",
534
648
  "macos:brew": "brew upgrade node",
535
649
  "linux:apt": "sudo apt install --only-upgrade -y nodejs",
650
+ "linux:dnf": "sudo dnf upgrade -y nodejs npm",
651
+ "linux:yum": "sudo yum update -y nodejs npm",
652
+ "linux:zypper": "sudo zypper --non-interactive update nodejs npm",
653
+ "linux:pacman": "sudo pacman -S --noconfirm nodejs npm",
536
654
  "linux:apk": "sudo apk upgrade --no-interactive nodejs npm"
537
655
  })
538
656
 
539
657
  info("update ANSI-Recolor")
540
658
  executeCommand({
541
- "windows:*": "npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
542
- "macos:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor",
543
- "linux:*": "sudo npm install -g --allow-scripts=node-pty,tty-attr ansi-recolor"
659
+ "*": npmInstallGlobal("--allow-scripts=node-pty,tty-attr", "ansi-recolor")
544
660
  })
545
661
 
546
662
  info("update TypeScript-Language-Server")
547
663
  executeCommand({
548
- "windows:*": "npm install -g typescript-language-server",
549
- "macos:*": "sudo npm install -g typescript-language-server",
550
- "linux:*": "sudo npm install -g typescript-language-server"
664
+ "*": npmInstallGlobal("typescript-language-server")
551
665
  })
552
666
 
553
667
  info("update CodeBurn")
554
668
  executeCommand({
555
- "windows:*": "npm install -g codeburn",
556
- "macos:*": "sudo npm install -g codeburn",
557
- "linux:*": "sudo npm install -g codeburn"
669
+ "*": npmInstallGlobal("codeburn")
558
670
  })
559
671
 
560
672
  info("update ASE")
561
673
  executeCommand({
562
- "windows:*": "npm install -g @rse/ase",
563
- "macos:*": "sudo npm install -g @rse/ase",
564
- "linux:*": "sudo npm install -g @rse/ase"
674
+ "*": npmInstallGlobal("@rse/ase")
565
675
  })
566
676
 
567
677
  info("update Claude Code")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rse/claudex",
3
3
  "publishConfig": { "access": "public" },
4
- "version": "1.0.13",
4
+ "version": "1.0.15",
5
5
  "description": "Claude Code eXtended",
6
6
  "type": "module",
7
7
  "keywords": [ "claude", "code", "extension", "wrapper" ],
package/stx.conf CHANGED
@@ -10,7 +10,7 @@ build
10
10
  tsc --project tsconfig.json
11
11
 
12
12
  # publish to github.com and npmjs.com
13
- publish [hostname=en4.*]
13
+ publish [hostname={en4.*,MSGMAC-M2M79300K6}]
14
14
  increment="patch"; \
15
15
  case "$*" in -i* ) increment=`echo "$*" | sed -e 's;^-i;;'` ;; esac; \
16
16
  kickout "$increment" && \