@rse/claudex 0.9.13 → 0.9.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/.claude/CLAUDE.md +1 -0
- package/AGENTS.md +69 -0
- package/CHANGELOG.md +160 -0
- package/LICENSE.txt +674 -0
- package/README.md +18 -33
- package/ansi-recolor.conf +3 -1
- package/claude +11 -13
- package/claude-settings.json +8 -0
- package/claudex +2 -1
- package/claudex.js +773 -569
- package/claudex.ts +829 -596
- package/eslint.mjs +1 -1
- package/lazygit.yaml +5 -0
- package/package.json +5 -3
- package/stx.conf +1 -1
- package/tmux.conf +11 -5
package/claudex.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*!
|
|
3
3
|
** claudeX -- Claude Code eXtended
|
|
4
4
|
** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
5
|
-
** Licensed under
|
|
5
|
+
** Licensed under GPL 3.0 <https://spdx.org/licenses/GPL-3.0-only>
|
|
6
6
|
*/
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
@@ -10,6 +10,8 @@ import * as os from "node:os";
|
|
|
10
10
|
import { execa, execaSync } from "execa";
|
|
11
11
|
import which from "which";
|
|
12
12
|
import chalk from "chalk";
|
|
13
|
+
import deepmerge from "deepmerge";
|
|
14
|
+
import { Command } from "commander";
|
|
13
15
|
/* determine our base directory (handle absolute, relative, PATH, symlinks) */
|
|
14
16
|
const findBaseDir = () => {
|
|
15
17
|
const argv1 = process.argv[1] ?? "";
|
|
@@ -28,8 +30,6 @@ const basedir = findBaseDir();
|
|
|
28
30
|
and embedded shell strings (docker/tmux) need a runnable command */
|
|
29
31
|
const selfPath = path.join(basedir, "claudex");
|
|
30
32
|
const selfPathJS = process.argv[1] ?? path.join(basedir, "claudex.js");
|
|
31
|
-
/* command line arguments (after node and script path) */
|
|
32
|
-
let argv = process.argv.slice(2);
|
|
33
33
|
/* helper for displaying info messages */
|
|
34
34
|
const info = (msg) => {
|
|
35
35
|
process.stderr.write(`${chalk.blue("claudex: ")}${chalk.blue.bold("INFO:")}${chalk.blue(` ${msg}`)}\n`);
|
|
@@ -42,6 +42,28 @@ const fatal = (msg) => {
|
|
|
42
42
|
/* helper for detecting the platform and package manager combination */
|
|
43
43
|
const detectPlatform = () => {
|
|
44
44
|
const has = (tool) => which.sync(tool, { nothrow: true }) !== null;
|
|
45
|
+
/* honor explicit override via CLAUDEX_PKG (e.g. "brew", "ports", "apt", ...)
|
|
46
|
+
to disambiguate hosts where multiple package managers are installed */
|
|
47
|
+
const override = process.env.CLAUDEX_PKG ?? "";
|
|
48
|
+
if (override !== "") {
|
|
49
|
+
const pm = {
|
|
50
|
+
winget: { plat: "win32", tool: "winget", key: "windows:winget" },
|
|
51
|
+
choco: { plat: "win32", tool: "choco", key: "windows:choco" },
|
|
52
|
+
ports: { plat: "darwin", tool: "port", key: "macos:ports" },
|
|
53
|
+
brew: { plat: "darwin", tool: "brew", key: "macos:brew" },
|
|
54
|
+
apt: { plat: "linux", tool: "apt", key: "linux:apt" },
|
|
55
|
+
apk: { plat: "linux", tool: "apk", key: "linux:apk" }
|
|
56
|
+
};
|
|
57
|
+
const entry = pm[override];
|
|
58
|
+
if (entry === undefined)
|
|
59
|
+
return fatal(`unknown CLAUDEX_PKG value "${override}" ` +
|
|
60
|
+
`(allowed: ${Object.keys(pm).join(", ")})`);
|
|
61
|
+
if (process.platform !== entry.plat)
|
|
62
|
+
return fatal(`CLAUDEX_PKG="${override}" is not valid on platform "${process.platform}"`);
|
|
63
|
+
if (!has(entry.tool))
|
|
64
|
+
return fatal(`CLAUDEX_PKG="${override}" requested but tool "${entry.tool}" not found in $PATH`);
|
|
65
|
+
return entry.key;
|
|
66
|
+
}
|
|
45
67
|
if (process.platform === "win32" && has("winget"))
|
|
46
68
|
return "windows:winget";
|
|
47
69
|
else if (process.platform === "win32" && has("choco"))
|
|
@@ -59,8 +81,8 @@ const detectPlatform = () => {
|
|
|
59
81
|
};
|
|
60
82
|
/* helper to spawn a child synchronously inheriting stdio, then exit
|
|
61
83
|
with its code (the closest equivalent of Bash "exec ...") */
|
|
62
|
-
const execInherit =
|
|
63
|
-
const r =
|
|
84
|
+
const execInherit = (file, args, opts = {}) => {
|
|
85
|
+
const r = execaSync(file, args, {
|
|
64
86
|
stdio: "inherit",
|
|
65
87
|
env: opts.env,
|
|
66
88
|
reject: false,
|
|
@@ -74,7 +96,7 @@ const executeCommand = (config) => {
|
|
|
74
96
|
const osName = platform.split(":")[0];
|
|
75
97
|
const command = config[platform] ?? config[`${osName}:*`];
|
|
76
98
|
if (command === undefined)
|
|
77
|
-
|
|
99
|
+
fatal(`no command configured for platform "${platform}"`);
|
|
78
100
|
const cmd = command instanceof Array ? command : command.split(/\s+/);
|
|
79
101
|
info(`execute: $ ${cmd.join(" ")}`);
|
|
80
102
|
const result = execaSync(cmd[0], cmd.slice(1), {
|
|
@@ -89,22 +111,31 @@ const executeCommand = (config) => {
|
|
|
89
111
|
const ensureTool = (tool, options = {}) => {
|
|
90
112
|
const tools = typeof tool === "string" ? [tool] : tool;
|
|
91
113
|
for (const tool of tools) {
|
|
92
|
-
|
|
93
|
-
if (r === null) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
114
|
+
let r = which.sync(tool, { nothrow: true });
|
|
115
|
+
if (r === null && options.install) {
|
|
116
|
+
const rc = executeCommand(options.install);
|
|
117
|
+
if (rc !== 0) {
|
|
118
|
+
if (options.optional)
|
|
97
119
|
continue;
|
|
120
|
+
fatal(`failed to install required tool "${tool}" (exit ${rc})` +
|
|
121
|
+
(options.hint !== undefined ? ` -- hint: ${options.hint}` : ""));
|
|
98
122
|
}
|
|
99
|
-
|
|
100
|
-
continue;
|
|
101
|
-
if (options.hint !== undefined)
|
|
102
|
-
fatal(`required tool "${tool}" not found in $PATH -- hint: ${options.hint}`);
|
|
103
|
-
else
|
|
104
|
-
fatal(`required tool "${tool}" not found in $PATH`);
|
|
123
|
+
r = which.sync(tool, { nothrow: true });
|
|
105
124
|
}
|
|
125
|
+
if (r !== null)
|
|
126
|
+
continue;
|
|
127
|
+
if (options.optional)
|
|
128
|
+
continue;
|
|
129
|
+
if (options.hint !== undefined)
|
|
130
|
+
fatal(`required tool "${tool}" not found in $PATH -- hint: ${options.hint}`);
|
|
131
|
+
else
|
|
132
|
+
fatal(`required tool "${tool}" not found in $PATH`);
|
|
106
133
|
}
|
|
107
134
|
};
|
|
135
|
+
/* helper to POSIX-single-quote-escape a string for safe interpolation
|
|
136
|
+
into a "bash -c" command line (defense against shell injection of
|
|
137
|
+
user-supplied or env-derived values) */
|
|
138
|
+
const shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
|
|
108
139
|
/* re-invoke this same script (mirrors "$0 ..." in Bash) */
|
|
109
140
|
const self = async (...args) => {
|
|
110
141
|
const r = await execa(process.execPath, [selfPathJS, ...args], {
|
|
@@ -115,585 +146,758 @@ const self = async (...args) => {
|
|
|
115
146
|
process.exit(r.exitCode ?? 1);
|
|
116
147
|
return r.exitCode ?? 0;
|
|
117
148
|
};
|
|
118
|
-
/*
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
process.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const cmd = argv[0];
|
|
136
|
-
argv = argv.slice(1);
|
|
149
|
+
/* detect the session/project name by walking up from the current working
|
|
150
|
+
directory looking for an AGENTS.md / CLAUDE.md marker; fall back to the
|
|
151
|
+
basename of the current working directory */
|
|
152
|
+
const detectSessionName = () => {
|
|
153
|
+
let dir = process.cwd();
|
|
154
|
+
while (true) {
|
|
155
|
+
if (fs.existsSync(path.join(dir, "AGENTS.md")) || fs.existsSync(path.join(dir, "CLAUDE.md")))
|
|
156
|
+
return path.basename(dir);
|
|
157
|
+
const parent = path.dirname(dir);
|
|
158
|
+
if (parent === dir)
|
|
159
|
+
break;
|
|
160
|
+
dir = parent;
|
|
161
|
+
}
|
|
162
|
+
const session = path.basename(process.cwd()) || "default";
|
|
163
|
+
info(`no AGENTS.md/CLAUDE.md marker found; using cwd basename "${session}" as session name`);
|
|
164
|
+
return session;
|
|
165
|
+
};
|
|
137
166
|
/* determine information */
|
|
138
167
|
const HOME = process.env.HOME ?? os.homedir();
|
|
139
168
|
const USER = process.env.USER ?? "";
|
|
140
169
|
const TERM = process.env.TERM ?? "";
|
|
141
170
|
const ENVIRONMENT = process.env.ENVIRONMENT ?? "";
|
|
142
|
-
/* the
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
171
|
+
/* helper: prune all but the given active Claude Code version */
|
|
172
|
+
const pruneClaudeVersions = (active) => {
|
|
173
|
+
if (active === null)
|
|
174
|
+
return;
|
|
175
|
+
const versionsDir = path.join(HOME, ".local/share/claude/versions");
|
|
176
|
+
if (!fs.existsSync(versionsDir))
|
|
177
|
+
return;
|
|
178
|
+
for (const f of fs.readdirSync(versionsDir)) {
|
|
179
|
+
if (f === active)
|
|
180
|
+
continue;
|
|
181
|
+
try {
|
|
182
|
+
fs.rmSync(path.join(versionsDir, f), { recursive: true, force: true });
|
|
150
183
|
}
|
|
151
|
-
|
|
152
|
-
/* sanity check environment */
|
|
153
|
-
if (ENVIRONMENT === "capsula")
|
|
154
|
-
fatal("cannot execute \"install\" command from within Capsula environment");
|
|
155
|
-
/* ensure we are not running from the home directory
|
|
156
|
-
in order to not read-write mount its ~/.local/! */
|
|
157
|
-
try {
|
|
158
|
-
process.chdir(basedir);
|
|
159
|
-
}
|
|
160
|
-
catch (_e) {
|
|
161
|
-
fatal("cannot switch to base directory");
|
|
162
|
-
}
|
|
163
|
-
/* dispatch according to host/container mode */
|
|
164
|
-
if (sandbox) {
|
|
165
|
-
info("update Debian GNU/Linux operating system");
|
|
166
|
-
await self("shell", "-s", "sudo", "-E", "apt", "update", "-qq");
|
|
167
|
-
await self("shell", "-s", "sudo", "-E", "apt", "upgrade", "-qq", "-y");
|
|
168
|
-
info("install Tmux / LazyGit / Git");
|
|
169
|
-
await self("shell", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "tmux", "lazygit", "git");
|
|
170
|
-
info("install Node.js");
|
|
171
|
-
await self("shell", "-s", "sudo", "-E", "bash", "-c", "curl -fsSL https://deb.nodesource.com/setup_24.x | bash -");
|
|
172
|
-
await self("shell", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "nodejs");
|
|
173
|
-
await self("shell", "-s", "sudo", "-E", "apt", "install", "-qq", "-y", "binutils", "gcc", "g++", "make");
|
|
174
|
-
info("install Claude Code");
|
|
175
|
-
await self("shell", "bash", "-c", "rm -f $HOME/.local/bin/claude");
|
|
176
|
-
await self("shell", "bash", "-c", "rm -f $HOME/.local/share/claude/versions/*");
|
|
177
|
-
await self("shell", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`);
|
|
178
|
-
info("install ANSI-Recolor");
|
|
179
|
-
await self("shell", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "ansi-recolor");
|
|
180
|
-
info("install TypeScript LS");
|
|
181
|
-
await self("shell", "-s", "sudo", "-E", "npm", "install", "-y", "-g", "typescript-language-server");
|
|
182
|
-
info("install Claude wrapper");
|
|
183
|
-
await self("shell", "-s", "sudo", "install", "-c", "-m", "755", `${basedir}/claude`, "/usr/bin/claude");
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
const platform = detectPlatform();
|
|
187
|
-
info("install Tmux");
|
|
188
|
-
ensureTool("tmux", {
|
|
189
|
-
hint: platform.match(/^windows:/) ?
|
|
190
|
-
"https://github.com/psmux/psmux" :
|
|
191
|
-
"https://github.com/tmux/tmux/",
|
|
192
|
-
install: {
|
|
193
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e psmux",
|
|
194
|
-
"windows:choco": "choco install -y --accept-license --no-progress psmux",
|
|
195
|
-
"macos:ports": "sudo port -N install tmux",
|
|
196
|
-
"macos:brew": "sudo brew install tmux",
|
|
197
|
-
"linux:apt": "sudo apt install -y tmux",
|
|
198
|
-
"linux:apk": "sudo apk add --no-interactive tmux"
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
info("install LazyGit");
|
|
202
|
-
ensureTool("lazygit", {
|
|
203
|
-
optional: true,
|
|
204
|
-
hint: "https://github.com/jesseduffield/lazygit/",
|
|
205
|
-
install: {
|
|
206
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
|
|
207
|
-
"windows:choco": "choco install -y --accept-license --no-progress lazygit",
|
|
208
|
-
"macos:ports": "sudo port -N install lazygit",
|
|
209
|
-
"macos:brew": "sudo brew install lazygit",
|
|
210
|
-
"linux:apt": "sudo apt install -y lazygit",
|
|
211
|
-
"linux:apk": "sudo apk add --no-interactive lazygit"
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
info("install Git");
|
|
215
|
-
ensureTool("git", {
|
|
216
|
-
optional: true,
|
|
217
|
-
hint: "https://git-scm.com",
|
|
218
|
-
install: {
|
|
219
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
|
|
220
|
-
"windows:choco": "choco install -y --accept-license --no-progress git",
|
|
221
|
-
"macos:ports": "sudo port -N install git",
|
|
222
|
-
"macos:brew": "sudo brew install git",
|
|
223
|
-
"linux:apt": "sudo apt install -y git",
|
|
224
|
-
"linux:apk": "sudo apk add --no-interactive git"
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
info("install Node.js");
|
|
228
|
-
ensureTool(["node", "npm"], {
|
|
229
|
-
hint: "https://nodejs.org",
|
|
230
|
-
install: {
|
|
231
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
|
|
232
|
-
"windows:choco": "choco install -y --accept-license --no-progress nodejs",
|
|
233
|
-
"macos:ports": "sudo port -N install nodejs24 npm11",
|
|
234
|
-
"macos:brew": "sudo brew install node",
|
|
235
|
-
"linux:apt": "curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash - && sudo apt install -y nodejs",
|
|
236
|
-
"linux:apk": "sudo apk add --no-interactive nodejs npm"
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
info("install ANSI-Recolor");
|
|
240
|
-
ensureTool("ansi-recolor", {
|
|
241
|
-
hint: "https://github.com/rse/ansi-recolor",
|
|
242
|
-
install: {
|
|
243
|
-
"windows:*": "npm install -g ansi-recolor",
|
|
244
|
-
"macos:*": "sudo npm install -g ansi-recolor",
|
|
245
|
-
"linux:*": "sudo npm install -g ansi-recolor"
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
info("install TypeScript-Language-Server");
|
|
249
|
-
ensureTool("typescript-language-server", {
|
|
250
|
-
hint: "https://github.com/typescript-language-server/typescript-language-server",
|
|
251
|
-
install: {
|
|
252
|
-
"windows:*": "npm install -g typescript-language-server",
|
|
253
|
-
"macos:*": "sudo npm install -g typescript-language-server",
|
|
254
|
-
"linux:*": "sudo npm install -g typescript-language-server"
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
info("install Claude Code");
|
|
258
|
-
/* helper: remove obsolete Claude Code versions */
|
|
259
|
-
const removeObsoleteClaudeVersions = (binName) => {
|
|
260
|
-
try {
|
|
261
|
-
fs.unlinkSync(path.join(HOME, ".local/bin", binName));
|
|
262
|
-
}
|
|
263
|
-
catch (_e) {
|
|
264
|
-
}
|
|
265
|
-
const versionsDir = path.join(HOME, ".local/share/claude/versions");
|
|
266
|
-
if (fs.existsSync(versionsDir)) {
|
|
267
|
-
for (const f of fs.readdirSync(versionsDir)) {
|
|
268
|
-
try {
|
|
269
|
-
fs.unlinkSync(path.join(versionsDir, f));
|
|
270
|
-
}
|
|
271
|
-
catch (_e) {
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
if (process.platform !== "win32") {
|
|
277
|
-
removeObsoleteClaudeVersions("claude");
|
|
278
|
-
/* run installation script */
|
|
279
|
-
ensureTool("bash", { hint: "https://www.gnu.org/software/bash/" });
|
|
280
|
-
ensureTool("curl", { hint: "https://curl.se/" });
|
|
281
|
-
await execa("bash", ["-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`], {
|
|
282
|
-
stdio: "inherit", reject: false
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
if (!process.env.PSModulePath)
|
|
287
|
-
fatal("on Windows the \"install\" command has to be run from within a PowerShell session");
|
|
288
|
-
removeObsoleteClaudeVersions("claude.exe");
|
|
289
|
-
/* run installation script */
|
|
290
|
-
ensureTool("powershell");
|
|
291
|
-
await execa("powershell", ["-NoProfile", "-Command", "irm https://claude.ai/install.ps1 | iex"], {
|
|
292
|
-
stdio: "inherit", reject: false
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
break;
|
|
184
|
+
catch (_e) {
|
|
297
185
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/* helper: detect the active Claude Code version via the installed binary */
|
|
189
|
+
const detectActiveClaudeVersion = (binName) => {
|
|
190
|
+
try {
|
|
191
|
+
const r = execaSync(path.join(HOME, ".local/bin", binName), ["--version"], { reject: false });
|
|
192
|
+
const m = /^(\S+)/.exec(r.stdout ?? "");
|
|
193
|
+
if (m)
|
|
194
|
+
return m[1];
|
|
195
|
+
}
|
|
196
|
+
catch (_e) {
|
|
197
|
+
/* binary missing or not executable */
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
};
|
|
201
|
+
/* action: install host-side or in-container dependencies */
|
|
202
|
+
const actionInstall = async (capsula) => {
|
|
203
|
+
/* sanity check environment */
|
|
204
|
+
if (ENVIRONMENT === "capsula")
|
|
205
|
+
fatal("cannot execute \"install\" command from within Capsula environment");
|
|
206
|
+
/* ensure we are not running from the home directory
|
|
207
|
+
in order to not read-write mount its ~/.local/! */
|
|
208
|
+
try {
|
|
209
|
+
process.chdir(basedir);
|
|
210
|
+
}
|
|
211
|
+
catch (_e) {
|
|
212
|
+
fatal("cannot switch to base directory");
|
|
213
|
+
}
|
|
214
|
+
/* dispatch according to host/container mode */
|
|
215
|
+
if (capsula) {
|
|
216
|
+
info("update Debian GNU/Linux operating system");
|
|
217
|
+
await self("internal", "capsula", "sudo", "-E", "apt", "update", "-qq");
|
|
218
|
+
await self("internal", "capsula", "sudo", "-E", "apt", "upgrade", "-qq", "-y");
|
|
219
|
+
info("install Tmux / LazyGit / Git");
|
|
220
|
+
await self("internal", "capsula", "sudo", "-E", "apt", "install", "-qq", "-y", "tmux", "lazygit", "git");
|
|
221
|
+
info("install Node.js");
|
|
222
|
+
await self("internal", "capsula", "sudo", "-E", "bash", "-c", "curl -fsSL https://deb.nodesource.com/setup_24.x | bash -");
|
|
223
|
+
await self("internal", "capsula", "sudo", "-E", "apt", "install", "-qq", "-y", "nodejs");
|
|
224
|
+
await self("internal", "capsula", "sudo", "-E", "apt", "install", "-qq", "-y", "binutils", "gcc", "g++", "make");
|
|
225
|
+
info("install Claude Code");
|
|
226
|
+
await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`);
|
|
227
|
+
/* prune obsolete versions only after successful install */
|
|
228
|
+
await self("internal", "capsula", "bash", "-c", "VERSIONS=\"$HOME/.local/share/claude/versions\"; " +
|
|
229
|
+
"[ -d \"$VERSIONS\" ] || exit 0; " +
|
|
230
|
+
"ACTIVE=$(\"$HOME/.local/bin/claude\" --version 2>/dev/null | awk '{print $1; exit}'); " +
|
|
231
|
+
"[ -n \"$ACTIVE\" ] || exit 0; " +
|
|
232
|
+
"find \"$VERSIONS\" -mindepth 1 -maxdepth 1 ! -name \"$ACTIVE\" -exec rm -rf {} +");
|
|
233
|
+
info("install ANSI-Recolor");
|
|
234
|
+
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "ansi-recolor");
|
|
235
|
+
info("install TypeScript LS");
|
|
236
|
+
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "typescript-language-server");
|
|
237
|
+
info("install Claude wrapper");
|
|
238
|
+
await self("internal", "capsula", "sudo", "install", "-c", "-m", "755", `${basedir}/claude`, "/usr/bin/claude");
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const platform = detectPlatform();
|
|
242
|
+
info("install Tmux");
|
|
243
|
+
ensureTool("tmux", {
|
|
244
|
+
hint: platform.match(/^windows:/) ?
|
|
245
|
+
"https://github.com/psmux/psmux" :
|
|
246
|
+
"https://github.com/tmux/tmux/",
|
|
247
|
+
install: {
|
|
248
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e psmux",
|
|
249
|
+
"windows:choco": "choco install -y --accept-license --no-progress psmux",
|
|
250
|
+
"macos:ports": "sudo port -N install tmux",
|
|
251
|
+
"macos:brew": "sudo brew install tmux",
|
|
252
|
+
"linux:apt": "sudo apt install -y tmux",
|
|
253
|
+
"linux:apk": "sudo apk add --no-interactive tmux"
|
|
323
254
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
|
|
337
|
-
"windows:choco": "choco upgrade -y --accept-license --no-progress lazygit",
|
|
338
|
-
"macos:ports": "sudo port -N upgrade lazygit",
|
|
339
|
-
"macos:brew": "sudo brew upgrade lazygit",
|
|
340
|
-
"linux:apt": "sudo apt install --only-upgrade -y lazygit",
|
|
341
|
-
"linux:apk": "sudo apk upgrade --no-interactive lazygit"
|
|
342
|
-
});
|
|
343
|
-
info("update Git");
|
|
344
|
-
executeCommand({
|
|
345
|
-
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
|
|
346
|
-
"windows:choco": "choco upgrade -y --accept-license --no-progress git",
|
|
347
|
-
"macos:ports": "sudo port -N upgrade git",
|
|
348
|
-
"macos:brew": "sudo brew upgrade git",
|
|
349
|
-
"linux:apt": "sudo apt install --only-upgrade -y git",
|
|
350
|
-
"linux:apk": "sudo apk upgrade --no-interactive git"
|
|
351
|
-
});
|
|
352
|
-
info("update Node.js");
|
|
353
|
-
executeCommand({
|
|
354
|
-
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
|
|
355
|
-
"windows:choco": "choco upgrade -y --accept-license --no-progress nodejs",
|
|
356
|
-
"macos:ports": "sudo port -N upgrade nodejs24 npm11",
|
|
357
|
-
"macos:brew": "sudo brew upgrade node",
|
|
358
|
-
"linux:apt": "sudo apt install --only-upgrade -y nodejs",
|
|
359
|
-
"linux:apk": "sudo apk upgrade --no-interactive nodejs npm"
|
|
360
|
-
});
|
|
361
|
-
info("update ANSI-Recolor");
|
|
362
|
-
executeCommand({
|
|
363
|
-
"windows:*": "npm install -g ansi-recolor",
|
|
364
|
-
"macos:*": "sudo npm install -g ansi-recolor",
|
|
365
|
-
"linux:*": "sudo npm install -g ansi-recolor"
|
|
366
|
-
});
|
|
367
|
-
info("update TypeScript-Language-Server");
|
|
368
|
-
executeCommand({
|
|
369
|
-
"windows:*": "npm install -g typescript-language-server",
|
|
370
|
-
"macos:*": "sudo npm install -g typescript-language-server",
|
|
371
|
-
"linux:*": "sudo npm install -g typescript-language-server"
|
|
372
|
-
});
|
|
373
|
-
info("update Claude Code");
|
|
374
|
-
if (process.platform !== "win32") {
|
|
375
|
-
ensureTool("bash");
|
|
376
|
-
await execa("bash", ["-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`], {
|
|
377
|
-
stdio: "inherit", reject: false
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
if (!process.env.PSModulePath)
|
|
382
|
-
fatal("on Windows the \"update\" command has to be run from within a PowerShell session");
|
|
383
|
-
ensureTool("powershell");
|
|
384
|
-
await execa("powershell", ["-NoProfile", "-Command", "claude update"], {
|
|
385
|
-
stdio: "inherit", reject: false
|
|
386
|
-
});
|
|
387
|
-
}
|
|
255
|
+
});
|
|
256
|
+
info("install LazyGit");
|
|
257
|
+
ensureTool("lazygit", {
|
|
258
|
+
optional: true,
|
|
259
|
+
hint: "https://github.com/jesseduffield/lazygit/",
|
|
260
|
+
install: {
|
|
261
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
|
|
262
|
+
"windows:choco": "choco install -y --accept-license --no-progress lazygit",
|
|
263
|
+
"macos:ports": "sudo port -N install lazygit",
|
|
264
|
+
"macos:brew": "sudo brew install lazygit",
|
|
265
|
+
"linux:apt": "sudo apt install -y lazygit",
|
|
266
|
+
"linux:apk": "sudo apk add --no-interactive lazygit"
|
|
388
267
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
268
|
+
});
|
|
269
|
+
info("install Git");
|
|
270
|
+
ensureTool("git", {
|
|
271
|
+
optional: true,
|
|
272
|
+
hint: "https://git-scm.com",
|
|
273
|
+
install: {
|
|
274
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
|
|
275
|
+
"windows:choco": "choco install -y --accept-license --no-progress git",
|
|
276
|
+
"macos:ports": "sudo port -N install git",
|
|
277
|
+
"macos:brew": "sudo brew install git",
|
|
278
|
+
"linux:apt": "sudo apt install -y git",
|
|
279
|
+
"linux:apk": "sudo apk add --no-interactive git"
|
|
400
280
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
281
|
+
});
|
|
282
|
+
info("install Node.js");
|
|
283
|
+
ensureTool(["node", "npm"], {
|
|
284
|
+
hint: "https://nodejs.org",
|
|
285
|
+
install: {
|
|
286
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
|
|
287
|
+
"windows:choco": "choco install -y --accept-license --no-progress nodejs",
|
|
288
|
+
"macos:ports": "sudo port -N install nodejs24 npm11",
|
|
289
|
+
"macos:brew": "sudo brew install node",
|
|
290
|
+
"linux:apt": "curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash - && sudo apt install -y nodejs",
|
|
291
|
+
"linux:apk": "sudo apk add --no-interactive nodejs npm"
|
|
413
292
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
await execInherit("docker", [
|
|
423
|
-
"exec", "-i", "-t", container,
|
|
424
|
-
"bash", "-c",
|
|
425
|
-
`TERM=${TERM} HOME=${HOME} sudo -E -u ${USER} ${selfPath} util tmux new-session -A -s "${session}"`
|
|
426
|
-
]);
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
/* start a new container and run tmux */
|
|
430
|
-
await self("shell", "-C", container, selfPath, "util", "tmux", "new-session", "-A", "-s", session, "-n", "claude", selfPath + " claude");
|
|
431
|
-
process.exit(0);
|
|
432
|
-
}
|
|
293
|
+
});
|
|
294
|
+
info("install ANSI-Recolor");
|
|
295
|
+
ensureTool("ansi-recolor", {
|
|
296
|
+
hint: "https://github.com/rse/ansi-recolor",
|
|
297
|
+
install: {
|
|
298
|
+
"windows:*": "npm install -g ansi-recolor",
|
|
299
|
+
"macos:*": "sudo npm install -g ansi-recolor",
|
|
300
|
+
"linux:*": "sudo npm install -g ansi-recolor"
|
|
433
301
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
302
|
+
});
|
|
303
|
+
info("install TypeScript-Language-Server");
|
|
304
|
+
ensureTool("typescript-language-server", {
|
|
305
|
+
hint: "https://github.com/typescript-language-server/typescript-language-server",
|
|
306
|
+
install: {
|
|
307
|
+
"windows:*": "npm install -g typescript-language-server",
|
|
308
|
+
"macos:*": "sudo npm install -g typescript-language-server",
|
|
309
|
+
"linux:*": "sudo npm install -g typescript-language-server"
|
|
437
310
|
}
|
|
438
|
-
|
|
311
|
+
});
|
|
312
|
+
info("install Claude Code");
|
|
313
|
+
if (process.platform !== "win32") {
|
|
314
|
+
/* run installation script */
|
|
315
|
+
ensureTool("bash", { hint: "https://www.gnu.org/software/bash/" });
|
|
316
|
+
ensureTool("curl", { hint: "https://curl.se/" });
|
|
317
|
+
await execa("bash", ["-c", `PATH="${HOME}/.local/bin:$PATH"; curl -kfsSL https://claude.ai/install.sh | bash`], {
|
|
318
|
+
stdio: "inherit", reject: false
|
|
319
|
+
});
|
|
320
|
+
/* prune obsolete versions only after successful install */
|
|
321
|
+
pruneClaudeVersions(detectActiveClaudeVersion("claude"));
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
if (!process.env.PSModulePath)
|
|
325
|
+
fatal("on Windows the \"install\" command has to be run from within a PowerShell session");
|
|
326
|
+
/* run installation script */
|
|
327
|
+
ensureTool("powershell");
|
|
328
|
+
await execa("powershell", ["-NoProfile", "-Command", "irm https://claude.ai/install.ps1 | iex"], {
|
|
329
|
+
stdio: "inherit", reject: false
|
|
330
|
+
});
|
|
331
|
+
/* prune obsolete versions only after successful install */
|
|
332
|
+
pruneClaudeVersions(detectActiveClaudeVersion("claude.exe"));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
/* action: update host-side or in-container components */
|
|
337
|
+
const actionUpdate = async (capsula) => {
|
|
338
|
+
/* sanity check environment */
|
|
339
|
+
if (ENVIRONMENT === "capsula")
|
|
340
|
+
fatal("cannot execute \"update\" command from within Capsula environment");
|
|
341
|
+
/* ensure we are not running from the home directory
|
|
342
|
+
in order to not read-write mount its ~/.local/! */
|
|
343
|
+
try {
|
|
344
|
+
process.chdir(basedir);
|
|
345
|
+
}
|
|
346
|
+
catch (_e) {
|
|
347
|
+
fatal("cannot switch to base directory");
|
|
348
|
+
}
|
|
349
|
+
/* dispatch according to host/container mode */
|
|
350
|
+
if (capsula) {
|
|
351
|
+
info("update Debian GNU/Linux operating system");
|
|
352
|
+
await self("internal", "capsula", "sudo", "apt", "update", "-qq");
|
|
353
|
+
await self("internal", "capsula", "sudo", "apt", "upgrade", "-qq", "-y");
|
|
354
|
+
info("update Claude Code");
|
|
355
|
+
await self("internal", "capsula", "bash", "-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`);
|
|
356
|
+
info("update ANSI-Recolor");
|
|
357
|
+
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "ansi-recolor");
|
|
358
|
+
info("update TypeScript LS");
|
|
359
|
+
await self("internal", "capsula", "sudo", "-E", "npm", "install", "-y", "-g", "typescript-language-server");
|
|
360
|
+
info("update Claude wrapper");
|
|
361
|
+
await self("internal", "capsula", "sudo", "install", "-c", "-m", "755", `${basedir}/claude`, "/usr/bin/claude");
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
info("update Tmux");
|
|
365
|
+
executeCommand({
|
|
366
|
+
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e psmux",
|
|
367
|
+
"windows:choco": "choco upgrade -y --accept-license --no-progress psmux",
|
|
368
|
+
"macos:ports": "sudo port -N upgrade tmux",
|
|
369
|
+
"macos:brew": "sudo brew upgrade tmux",
|
|
370
|
+
"linux:apt": "sudo apt install --only-upgrade -y tmux",
|
|
371
|
+
"linux:apk": "sudo apk upgrade --no-interactive tmux"
|
|
372
|
+
});
|
|
373
|
+
info("update LazyGit");
|
|
374
|
+
executeCommand({
|
|
375
|
+
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id JesseDuffield.lazygit",
|
|
376
|
+
"windows:choco": "choco upgrade -y --accept-license --no-progress lazygit",
|
|
377
|
+
"macos:ports": "sudo port -N upgrade lazygit",
|
|
378
|
+
"macos:brew": "sudo brew upgrade lazygit",
|
|
379
|
+
"linux:apt": "sudo apt install --only-upgrade -y lazygit",
|
|
380
|
+
"linux:apk": "sudo apk upgrade --no-interactive lazygit"
|
|
381
|
+
});
|
|
382
|
+
info("update Git");
|
|
383
|
+
executeCommand({
|
|
384
|
+
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git --source winget",
|
|
385
|
+
"windows:choco": "choco upgrade -y --accept-license --no-progress git",
|
|
386
|
+
"macos:ports": "sudo port -N upgrade git",
|
|
387
|
+
"macos:brew": "sudo brew upgrade git",
|
|
388
|
+
"linux:apt": "sudo apt install --only-upgrade -y git",
|
|
389
|
+
"linux:apk": "sudo apk upgrade --no-interactive git"
|
|
390
|
+
});
|
|
391
|
+
info("update Node.js");
|
|
392
|
+
executeCommand({
|
|
393
|
+
"windows:winget": "winget upgrade --accept-package-agreements --accept-source-agreements --silent -e --id OpenJS.NodeJS.LTS",
|
|
394
|
+
"windows:choco": "choco upgrade -y --accept-license --no-progress nodejs",
|
|
395
|
+
"macos:ports": "sudo port -N upgrade nodejs24 npm11",
|
|
396
|
+
"macos:brew": "sudo brew upgrade node",
|
|
397
|
+
"linux:apt": "sudo apt install --only-upgrade -y nodejs",
|
|
398
|
+
"linux:apk": "sudo apk upgrade --no-interactive nodejs npm"
|
|
399
|
+
});
|
|
400
|
+
info("update ANSI-Recolor");
|
|
401
|
+
executeCommand({
|
|
402
|
+
"windows:*": "npm install -g ansi-recolor",
|
|
403
|
+
"macos:*": "sudo npm install -g ansi-recolor",
|
|
404
|
+
"linux:*": "sudo npm install -g ansi-recolor"
|
|
405
|
+
});
|
|
406
|
+
info("update TypeScript-Language-Server");
|
|
407
|
+
executeCommand({
|
|
408
|
+
"windows:*": "npm install -g typescript-language-server",
|
|
409
|
+
"macos:*": "sudo npm install -g typescript-language-server",
|
|
410
|
+
"linux:*": "sudo npm install -g typescript-language-server"
|
|
411
|
+
});
|
|
412
|
+
info("update Claude Code");
|
|
413
|
+
if (process.platform !== "win32") {
|
|
414
|
+
ensureTool("bash");
|
|
415
|
+
await execa("bash", ["-c", `PATH="${HOME}/.local/bin:$PATH"; ${HOME}/.local/bin/claude update`], {
|
|
416
|
+
stdio: "inherit", reject: false
|
|
417
|
+
});
|
|
418
|
+
/* prune obsolete versions only after successful update */
|
|
419
|
+
pruneClaudeVersions(detectActiveClaudeVersion("claude"));
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
if (!process.env.PSModulePath)
|
|
423
|
+
fatal("on Windows the \"update\" command has to be run from within a PowerShell session");
|
|
424
|
+
ensureTool("powershell");
|
|
425
|
+
await execa("powershell", ["-NoProfile", "-Command", "claude update"], {
|
|
426
|
+
stdio: "inherit", reject: false
|
|
427
|
+
});
|
|
428
|
+
/* prune obsolete versions only after successful update */
|
|
429
|
+
pruneClaudeVersions(detectActiveClaudeVersion("claude.exe"));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
/* action: internal "tmux" -- spawn tmux with our generated configuration.
|
|
434
|
+
The tmux.conf bind-keys for new claude panes embed the parent invocation's
|
|
435
|
+
pass-through flags (e.g. "-R") so panes inherit the user's choice; flags
|
|
436
|
+
are transported via the CLAUDEX_FLAGS env var (set by actionDefault when
|
|
437
|
+
entering tmux mode). */
|
|
438
|
+
const actionInternalTmux = (args) => {
|
|
439
|
+
ensureTool("tmux");
|
|
440
|
+
const claudexFlags = process.env.CLAUDEX_FLAGS ?? "";
|
|
441
|
+
const conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
|
|
442
|
+
.replace(/@SELFPATH@/g, selfPath)
|
|
443
|
+
.replace(/@CLAUDEX_FLAGS@/g, claudexFlags);
|
|
444
|
+
const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`);
|
|
445
|
+
fs.writeFileSync(confFile, conf, { mode: 0o600 });
|
|
446
|
+
const r = execaSync("tmux", [
|
|
447
|
+
"-f", confFile,
|
|
448
|
+
...args
|
|
449
|
+
], {
|
|
450
|
+
stdio: "inherit",
|
|
451
|
+
reject: false,
|
|
452
|
+
windowsHide: false
|
|
453
|
+
});
|
|
454
|
+
try {
|
|
455
|
+
fs.unlinkSync(confFile);
|
|
456
|
+
}
|
|
457
|
+
catch (_e) {
|
|
458
|
+
/* ignore */
|
|
459
|
+
}
|
|
460
|
+
return process.exit(r.exitCode ?? 0);
|
|
461
|
+
};
|
|
462
|
+
/* action: internal "shell" -- spawn an interactive login shell */
|
|
463
|
+
const actionInternalShell = (args) => {
|
|
464
|
+
if (process.platform === "win32") {
|
|
465
|
+
const shell = process.env.SHELL ?? process.env.ComSpec ?? "powershell";
|
|
466
|
+
const name = path.basename(shell).toLowerCase().replace(/\.exe$/, "");
|
|
467
|
+
if (name === "powershell" || name === "pwsh") {
|
|
468
|
+
ensureTool(name);
|
|
469
|
+
return execInherit(name, ["-NoLogo", "-NoProfile", ...args]);
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
ensureTool(shell);
|
|
473
|
+
return execInherit(shell, args);
|
|
439
474
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
const shell = process.env.SHELL ?? "bash";
|
|
478
|
+
ensureTool(shell);
|
|
479
|
+
return execInherit(shell, ["-l", ...args]);
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
/* action: internal "ase-task-edit" -- edit the ASE task associated with the current tmux pane */
|
|
483
|
+
const actionInternalAseTaskEdit = async () => {
|
|
484
|
+
ensureTool("ase");
|
|
485
|
+
let tid = "";
|
|
486
|
+
const r1 = execaSync("tmux", ["display-message", "-p", "#{@ase_task_id}"], { reject: false });
|
|
487
|
+
tid = (r1.stdout ?? "").trim();
|
|
488
|
+
if (tid !== "")
|
|
489
|
+
execInherit("ase", ["task", "edit", tid]);
|
|
490
|
+
else {
|
|
491
|
+
process.stderr.write("no ASE task id known for this pane yet\n");
|
|
492
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
/* action: internal "lazygit" -- spawn lazygit (optionally recolored) */
|
|
496
|
+
const actionInternalLazygit = (recolor, args) => {
|
|
497
|
+
ensureTool("git");
|
|
498
|
+
ensureTool("lazygit");
|
|
499
|
+
const env = { ...process.env, TERM: "xterm-color" };
|
|
500
|
+
if (recolor) {
|
|
501
|
+
ensureTool("ansi-recolor");
|
|
502
|
+
return execInherit("ansi-recolor", [
|
|
503
|
+
"-c", path.join(basedir, "ansi-recolor.conf"),
|
|
504
|
+
"-m",
|
|
505
|
+
"-n", "lazygit",
|
|
506
|
+
"-t", path.join(HOME, "ansi-recolor.txt"),
|
|
507
|
+
"lazygit", "-ucf", path.join(basedir, "lazygit.yaml"),
|
|
508
|
+
...args
|
|
509
|
+
], { env });
|
|
510
|
+
}
|
|
511
|
+
return execInherit("lazygit", [
|
|
512
|
+
"-ucf", path.join(basedir, "lazygit.yaml"),
|
|
513
|
+
...args
|
|
514
|
+
], { env });
|
|
515
|
+
};
|
|
516
|
+
/* action: internal "capsula" -- enter/start a Capsula container with the curated env-var/dotfile setup */
|
|
517
|
+
const actionInternalCapsula = (args) => {
|
|
518
|
+
/* sanity check environment */
|
|
519
|
+
ensureTool("capsula");
|
|
520
|
+
if (ENVIRONMENT === "capsula")
|
|
521
|
+
fatal("cannot execute \"internal capsula\" command from within Capsula environment");
|
|
522
|
+
/* define list of environment variables */
|
|
523
|
+
const envs = ["TERM", "HOME"];
|
|
524
|
+
const envOpts = ["-e", "!"];
|
|
525
|
+
for (const e of envs)
|
|
526
|
+
envOpts.push("-e", e);
|
|
527
|
+
/* find list of dot-files (relative to $HOME) */
|
|
528
|
+
const dotfiles = [
|
|
529
|
+
".inputrc",
|
|
530
|
+
".dotfiles/inputrc",
|
|
531
|
+
".bash_login",
|
|
532
|
+
".bash_logout",
|
|
533
|
+
".bashrc",
|
|
534
|
+
".dotfiles/bashrc",
|
|
535
|
+
".ssh/authorized_keys",
|
|
536
|
+
".ssh/known_hosts!",
|
|
537
|
+
".ssh/config",
|
|
538
|
+
".dotfiles/sshconfig",
|
|
539
|
+
".vimrc",
|
|
540
|
+
".dotfiles/vimrc",
|
|
541
|
+
".vim",
|
|
542
|
+
".tmux.conf",
|
|
543
|
+
".dotfiles/tmux.conf",
|
|
544
|
+
".gitconfig",
|
|
545
|
+
".dotfiles/gitconfig",
|
|
546
|
+
".npmrc",
|
|
547
|
+
".npm!",
|
|
548
|
+
".cache!",
|
|
549
|
+
".claude!",
|
|
550
|
+
".claude.json!"
|
|
551
|
+
];
|
|
552
|
+
const dotfileOpts = ["-m", "!"];
|
|
553
|
+
for (const dotfile of dotfiles) {
|
|
554
|
+
const p = dotfile.endsWith("!") ? dotfile.slice(0, -1) : dotfile;
|
|
555
|
+
if (fs.existsSync(path.join(HOME, p)))
|
|
556
|
+
dotfileOpts.push("-m", dotfile);
|
|
557
|
+
}
|
|
558
|
+
/* find all sensitive ".env" files from current working
|
|
559
|
+
directory up to root directory for hiding */
|
|
560
|
+
const nullOpts = ["-n", "!"];
|
|
561
|
+
let dir = process.cwd();
|
|
562
|
+
while (true) {
|
|
563
|
+
const envFile = path.join(dir, ".env");
|
|
564
|
+
if (fs.existsSync(envFile) && fs.statSync(envFile).isFile())
|
|
565
|
+
nullOpts.push("-n", envFile);
|
|
566
|
+
const parent = path.dirname(dir);
|
|
567
|
+
if (parent === dir)
|
|
568
|
+
break;
|
|
569
|
+
dir = parent;
|
|
570
|
+
}
|
|
571
|
+
/* execute */
|
|
572
|
+
return execInherit("capsula", [
|
|
573
|
+
"-c", "claude",
|
|
574
|
+
"-t", "debian",
|
|
575
|
+
"-P", "linux/arm64",
|
|
576
|
+
...envOpts,
|
|
577
|
+
...dotfileOpts,
|
|
578
|
+
...nullOpts,
|
|
579
|
+
"-p", "!",
|
|
580
|
+
"-e", `CLAUDE_MODEL=${process.env.CLAUDE_MODEL ?? ""}`,
|
|
581
|
+
"-e", `CLAUDEX=${basedir}`,
|
|
582
|
+
"-b", basedir,
|
|
583
|
+
...args
|
|
584
|
+
]);
|
|
585
|
+
};
|
|
586
|
+
/* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula) */
|
|
587
|
+
const actionInternal = async (opts, args) => {
|
|
588
|
+
const util = args[0];
|
|
589
|
+
const rest = args.slice(1);
|
|
590
|
+
switch (util) {
|
|
591
|
+
case "tmux": return actionInternalTmux(rest);
|
|
592
|
+
case "shell": return actionInternalShell(rest);
|
|
593
|
+
case "ase-task-edit": return actionInternalAseTaskEdit();
|
|
594
|
+
case "lazygit": return actionInternalLazygit(opts.recolor === true, rest);
|
|
595
|
+
case "capsula": return actionInternalCapsula(rest);
|
|
596
|
+
default:
|
|
597
|
+
fatal(`invalid internal command "${util ?? ""}"`);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
/* action: top-level command -- run "claude" */
|
|
601
|
+
const actionDefault = (opts, args) => {
|
|
602
|
+
/* build the inner self-invocation flag list. Pass-through "-R"/"-A" only,
|
|
603
|
+
as "-C" and "-T" are consumed at the outer layer to avoid recursion. */
|
|
604
|
+
const innerFlags = [];
|
|
605
|
+
if (opts.recolor)
|
|
606
|
+
innerFlags.push("-R");
|
|
607
|
+
if (opts.ase)
|
|
608
|
+
innerFlags.push("-A");
|
|
609
|
+
/* branch: tmux mode (with or without capsula) */
|
|
610
|
+
if (opts.tmux) {
|
|
611
|
+
/* sanity check environment */
|
|
612
|
+
if (ENVIRONMENT === "capsula")
|
|
613
|
+
fatal("cannot execute tmux mode from within Capsula environment");
|
|
614
|
+
/* determine session name (from "-T <name>" option value, or auto-detected) */
|
|
615
|
+
let session;
|
|
616
|
+
if (typeof opts.tmux === "string" && opts.tmux !== "")
|
|
617
|
+
session = opts.tmux;
|
|
618
|
+
else
|
|
619
|
+
session = detectSessionName();
|
|
620
|
+
const rest = args;
|
|
621
|
+
/* build the in-pane self-invocation shell string (recolor pass-through) */
|
|
622
|
+
const inPane = [shq(selfPath), ...innerFlags.map(shq), ...rest.map(shq)].join(" ");
|
|
623
|
+
/* propagate the chosen pass-through flags to "internal tmux" so its
|
|
624
|
+
tmux.conf bind-keys spawn new claude panes with the same flags */
|
|
625
|
+
const claudexFlags = innerFlags.join(" ");
|
|
626
|
+
process.env.CLAUDEX_FLAGS = claudexFlags;
|
|
627
|
+
/* dispatch according to global options */
|
|
628
|
+
if (opts.capsula) {
|
|
629
|
+
/* enter/start container, then run tmux inside it */
|
|
630
|
+
ensureTool("docker");
|
|
631
|
+
const container = `capsula-${USER}-debian-claude-${session}`;
|
|
632
|
+
const inspect = execaSync("docker", ["inspect", container], { reject: false, stdio: "ignore" });
|
|
633
|
+
if (inspect.exitCode === 0) {
|
|
634
|
+
/* enter already running container and run tmux */
|
|
635
|
+
return execInherit("docker", [
|
|
636
|
+
"exec", "-i", "-t", container,
|
|
637
|
+
"bash", "-c",
|
|
638
|
+
`TERM=${shq(TERM)} HOME=${shq(HOME)} CLAUDEX_FLAGS=${shq(claudexFlags)} sudo -E -u ${shq(USER)} ${shq(selfPath)} internal tmux new-session -A -s ${shq(session)}`
|
|
639
|
+
]);
|
|
464
640
|
}
|
|
465
641
|
else {
|
|
466
|
-
/*
|
|
467
|
-
|
|
642
|
+
/* start a new container and run tmux */
|
|
643
|
+
return execInherit(process.execPath, [
|
|
644
|
+
selfPathJS, "internal", "capsula",
|
|
645
|
+
"-e", `CLAUDEX_FLAGS=${claudexFlags}`,
|
|
646
|
+
"-C", container, selfPath, "internal", "tmux",
|
|
647
|
+
"new-session", "-A", "-s", session, "-n", "claude", inPane
|
|
648
|
+
]);
|
|
468
649
|
}
|
|
469
|
-
break;
|
|
470
650
|
}
|
|
471
|
-
|
|
472
|
-
/*
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
fatal("cannot execute \"shell\" command from within Capsula environment");
|
|
476
|
-
/* define list of environment variables */
|
|
477
|
-
const envs = ["TERM", "HOME"];
|
|
478
|
-
const envOpts = ["-e", "!"];
|
|
479
|
-
for (const e of envs)
|
|
480
|
-
envOpts.push("-e", e);
|
|
481
|
-
/* find list of dot-files (relative to $HOME) */
|
|
482
|
-
const dotfiles = [
|
|
483
|
-
".inputrc",
|
|
484
|
-
".dotfiles/inputrc",
|
|
485
|
-
".bash_login",
|
|
486
|
-
".bash_logout",
|
|
487
|
-
".bashrc",
|
|
488
|
-
".dotfiles/bashrc",
|
|
489
|
-
".ssh/authorized_keys",
|
|
490
|
-
".ssh/known_hosts!",
|
|
491
|
-
".ssh/config",
|
|
492
|
-
".dotfiles/sshconfig",
|
|
493
|
-
".vimrc",
|
|
494
|
-
".dotfiles/vimrc",
|
|
495
|
-
".vim",
|
|
496
|
-
".tmux.conf",
|
|
497
|
-
".dotfiles/tmux.conf",
|
|
498
|
-
".gitconfig",
|
|
499
|
-
".dotfiles/gitconfig",
|
|
500
|
-
".npmrc",
|
|
501
|
-
".npm!",
|
|
502
|
-
".cache!",
|
|
503
|
-
".claude!",
|
|
504
|
-
".claude.json!"
|
|
505
|
-
];
|
|
506
|
-
const dotfileOpts = ["-m", "!"];
|
|
507
|
-
for (const dotfile of dotfiles) {
|
|
508
|
-
const p = dotfile.endsWith("!") ? dotfile.slice(0, -1) : dotfile;
|
|
509
|
-
if (fs.existsSync(path.join(HOME, p)))
|
|
510
|
-
dotfileOpts.push("-m", dotfile);
|
|
511
|
-
}
|
|
512
|
-
/* find all sensitive ".env" files from current working
|
|
513
|
-
directory up to root directory for hiding */
|
|
514
|
-
const nullOpts = ["-n", "!"];
|
|
515
|
-
let dir = process.cwd();
|
|
516
|
-
while (true) {
|
|
517
|
-
const envFile = path.join(dir, ".env");
|
|
518
|
-
if (fs.existsSync(envFile) && fs.statSync(envFile).isFile())
|
|
519
|
-
nullOpts.push("-n", envFile);
|
|
520
|
-
const parent = path.dirname(dir);
|
|
521
|
-
if (parent === dir)
|
|
522
|
-
break;
|
|
523
|
-
dir = parent;
|
|
524
|
-
}
|
|
525
|
-
/* execute */
|
|
526
|
-
await execInherit("capsula", [
|
|
527
|
-
"-c", "claude",
|
|
528
|
-
"-t", "debian",
|
|
529
|
-
"-P", "linux/arm64",
|
|
530
|
-
...envOpts,
|
|
531
|
-
...dotfileOpts,
|
|
532
|
-
...nullOpts,
|
|
533
|
-
"-p", "!",
|
|
534
|
-
"-e", `CLAUDE_MODEL=${process.env.CLAUDE_MODEL ?? ""}`,
|
|
535
|
-
"-e", `CLAUDEX=${basedir}`,
|
|
536
|
-
"-b", basedir,
|
|
537
|
-
...argv
|
|
651
|
+
else {
|
|
652
|
+
/* enter/start plain tmux */
|
|
653
|
+
return execInherit(selfPath, [
|
|
654
|
+
"internal", "tmux", "new-session", "-A", "-s", session, "-n", "claude", inPane
|
|
538
655
|
]);
|
|
539
|
-
break;
|
|
540
656
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
env.ANTHROPIC_BASE_URL = `http://${ohost}`;
|
|
586
|
-
env.ANTHROPIC_CUSTOM_MODEL_OPTION_SUPPORTED_CAPABILITIES = capabilities;
|
|
587
|
-
env.ANTHROPIC_DEFAULT_HAIKU_MODEL = model;
|
|
588
|
-
env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
|
|
589
|
-
env.ANTHROPIC_DEFAULT_SONNET_MODEL = model;
|
|
590
|
-
env.CLAUDE_CODE_ATTRIBUTION_HEADER = "0";
|
|
591
|
-
env.CLAUDE_CODE_AUTO_COMPACT_WINDOW = context;
|
|
592
|
-
env.CLAUDE_CODE_SUBAGENT_MODEL = model;
|
|
593
|
-
env.DISABLE_LOGIN_COMMAND = "1";
|
|
594
|
-
env.DISABLE_LOGOUT_COMMAND = "1";
|
|
657
|
+
}
|
|
658
|
+
/* branch: capsula-only mode */
|
|
659
|
+
if (opts.capsula) {
|
|
660
|
+
if (ENVIRONMENT === "capsula")
|
|
661
|
+
fatal("cannot execute capsula mode from within Capsula environment");
|
|
662
|
+
ensureTool("docker");
|
|
663
|
+
const session = detectSessionName();
|
|
664
|
+
const container = `capsula-${USER}-debian-claude-${session}`;
|
|
665
|
+
const inspect = execaSync("docker", ["inspect", container], { reject: false, stdio: "ignore" });
|
|
666
|
+
if (inspect.exitCode === 0) {
|
|
667
|
+
/* enter already running container and run claude (single-quote shell-escape) */
|
|
668
|
+
const passthru = [...innerFlags, ...args].map(shq).join(" ");
|
|
669
|
+
return execInherit("docker", [
|
|
670
|
+
"exec", "-i", "-t", container,
|
|
671
|
+
"bash", "-c",
|
|
672
|
+
`TERM=${shq(TERM)} HOME=${shq(HOME)} sudo -E -u ${shq(USER)} ${shq(selfPath)} ${passthru}`
|
|
673
|
+
]);
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
/* start a new container and run claude */
|
|
677
|
+
return execInherit(process.execPath, [
|
|
678
|
+
selfPathJS, "internal", "capsula", "-C", container, selfPath, ...innerFlags, ...args
|
|
679
|
+
]);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/* branch: plain claude -- execute Claude Code, optionally
|
|
683
|
+
wrapped with ansi-recolor when "-R" was given */
|
|
684
|
+
const recolor = opts.recolor === true;
|
|
685
|
+
if (recolor)
|
|
686
|
+
ensureTool("ansi-recolor");
|
|
687
|
+
process.env.PATH = `${HOME}/.local/bin:${process.env.PATH ?? ""}`;
|
|
688
|
+
ensureTool("claude");
|
|
689
|
+
const env = { ...process.env };
|
|
690
|
+
const claudeModel = process.env.CLAUDE_MODEL ?? "";
|
|
691
|
+
if (/^ollama:/.test(claudeModel)) {
|
|
692
|
+
/* parse ollama[://<host>[:<port>]]/<model>[?[context=<size>],[capabilities=<list>]] */
|
|
693
|
+
let remainder = claudeModel.slice("ollama:".length);
|
|
694
|
+
let ohost = "localhost:11434";
|
|
695
|
+
if (remainder.startsWith("//")) {
|
|
696
|
+
remainder = remainder.slice(2);
|
|
697
|
+
const slash = remainder.indexOf("/");
|
|
698
|
+
if (slash >= 0) {
|
|
699
|
+
ohost = remainder.slice(0, slash);
|
|
700
|
+
remainder = remainder.slice(slash + 1);
|
|
595
701
|
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
if (process.stdout.isTTY) {
|
|
600
|
-
const cols = process.stdout.columns;
|
|
601
|
-
if (typeof cols === "number" && cols > 0)
|
|
602
|
-
width = cols;
|
|
603
|
-
}
|
|
604
|
-
process.env.ASE_TERM_WIDTH = `${width}`;
|
|
702
|
+
else {
|
|
703
|
+
ohost = remainder;
|
|
704
|
+
remainder = "";
|
|
605
705
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
706
|
+
}
|
|
707
|
+
else if (remainder.startsWith("/"))
|
|
708
|
+
remainder = remainder.slice(1);
|
|
709
|
+
const qIdx = remainder.indexOf("?");
|
|
710
|
+
const model = qIdx >= 0 ? remainder.slice(0, qIdx) : remainder;
|
|
711
|
+
if (model === "")
|
|
712
|
+
fatal("invalid CLAUDE_MODEL: missing model name in " +
|
|
713
|
+
`"${claudeModel}" (expected: ollama:[//host[:port]]/<model>[?...])`);
|
|
714
|
+
let context = "200k";
|
|
715
|
+
let capabilities = "";
|
|
716
|
+
if (qIdx >= 0) {
|
|
717
|
+
const query = remainder.slice(qIdx + 1);
|
|
718
|
+
for (const pair of query.split(",")) {
|
|
719
|
+
const eq = pair.indexOf("=");
|
|
720
|
+
const key = eq >= 0 ? pair.slice(0, eq) : pair;
|
|
721
|
+
const val = eq >= 0 ? pair.slice(eq + 1) : "";
|
|
722
|
+
if (key === "context")
|
|
723
|
+
context = val;
|
|
724
|
+
else if (key === "capabilities")
|
|
725
|
+
capabilities = val;
|
|
620
726
|
}
|
|
621
|
-
const settingsRaw = fs.readFileSync(path.join(basedir, "claude-settings.json"), "utf8");
|
|
622
|
-
const settings = settingsRaw.replace(/@BASEDIR@/g, basedir);
|
|
623
|
-
await execInherit("ansi-recolor", [
|
|
624
|
-
"-c", path.join(basedir, "ansi-recolor.conf"),
|
|
625
|
-
"-m",
|
|
626
|
-
"-n", "claude",
|
|
627
|
-
"-t", path.join(HOME, "ansi-recolor.txt"),
|
|
628
|
-
path.join(HOME, ".local/bin/claude"),
|
|
629
|
-
"--settings", settings,
|
|
630
|
-
...argv
|
|
631
|
-
], { env });
|
|
632
|
-
break;
|
|
633
727
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
ensureTool("bash");
|
|
657
|
-
await execInherit("bash", ["-l", ...argv]);
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
case "ase-task-edit": {
|
|
661
|
-
ensureTool("ase");
|
|
662
|
-
let tid = "";
|
|
663
|
-
const r1 = execaSync("tmux", ["display-message", "-p", "#{@ase_task_id}"], { reject: false });
|
|
664
|
-
tid = (r1.stdout ?? "").trim();
|
|
665
|
-
if (tid !== "")
|
|
666
|
-
await execInherit("ase", ["task", "edit", tid]);
|
|
667
|
-
else {
|
|
668
|
-
process.stderr.write("no ASE task id known for this pane yet\n");
|
|
669
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
670
|
-
}
|
|
671
|
-
break;
|
|
672
|
-
}
|
|
673
|
-
case "lazygit": {
|
|
674
|
-
ensureTool("ansi-recolor");
|
|
675
|
-
ensureTool("git");
|
|
676
|
-
ensureTool("lazygit");
|
|
677
|
-
ensureTool("vim", { optional: true });
|
|
678
|
-
const env = { ...process.env, TERM: "xterm-color" };
|
|
679
|
-
await execInherit("ansi-recolor", [
|
|
680
|
-
"-c", path.join(basedir, "ansi-recolor.conf"),
|
|
681
|
-
"-m",
|
|
682
|
-
"-n", "lazygit",
|
|
683
|
-
"-t", path.join(HOME, "ansi-recolor.txt"),
|
|
684
|
-
"lazygit", "-ucf", path.join(basedir, "lazygit.yaml"),
|
|
685
|
-
...argv
|
|
686
|
-
], { env });
|
|
687
|
-
break;
|
|
688
|
-
}
|
|
689
|
-
default:
|
|
690
|
-
fatal(`invalid util "${util ?? ""}"`);
|
|
728
|
+
/* override Claude Code configuration */
|
|
729
|
+
env.ANTHROPIC_API_KEY = "";
|
|
730
|
+
env.ANTHROPIC_AUTH_TOKEN = "ollama";
|
|
731
|
+
env.ANTHROPIC_BASE_URL = `http://${ohost}`;
|
|
732
|
+
env.ANTHROPIC_CUSTOM_MODEL_OPTION_SUPPORTED_CAPABILITIES = capabilities;
|
|
733
|
+
env.ANTHROPIC_DEFAULT_HAIKU_MODEL = model;
|
|
734
|
+
env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
|
|
735
|
+
env.ANTHROPIC_DEFAULT_SONNET_MODEL = model;
|
|
736
|
+
env.CLAUDE_CODE_ATTRIBUTION_HEADER = "0";
|
|
737
|
+
env.CLAUDE_CODE_AUTO_COMPACT_WINDOW = context;
|
|
738
|
+
env.CLAUDE_CODE_SUBAGENT_MODEL = model;
|
|
739
|
+
env.DISABLE_LOGIN_COMMAND = "1";
|
|
740
|
+
env.DISABLE_LOGOUT_COMMAND = "1";
|
|
741
|
+
}
|
|
742
|
+
/* override ASE configuration (for its diagram rendering) */
|
|
743
|
+
if (opts.ase) {
|
|
744
|
+
if (process.env.ASE_TERM_WIDTH === undefined) {
|
|
745
|
+
let width = 0;
|
|
746
|
+
if (process.stdout.isTTY) {
|
|
747
|
+
const cols = process.stdout.columns;
|
|
748
|
+
if (typeof cols === "number" && cols > 0)
|
|
749
|
+
width = cols;
|
|
691
750
|
}
|
|
692
|
-
|
|
751
|
+
process.env.ASE_TERM_WIDTH = `${width}`;
|
|
752
|
+
}
|
|
753
|
+
if (process.env.ASE_TERM_COLORS === undefined) {
|
|
754
|
+
let colorMode = "none";
|
|
755
|
+
const depth = process.stdout.getColorDepth();
|
|
756
|
+
if (depth >= 8)
|
|
757
|
+
colorMode = "ansi256";
|
|
758
|
+
else if (depth >= 4)
|
|
759
|
+
colorMode = "ansi16";
|
|
760
|
+
process.env.ASE_TERM_COLORS = `${colorMode}`;
|
|
693
761
|
}
|
|
694
|
-
default:
|
|
695
|
-
fatal(`invalid command "${cmd}"`);
|
|
696
762
|
}
|
|
763
|
+
/* determine Claude Code settings */
|
|
764
|
+
let claudeSettings = {
|
|
765
|
+
"env": {
|
|
766
|
+
"DISABLE_TELEMETRY": "1",
|
|
767
|
+
"DISABLE_AUTOUPDATER": "1",
|
|
768
|
+
"DISABLE_BUG_COMMAND": "1",
|
|
769
|
+
"DISABLE_ERROR_REPORTING": "1"
|
|
770
|
+
},
|
|
771
|
+
"verbose": false,
|
|
772
|
+
"spinnerTipsEnabled": false,
|
|
773
|
+
"spinnerVerbs": {
|
|
774
|
+
"mode": "replace",
|
|
775
|
+
"verbs": [
|
|
776
|
+
"Working",
|
|
777
|
+
"Working (Just be patient)"
|
|
778
|
+
]
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
if (opts.ase) {
|
|
782
|
+
claudeSettings = deepmerge(claudeSettings, {
|
|
783
|
+
"statusLine": {
|
|
784
|
+
"type": "command",
|
|
785
|
+
"command": "ase statusline -w 0 -m 2 '<blue>%u</blue> <red>%p</red> <black>%T</black> %s' '%m %e %t' '%P %c'",
|
|
786
|
+
"padding": 0
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
if (opts.tmux) {
|
|
791
|
+
claudeSettings = deepmerge(claudeSettings, {
|
|
792
|
+
"env": {
|
|
793
|
+
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
|
|
794
|
+
},
|
|
795
|
+
"teammateMode": "tmux",
|
|
796
|
+
"preferences": {
|
|
797
|
+
"tmuxSplitPanes": true
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
/* execute "claude" */
|
|
802
|
+
const claudeBin = path.join(HOME, ".local/bin/claude");
|
|
803
|
+
if (recolor) {
|
|
804
|
+
return execInherit("ansi-recolor", [
|
|
805
|
+
"-c", path.join(basedir, "ansi-recolor.conf"),
|
|
806
|
+
"-m",
|
|
807
|
+
"-n", "claude",
|
|
808
|
+
"-t", path.join(HOME, "ansi-recolor.txt"),
|
|
809
|
+
claudeBin,
|
|
810
|
+
"--settings", JSON.stringify(claudeSettings),
|
|
811
|
+
...args
|
|
812
|
+
], { env });
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
return execInherit(claudeBin, [
|
|
816
|
+
"--settings", JSON.stringify(claudeSettings),
|
|
817
|
+
...args
|
|
818
|
+
], { env });
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
/* action: top-level "-h/--help" */
|
|
822
|
+
const actionHelp = () => {
|
|
823
|
+
/* run "claude --help" */
|
|
824
|
+
process.env.PATH = `${HOME}/.local/bin:${process.env.PATH ?? ""}`;
|
|
825
|
+
ensureTool("claude");
|
|
826
|
+
const claudeBin = path.join(HOME, ".local/bin/claude");
|
|
827
|
+
execaSync(claudeBin, ["--help"], { reject: false, stdio: ["ignore", "inherit", "inherit"] });
|
|
828
|
+
/* append our claudeX extension information */
|
|
829
|
+
process.stdout.write("\n" +
|
|
830
|
+
"claudeX extension options (honored before claude):\n" +
|
|
831
|
+
" -A, --ase enable ASE-specific Claude Code statusline and ASE_* environment variables\n" +
|
|
832
|
+
" -C, --capsula execute Claude Code inside a Capsula sandbox container\n" +
|
|
833
|
+
" -R, --recolor wrap Claude Code with ANSI recoloring for improved theming\n" +
|
|
834
|
+
" -T, --tmux [session] wrap Claude Code in a Tmux terminal multiplexing session (optional session name)\n" +
|
|
835
|
+
"\n" +
|
|
836
|
+
"claudeX extension subcommands (honored before claude):\n" +
|
|
837
|
+
" install install host-side or in-container dependencies\n" +
|
|
838
|
+
" update update host-side or in-container dependencies\n" +
|
|
839
|
+
" internal … internal command dispatcher (internal use only)\n");
|
|
840
|
+
process.exit(0);
|
|
841
|
+
};
|
|
842
|
+
/* the main procedure -- builds and dispatches according to options and commands */
|
|
843
|
+
const main = async () => {
|
|
844
|
+
/* intercept top-level "-h/--help" before commander grabs it, so we can
|
|
845
|
+
pass-through to "claude --help" and append our extension info */
|
|
846
|
+
const topArgs = process.argv.slice(2);
|
|
847
|
+
const firstNonFlag = topArgs.findIndex((a) => !a.startsWith("-"));
|
|
848
|
+
const headFlags = firstNonFlag < 0 ? topArgs : topArgs.slice(0, firstNonFlag);
|
|
849
|
+
const subcmd = firstNonFlag < 0 ? "" : topArgs[firstNonFlag];
|
|
850
|
+
if ((headFlags.includes("-h") || headFlags.includes("--help"))
|
|
851
|
+
&& subcmd !== "install" && subcmd !== "update" && subcmd !== "internal")
|
|
852
|
+
actionHelp();
|
|
853
|
+
/* dispatch main command */
|
|
854
|
+
const program = new Command();
|
|
855
|
+
program
|
|
856
|
+
.name("claudex")
|
|
857
|
+
.description("Claude Code eXtended")
|
|
858
|
+
.version(JSON.parse(fs.readFileSync(path.join(basedir, "package.json"), "utf8")).version, "-V, --version")
|
|
859
|
+
.enablePositionalOptions()
|
|
860
|
+
.passThroughOptions()
|
|
861
|
+
.allowUnknownOption()
|
|
862
|
+
.helpOption(false)
|
|
863
|
+
.option("-A, --ase", "enable ASE-specific Claude Code statusline and ASE_* environment variables")
|
|
864
|
+
.option("-C, --capsula", "execute Claude Code inside a Capsula sandbox container")
|
|
865
|
+
.option("-R, --recolor", "wrap Claude Code with ANSI recoloing for improved theming")
|
|
866
|
+
.option("-T, --tmux [session]", "wrap Claude Code in a Tmux terminal multiplexing session (optional session name)")
|
|
867
|
+
.argument("[args...]", "arguments passed unparsed to Claude Code")
|
|
868
|
+
.action((args, opts) => {
|
|
869
|
+
actionDefault(opts, args);
|
|
870
|
+
});
|
|
871
|
+
/* dispatch "install" sub-command */
|
|
872
|
+
program
|
|
873
|
+
.command("install")
|
|
874
|
+
.description("install host-side or in-container dependencies")
|
|
875
|
+
.helpOption("-h, --help", "display help for command")
|
|
876
|
+
.action(async (_opts, cmd) => {
|
|
877
|
+
const capsula = cmd.parent?.opts().capsula === true;
|
|
878
|
+
await actionInstall(capsula);
|
|
879
|
+
});
|
|
880
|
+
/* dispatch "update" sub-command */
|
|
881
|
+
program
|
|
882
|
+
.command("update")
|
|
883
|
+
.description("update host-side or in-container dependencies")
|
|
884
|
+
.helpOption("-h, --help", "display help for command")
|
|
885
|
+
.action(async (_opts, cmd) => {
|
|
886
|
+
const capsula = cmd.parent?.opts().capsula === true;
|
|
887
|
+
await actionUpdate(capsula);
|
|
888
|
+
});
|
|
889
|
+
/* dispatch "internal" sub-command */
|
|
890
|
+
program
|
|
891
|
+
.command("internal")
|
|
892
|
+
.description("internal command dispatcher (tmux, shell, lazygit, ase-task-edit, capsula)")
|
|
893
|
+
.helpOption("-h, --help", "display help for command")
|
|
894
|
+
.allowUnknownOption()
|
|
895
|
+
.argument("[args...]", "internal command name and its arguments")
|
|
896
|
+
.action(async (args, _opts, cmd) => {
|
|
897
|
+
const opts = (cmd.parent?.opts() ?? {});
|
|
898
|
+
await actionInternal(opts, args);
|
|
899
|
+
});
|
|
900
|
+
await program.parseAsync(process.argv);
|
|
697
901
|
};
|
|
698
902
|
main().catch((err) => {
|
|
699
903
|
const msg = err instanceof Error ? err.message : String(err);
|