@rse/claudex 0.9.21 → 0.9.23
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 +18 -0
- package/claudex.js +108 -33
- package/claudex.ts +110 -35
- package/package.json +5 -2
- package/stx.conf +2 -2
- package/tmux.conf +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
ChangeLog
|
|
3
3
|
=========
|
|
4
4
|
|
|
5
|
+
0.9.23 (2026-05-10)
|
|
6
|
+
-------------------
|
|
7
|
+
|
|
8
|
+
- IMPROVEMENT: detect psmux on Windows and apply tmux.conf color fallback
|
|
9
|
+
- IMPROVEMENT: replace "echo $LOGNAME" with a portable variant
|
|
10
|
+
- BUGFIX: fix opening panes under Windows
|
|
11
|
+
- BUGFIX: workaround tmux statusline color issues under psmux on Windows
|
|
12
|
+
- BUGFIX: fix regexp use in psmux color fallback
|
|
13
|
+
- UPDATE: drop "--source winget" to avoid pinning to older package versions
|
|
14
|
+
|
|
15
|
+
0.9.22 (2026-05-09)
|
|
16
|
+
-------------------
|
|
17
|
+
|
|
18
|
+
- BUGFIX: fix building under Windows
|
|
19
|
+
- BUGFIX: workaround shell argument escaping and tmux argument parsing problems under Windows
|
|
20
|
+
- BUGFIX: fix internal script invocation
|
|
21
|
+
- CLEANUP: record CHANGELOG entry for previous change
|
|
22
|
+
|
|
5
23
|
0.9.21 (2026-05-09)
|
|
6
24
|
-------------------
|
|
7
25
|
|
package/claudex.js
CHANGED
|
@@ -12,6 +12,7 @@ import which from "which";
|
|
|
12
12
|
import chalk from "chalk";
|
|
13
13
|
import deepmerge from "deepmerge";
|
|
14
14
|
import { Command } from "commander";
|
|
15
|
+
import * as shQ from "shell-quote";
|
|
15
16
|
/* determine our base directory (handle absolute, relative, PATH, symlinks) */
|
|
16
17
|
const findBaseDir = () => {
|
|
17
18
|
const argv1 = process.argv[1] ?? "";
|
|
@@ -56,6 +57,17 @@ const findTool = (tool) => {
|
|
|
56
57
|
}
|
|
57
58
|
return null;
|
|
58
59
|
};
|
|
60
|
+
/* helper to detect whether the active `tmux` is actually `psmux`
|
|
61
|
+
(the Windows port). psmux does not identify itself via `tmux -V`,
|
|
62
|
+
so we instead check whether we are on Windows AND a `psmux` command
|
|
63
|
+
is available in $PATH. The result is cached after the first call. */
|
|
64
|
+
let isPsmuxCached = null;
|
|
65
|
+
const isPsmux = () => {
|
|
66
|
+
if (isPsmuxCached !== null)
|
|
67
|
+
return isPsmuxCached;
|
|
68
|
+
isPsmuxCached = process.platform === "win32" && findTool("psmux") !== null;
|
|
69
|
+
return isPsmuxCached;
|
|
70
|
+
};
|
|
59
71
|
/* helper for detecting the platform and package manager combination */
|
|
60
72
|
const detectPlatform = () => {
|
|
61
73
|
/* helper function for finding a tool in PATH */
|
|
@@ -150,10 +162,6 @@ const ensureTool = (tool, options = {}) => {
|
|
|
150
162
|
fatal(`required tool "${tool}" not found in $PATH`);
|
|
151
163
|
}
|
|
152
164
|
};
|
|
153
|
-
/* helper to POSIX-single-quote-escape a string for safe interpolation
|
|
154
|
-
into a "bash -c" command line (defense against shell injection of
|
|
155
|
-
user-supplied or env-derived values) */
|
|
156
|
-
const shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
|
|
157
165
|
/* re-invoke this same script (mirrors "$0 ..." in Bash) */
|
|
158
166
|
const self = async (...args) => {
|
|
159
167
|
const r = await execa(process.execPath, [selfPathJS, ...args], {
|
|
@@ -183,7 +191,21 @@ const detectSessionName = () => {
|
|
|
183
191
|
};
|
|
184
192
|
/* determine information */
|
|
185
193
|
const HOME = process.env.HOME ?? os.homedir();
|
|
186
|
-
const
|
|
194
|
+
const detectUser = () => {
|
|
195
|
+
if (process.env.USER)
|
|
196
|
+
return process.env.USER;
|
|
197
|
+
if (process.env.LOGNAME)
|
|
198
|
+
return process.env.LOGNAME;
|
|
199
|
+
if (process.env.USERNAME)
|
|
200
|
+
return process.env.USERNAME;
|
|
201
|
+
try {
|
|
202
|
+
return os.userInfo().username;
|
|
203
|
+
}
|
|
204
|
+
catch (_e) {
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const USER = detectUser();
|
|
187
209
|
const TERM = process.env.TERM ?? "";
|
|
188
210
|
const ENVIRONMENT = process.env.ENVIRONMENT ?? "";
|
|
189
211
|
/* helper: prune all but the given active Claude Code version */
|
|
@@ -289,7 +311,7 @@ const actionInstall = async (capsula) => {
|
|
|
289
311
|
optional: true,
|
|
290
312
|
hint: "https://git-scm.com",
|
|
291
313
|
install: {
|
|
292
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git
|
|
314
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git",
|
|
293
315
|
"windows:choco": "choco install -y --accept-license --no-progress git",
|
|
294
316
|
"macos:ports": "sudo port -N install git",
|
|
295
317
|
"macos:brew": "sudo brew install git",
|
|
@@ -449,16 +471,26 @@ const actionUpdate = async (capsula) => {
|
|
|
449
471
|
}
|
|
450
472
|
};
|
|
451
473
|
/* action: internal "tmux" -- spawn tmux with our generated configuration.
|
|
452
|
-
The tmux.conf bind-keys for new claude panes
|
|
453
|
-
|
|
454
|
-
are
|
|
455
|
-
actionDefault when entering tmux mode)
|
|
474
|
+
The tmux.conf bind-keys for new claude panes invoke "claudex" (which is
|
|
475
|
+
expected to be in $PATH); the parent invocation's pass-through flags
|
|
476
|
+
(e.g. "-R") are propagated to those panes via the CLAUDEX_FLAGS env var
|
|
477
|
+
(set by actionDefault when entering tmux mode), which the env-merge in
|
|
478
|
+
main() picks up. */
|
|
456
479
|
const actionInternalTmux = (args) => {
|
|
457
480
|
ensureTool("tmux");
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
481
|
+
let conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8");
|
|
482
|
+
conf = conf.replace(/@USER@/g, USER);
|
|
483
|
+
if (isPsmux()) {
|
|
484
|
+
/* psmux does not honor the reverse ANSI sequence in at least the statusline
|
|
485
|
+
and no expansions at all in the pane border format */
|
|
486
|
+
conf = conf.replace(/fg=default,bg=default,reverse/, "bg=black,fg=color15")
|
|
487
|
+
.replaceAll(/(status.*?)fg=blue,reverse/g, "$1bg=blue,fg=color15")
|
|
488
|
+
.replaceAll(/(status.*?)fg=blue/g, "$1bg=blue,fg=color15")
|
|
489
|
+
.replaceAll(/(status.*?)fg=red/g, "$1bg=red,fg=color15")
|
|
490
|
+
.replaceAll(/(status.*?)fg=default/g, "$1bg=black,fg=color15")
|
|
491
|
+
.replaceAll(/#\[reverse\]/g, "")
|
|
492
|
+
.replaceAll(/#\[noreverse\]/g, "");
|
|
493
|
+
}
|
|
462
494
|
const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`);
|
|
463
495
|
fs.writeFileSync(confFile, conf, { mode: 0o600 });
|
|
464
496
|
/* ensure the temp config is removed on normal exit AND on signal-driven
|
|
@@ -609,7 +641,32 @@ const actionInternalCapsula = (args) => {
|
|
|
609
641
|
...args
|
|
610
642
|
]);
|
|
611
643
|
};
|
|
612
|
-
/* action: internal
|
|
644
|
+
/* action: internal "exec" -- execute a command supplied via the
|
|
645
|
+
$CLAUDEX_INTERNAL_EXEC environment variable. The variable value is split
|
|
646
|
+
into argv via shell-quote (honoring '..' and ".." quoting, no shell
|
|
647
|
+
expansion of operators), and then the resulting command is run with stdio
|
|
648
|
+
inherited. This indirection exists to work around platforms (notably
|
|
649
|
+
Windows tmux) that mishandle quoting when a command is passed via "tmux
|
|
650
|
+
new-session" as multiple trailing argv items: we instead pass the whole
|
|
651
|
+
command as a single env-var value. */
|
|
652
|
+
const actionInternalExec = () => {
|
|
653
|
+
const cmdline = process.env.CLAUDEX_INTERNAL_EXEC ?? "";
|
|
654
|
+
if (cmdline === "")
|
|
655
|
+
fatal("CLAUDEX_INTERNAL_EXEC environment variable is empty or unset");
|
|
656
|
+
const parsed = shQ.parse(cmdline);
|
|
657
|
+
const argv = [];
|
|
658
|
+
for (const tok of parsed) {
|
|
659
|
+
if (typeof tok === "string")
|
|
660
|
+
argv.push(tok);
|
|
661
|
+
else
|
|
662
|
+
fatal("CLAUDEX_INTERNAL_EXEC contains unsupported shell construct (operators, globs, or env-var expansion are not allowed)");
|
|
663
|
+
}
|
|
664
|
+
if (argv.length === 0)
|
|
665
|
+
fatal("CLAUDEX_INTERNAL_EXEC contains no command to execute");
|
|
666
|
+
const [file, ...rest] = argv;
|
|
667
|
+
return execInherit(file, rest);
|
|
668
|
+
};
|
|
669
|
+
/* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula, exec) */
|
|
613
670
|
const actionInternal = async (opts, args) => {
|
|
614
671
|
const util = args[0];
|
|
615
672
|
const rest = args.slice(1);
|
|
@@ -619,6 +676,7 @@ const actionInternal = async (opts, args) => {
|
|
|
619
676
|
case "ase-task-edit": return actionInternalAseTaskEdit();
|
|
620
677
|
case "lazygit": return actionInternalLazygit(opts.recolor === true, rest);
|
|
621
678
|
case "capsula": return actionInternalCapsula(rest);
|
|
679
|
+
case "exec": return actionInternalExec();
|
|
622
680
|
default:
|
|
623
681
|
fatal(`invalid internal command "${util ?? ""}"`);
|
|
624
682
|
}
|
|
@@ -644,17 +702,12 @@ const actionDefault = (opts, args) => {
|
|
|
644
702
|
else
|
|
645
703
|
session = detectSessionName();
|
|
646
704
|
const rest = args;
|
|
647
|
-
/* build the in-pane self-invocation
|
|
648
|
-
const inPane = [
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
...rest.map(shq)
|
|
653
|
-
].join(" ");
|
|
654
|
-
/* propagate the chosen pass-through flags to "internal tmux" so its
|
|
655
|
-
tmux.conf bind-keys spawn new claude panes with the same flags */
|
|
705
|
+
/* build the in-pane self-invocation */
|
|
706
|
+
const inPane = shQ.quote([process.execPath, selfPathJS, ...innerFlags, ...rest]);
|
|
707
|
+
/* propagate the chosen pass-through flags to subsequent in-pane
|
|
708
|
+
"claudex" invocations via the CLAUDEX_FLAGS env var (honored by
|
|
709
|
+
the env-merge in main()) */
|
|
656
710
|
const claudexFlags = innerFlags.join(" ");
|
|
657
|
-
process.env.CLAUDEX_FLAGS_PASSTHROUGH = claudexFlags;
|
|
658
711
|
/* dispatch according to global options */
|
|
659
712
|
if (opts.capsula) {
|
|
660
713
|
/* enter/start container, then run tmux inside it */
|
|
@@ -669,24 +722,39 @@ const actionDefault = (opts, args) => {
|
|
|
669
722
|
return execInherit("docker", [
|
|
670
723
|
"exec", "-i", "-t", container,
|
|
671
724
|
"bash", "-c",
|
|
672
|
-
`TERM=${
|
|
725
|
+
`TERM=${shQ.quote([TERM])} ` +
|
|
726
|
+
`HOME=${shQ.quote([HOME])} ` +
|
|
727
|
+
`CLAUDEX_FLAGS=${shQ.quote([claudexFlags])} ` +
|
|
728
|
+
`sudo -E -u ${shQ.quote([USER])} ` +
|
|
729
|
+
`${shQ.quote([process.execPath, selfPathJS])} ` +
|
|
730
|
+
`internal tmux new-session -A -s ${shQ.quote([session])}`
|
|
673
731
|
]);
|
|
674
732
|
}
|
|
675
733
|
else {
|
|
676
734
|
/* start a new container and run tmux */
|
|
677
735
|
return execInherit(process.execPath, [
|
|
678
736
|
selfPathJS, "internal", "capsula",
|
|
679
|
-
"-e", `
|
|
737
|
+
"-e", `CLAUDEX_FLAGS=${claudexFlags}`,
|
|
738
|
+
"-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
|
|
680
739
|
"-C", container, process.execPath, selfPathJS, "internal", "tmux",
|
|
681
|
-
"new-session", "-A", "-s", session, "-n", "claude",
|
|
740
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
741
|
+
"claudex", "internal", "exec"
|
|
682
742
|
]);
|
|
683
743
|
}
|
|
684
744
|
}
|
|
685
745
|
else {
|
|
686
746
|
/* enter/start plain tmux */
|
|
687
747
|
return execInherit(process.execPath, [
|
|
688
|
-
selfPathJS,
|
|
689
|
-
|
|
748
|
+
selfPathJS,
|
|
749
|
+
"internal", "tmux",
|
|
750
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
751
|
+
"claudex", "internal", "exec"
|
|
752
|
+
], {
|
|
753
|
+
env: {
|
|
754
|
+
CLAUDEX_FLAGS: claudexFlags,
|
|
755
|
+
CLAUDEX_INTERNAL_EXEC: inPane
|
|
756
|
+
}
|
|
757
|
+
});
|
|
690
758
|
}
|
|
691
759
|
}
|
|
692
760
|
/* branch: capsula-only mode */
|
|
@@ -697,22 +765,29 @@ const actionDefault = (opts, args) => {
|
|
|
697
765
|
const session = detectSessionName();
|
|
698
766
|
const container = `capsula-${USER}-debian-claude-${session}`;
|
|
699
767
|
const inspect = execaSync("docker", ["inspect", "-f", "{{.State.Running}}", container], { reject: false });
|
|
768
|
+
const passthru = [...innerFlags, ...args];
|
|
700
769
|
if (inspect.exitCode === 0) {
|
|
701
770
|
/* start the container if it exists but is not running */
|
|
702
771
|
if (inspect.stdout.trim() !== "true")
|
|
703
772
|
execaSync("docker", ["start", container], { reject: false, stdio: "ignore" });
|
|
704
773
|
/* enter already running container and run claude (single-quote shell-escape) */
|
|
705
|
-
const passthru = [...innerFlags, ...args].map(shq).join(" ");
|
|
706
774
|
return execInherit("docker", [
|
|
707
775
|
"exec", "-i", "-t", container,
|
|
708
776
|
"bash", "-c",
|
|
709
|
-
`TERM=${
|
|
777
|
+
`TERM=${shQ.quote([TERM])} ` +
|
|
778
|
+
`HOME=${shQ.quote([HOME])} ` +
|
|
779
|
+
`sudo -E -u ${shQ.quote([USER])} ` +
|
|
780
|
+
`${shQ.quote([process.execPath, selfPathJS])} ` +
|
|
781
|
+
`${shQ.quote(passthru)}`
|
|
710
782
|
]);
|
|
711
783
|
}
|
|
712
784
|
else {
|
|
713
785
|
/* start a new container and run claude */
|
|
714
786
|
return execInherit(process.execPath, [
|
|
715
|
-
selfPathJS,
|
|
787
|
+
selfPathJS,
|
|
788
|
+
"internal", "capsula", "-C", container,
|
|
789
|
+
process.execPath, selfPathJS,
|
|
790
|
+
...passthru
|
|
716
791
|
]);
|
|
717
792
|
}
|
|
718
793
|
}
|
package/claudex.ts
CHANGED
|
@@ -13,6 +13,7 @@ import which from "which"
|
|
|
13
13
|
import chalk from "chalk"
|
|
14
14
|
import deepmerge from "deepmerge"
|
|
15
15
|
import { Command } from "commander"
|
|
16
|
+
import * as shQ from "shell-quote"
|
|
16
17
|
|
|
17
18
|
/* type for environment variable map */
|
|
18
19
|
type Env = Record<string, string | undefined>
|
|
@@ -66,6 +67,18 @@ const findTool = (tool: string): string | null => {
|
|
|
66
67
|
return null
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/* helper to detect whether the active `tmux` is actually `psmux`
|
|
71
|
+
(the Windows port). psmux does not identify itself via `tmux -V`,
|
|
72
|
+
so we instead check whether we are on Windows AND a `psmux` command
|
|
73
|
+
is available in $PATH. The result is cached after the first call. */
|
|
74
|
+
let isPsmuxCached: boolean | null = null
|
|
75
|
+
const isPsmux = (): boolean => {
|
|
76
|
+
if (isPsmuxCached !== null)
|
|
77
|
+
return isPsmuxCached
|
|
78
|
+
isPsmuxCached = process.platform === "win32" && findTool("psmux") !== null
|
|
79
|
+
return isPsmuxCached
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
/* helper for detecting the platform and package manager combination */
|
|
70
83
|
const detectPlatform = (): string => {
|
|
71
84
|
/* helper function for finding a tool in PATH */
|
|
@@ -170,12 +183,6 @@ const ensureTool = (tool: string | string[], options: {
|
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
185
|
|
|
173
|
-
/* helper to POSIX-single-quote-escape a string for safe interpolation
|
|
174
|
-
into a "bash -c" command line (defense against shell injection of
|
|
175
|
-
user-supplied or env-derived values) */
|
|
176
|
-
const shq = (s: string): string =>
|
|
177
|
-
`'${s.replace(/'/g, "'\\''")}'`
|
|
178
|
-
|
|
179
186
|
/* re-invoke this same script (mirrors "$0 ..." in Bash) */
|
|
180
187
|
const self = async (...args: string[]): Promise<number> => {
|
|
181
188
|
const r = await execa(process.execPath, [ selfPathJS, ...args ], {
|
|
@@ -207,7 +214,21 @@ const detectSessionName = (): string => {
|
|
|
207
214
|
|
|
208
215
|
/* determine information */
|
|
209
216
|
const HOME = process.env.HOME ?? os.homedir()
|
|
210
|
-
const
|
|
217
|
+
const detectUser = (): string => {
|
|
218
|
+
if (process.env.USER)
|
|
219
|
+
return process.env.USER
|
|
220
|
+
if (process.env.LOGNAME)
|
|
221
|
+
return process.env.LOGNAME
|
|
222
|
+
if (process.env.USERNAME)
|
|
223
|
+
return process.env.USERNAME
|
|
224
|
+
try {
|
|
225
|
+
return os.userInfo().username
|
|
226
|
+
}
|
|
227
|
+
catch (_e) {
|
|
228
|
+
return ""
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const USER = detectUser()
|
|
211
232
|
const TERM = process.env.TERM ?? ""
|
|
212
233
|
const ENVIRONMENT = process.env.ENVIRONMENT ?? ""
|
|
213
234
|
|
|
@@ -338,7 +359,7 @@ const actionInstall = async (capsula: boolean): Promise<void> => {
|
|
|
338
359
|
optional: true,
|
|
339
360
|
hint: "https://git-scm.com",
|
|
340
361
|
install: {
|
|
341
|
-
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git
|
|
362
|
+
"windows:winget": "winget install --accept-package-agreements --accept-source-agreements --silent -e --id Git.Git",
|
|
342
363
|
"windows:choco": "choco install -y --accept-license --no-progress git",
|
|
343
364
|
"macos:ports": "sudo port -N install git",
|
|
344
365
|
"macos:brew": "sudo brew install git",
|
|
@@ -521,16 +542,26 @@ const actionUpdate = async (capsula: boolean): Promise<void> => {
|
|
|
521
542
|
}
|
|
522
543
|
|
|
523
544
|
/* action: internal "tmux" -- spawn tmux with our generated configuration.
|
|
524
|
-
The tmux.conf bind-keys for new claude panes
|
|
525
|
-
|
|
526
|
-
are
|
|
527
|
-
actionDefault when entering tmux mode)
|
|
545
|
+
The tmux.conf bind-keys for new claude panes invoke "claudex" (which is
|
|
546
|
+
expected to be in $PATH); the parent invocation's pass-through flags
|
|
547
|
+
(e.g. "-R") are propagated to those panes via the CLAUDEX_FLAGS env var
|
|
548
|
+
(set by actionDefault when entering tmux mode), which the env-merge in
|
|
549
|
+
main() picks up. */
|
|
528
550
|
const actionInternalTmux = (args: string[]): never => {
|
|
529
551
|
ensureTool("tmux")
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
552
|
+
let conf = fs.readFileSync(path.join(basedir, "tmux.conf"), "utf8")
|
|
553
|
+
conf = conf.replace(/@USER@/g, USER)
|
|
554
|
+
if (isPsmux()) {
|
|
555
|
+
/* psmux does not honor the reverse ANSI sequence in at least the statusline
|
|
556
|
+
and no expansions at all in the pane border format */
|
|
557
|
+
conf = conf.replace(/fg=default,bg=default,reverse/, "bg=black,fg=color15")
|
|
558
|
+
.replaceAll(/(status.*?)fg=blue,reverse/g, "$1bg=blue,fg=color15")
|
|
559
|
+
.replaceAll(/(status.*?)fg=blue/g, "$1bg=blue,fg=color15")
|
|
560
|
+
.replaceAll(/(status.*?)fg=red/g, "$1bg=red,fg=color15")
|
|
561
|
+
.replaceAll(/(status.*?)fg=default/g, "$1bg=black,fg=color15")
|
|
562
|
+
.replaceAll(/#\[reverse\]/g, "")
|
|
563
|
+
.replaceAll(/#\[noreverse\]/g, "")
|
|
564
|
+
}
|
|
534
565
|
const confFile = path.join(os.tmpdir(), `claudex-tmux-${process.pid}.conf`)
|
|
535
566
|
fs.writeFileSync(confFile, conf, { mode: 0o600 })
|
|
536
567
|
/* ensure the temp config is removed on normal exit AND on signal-driven
|
|
@@ -688,7 +719,33 @@ const actionInternalCapsula = (args: string[]): never => {
|
|
|
688
719
|
])
|
|
689
720
|
}
|
|
690
721
|
|
|
691
|
-
/* action: internal
|
|
722
|
+
/* action: internal "exec" -- execute a command supplied via the
|
|
723
|
+
$CLAUDEX_INTERNAL_EXEC environment variable. The variable value is split
|
|
724
|
+
into argv via shell-quote (honoring '..' and ".." quoting, no shell
|
|
725
|
+
expansion of operators), and then the resulting command is run with stdio
|
|
726
|
+
inherited. This indirection exists to work around platforms (notably
|
|
727
|
+
Windows tmux) that mishandle quoting when a command is passed via "tmux
|
|
728
|
+
new-session" as multiple trailing argv items: we instead pass the whole
|
|
729
|
+
command as a single env-var value. */
|
|
730
|
+
const actionInternalExec = (): never => {
|
|
731
|
+
const cmdline = process.env.CLAUDEX_INTERNAL_EXEC ?? ""
|
|
732
|
+
if (cmdline === "")
|
|
733
|
+
fatal("CLAUDEX_INTERNAL_EXEC environment variable is empty or unset")
|
|
734
|
+
const parsed = shQ.parse(cmdline)
|
|
735
|
+
const argv: string[] = []
|
|
736
|
+
for (const tok of parsed) {
|
|
737
|
+
if (typeof tok === "string")
|
|
738
|
+
argv.push(tok)
|
|
739
|
+
else
|
|
740
|
+
fatal("CLAUDEX_INTERNAL_EXEC contains unsupported shell construct (operators, globs, or env-var expansion are not allowed)")
|
|
741
|
+
}
|
|
742
|
+
if (argv.length === 0)
|
|
743
|
+
fatal("CLAUDEX_INTERNAL_EXEC contains no command to execute")
|
|
744
|
+
const [ file, ...rest ] = argv
|
|
745
|
+
return execInherit(file, rest)
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/* action: internal sub-dispatch (tmux, shell, ase-task-edit, lazygit, capsula, exec) */
|
|
692
749
|
const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
|
|
693
750
|
const util = args[0]
|
|
694
751
|
const rest = args.slice(1)
|
|
@@ -698,6 +755,7 @@ const actionInternal = async (opts: TopOpts, args: string[]): Promise<void> => {
|
|
|
698
755
|
case "ase-task-edit": return actionInternalAseTaskEdit()
|
|
699
756
|
case "lazygit": return actionInternalLazygit(opts.recolor === true, rest)
|
|
700
757
|
case "capsula": return actionInternalCapsula(rest)
|
|
758
|
+
case "exec": return actionInternalExec()
|
|
701
759
|
default:
|
|
702
760
|
fatal(`invalid internal command "${util ?? ""}"`)
|
|
703
761
|
}
|
|
@@ -727,18 +785,13 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
|
|
|
727
785
|
session = detectSessionName()
|
|
728
786
|
const rest = args
|
|
729
787
|
|
|
730
|
-
/* build the in-pane self-invocation
|
|
731
|
-
const inPane = [
|
|
732
|
-
shq(process.execPath),
|
|
733
|
-
shq(selfPathJS),
|
|
734
|
-
...innerFlags.map(shq),
|
|
735
|
-
...rest.map(shq)
|
|
736
|
-
].join(" ")
|
|
788
|
+
/* build the in-pane self-invocation */
|
|
789
|
+
const inPane = shQ.quote([ process.execPath, selfPathJS, ...innerFlags, ...rest ])
|
|
737
790
|
|
|
738
|
-
/* propagate the chosen pass-through flags to
|
|
739
|
-
|
|
791
|
+
/* propagate the chosen pass-through flags to subsequent in-pane
|
|
792
|
+
"claudex" invocations via the CLAUDEX_FLAGS env var (honored by
|
|
793
|
+
the env-merge in main()) */
|
|
740
794
|
const claudexFlags = innerFlags.join(" ")
|
|
741
|
-
process.env.CLAUDEX_FLAGS_PASSTHROUGH = claudexFlags
|
|
742
795
|
|
|
743
796
|
/* dispatch according to global options */
|
|
744
797
|
if (opts.capsula) {
|
|
@@ -755,24 +808,39 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
|
|
|
755
808
|
return execInherit("docker", [
|
|
756
809
|
"exec", "-i", "-t", container,
|
|
757
810
|
"bash", "-c",
|
|
758
|
-
`TERM=${
|
|
811
|
+
`TERM=${shQ.quote([ TERM ])} ` +
|
|
812
|
+
`HOME=${shQ.quote([ HOME ])} ` +
|
|
813
|
+
`CLAUDEX_FLAGS=${shQ.quote([ claudexFlags ])} ` +
|
|
814
|
+
`sudo -E -u ${shQ.quote([ USER ])} ` +
|
|
815
|
+
`${shQ.quote([ process.execPath, selfPathJS ])} ` +
|
|
816
|
+
`internal tmux new-session -A -s ${shQ.quote([ session ])}`
|
|
759
817
|
])
|
|
760
818
|
}
|
|
761
819
|
else {
|
|
762
820
|
/* start a new container and run tmux */
|
|
763
821
|
return execInherit(process.execPath, [
|
|
764
822
|
selfPathJS, "internal", "capsula",
|
|
765
|
-
"-e", `
|
|
823
|
+
"-e", `CLAUDEX_FLAGS=${claudexFlags}`,
|
|
824
|
+
"-e", `CLAUDEX_INTERNAL_EXEC=${inPane}`,
|
|
766
825
|
"-C", container, process.execPath, selfPathJS, "internal", "tmux",
|
|
767
|
-
"new-session", "-A", "-s", session, "-n", "claude",
|
|
826
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
827
|
+
"claudex", "internal", "exec"
|
|
768
828
|
])
|
|
769
829
|
}
|
|
770
830
|
}
|
|
771
831
|
else {
|
|
772
832
|
/* enter/start plain tmux */
|
|
773
833
|
return execInherit(process.execPath, [
|
|
774
|
-
selfPathJS,
|
|
775
|
-
|
|
834
|
+
selfPathJS,
|
|
835
|
+
"internal", "tmux",
|
|
836
|
+
"new-session", "-A", "-s", session, "-n", "claude",
|
|
837
|
+
"claudex", "internal", "exec"
|
|
838
|
+
], {
|
|
839
|
+
env: {
|
|
840
|
+
CLAUDEX_FLAGS: claudexFlags,
|
|
841
|
+
CLAUDEX_INTERNAL_EXEC: inPane
|
|
842
|
+
}
|
|
843
|
+
})
|
|
776
844
|
}
|
|
777
845
|
}
|
|
778
846
|
|
|
@@ -784,23 +852,30 @@ const actionDefault = (opts: TopOpts, args: string[]): never => {
|
|
|
784
852
|
const session = detectSessionName()
|
|
785
853
|
const container = `capsula-${USER}-debian-claude-${session}`
|
|
786
854
|
const inspect = execaSync("docker", [ "inspect", "-f", "{{.State.Running}}", container ], { reject: false })
|
|
855
|
+
const passthru = [ ...innerFlags, ...args ]
|
|
787
856
|
if (inspect.exitCode === 0) {
|
|
788
857
|
/* start the container if it exists but is not running */
|
|
789
858
|
if (inspect.stdout.trim() !== "true")
|
|
790
859
|
execaSync("docker", [ "start", container ], { reject: false, stdio: "ignore" })
|
|
791
860
|
|
|
792
861
|
/* enter already running container and run claude (single-quote shell-escape) */
|
|
793
|
-
const passthru = [ ...innerFlags, ...args ].map(shq).join(" ")
|
|
794
862
|
return execInherit("docker", [
|
|
795
863
|
"exec", "-i", "-t", container,
|
|
796
864
|
"bash", "-c",
|
|
797
|
-
`TERM=${
|
|
865
|
+
`TERM=${shQ.quote([ TERM ])} ` +
|
|
866
|
+
`HOME=${shQ.quote([ HOME ])} ` +
|
|
867
|
+
`sudo -E -u ${shQ.quote([ USER ])} ` +
|
|
868
|
+
`${shQ.quote([ process.execPath, selfPathJS ])} ` +
|
|
869
|
+
`${shQ.quote(passthru)}`
|
|
798
870
|
])
|
|
799
871
|
}
|
|
800
872
|
else {
|
|
801
873
|
/* start a new container and run claude */
|
|
802
874
|
return execInherit(process.execPath, [
|
|
803
|
-
selfPathJS,
|
|
875
|
+
selfPathJS,
|
|
876
|
+
"internal", "capsula", "-C", container,
|
|
877
|
+
process.execPath, selfPathJS,
|
|
878
|
+
...passthru
|
|
804
879
|
])
|
|
805
880
|
}
|
|
806
881
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rse/claudex",
|
|
3
3
|
"publishConfig": { "access": "public" },
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.23",
|
|
5
5
|
"description": "Claude Code eXtended",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [ "claude", "code", "extension", "wrapper" ],
|
|
@@ -20,12 +20,15 @@
|
|
|
20
20
|
"execa": "9.6.1",
|
|
21
21
|
"chalk": "5.6.2",
|
|
22
22
|
"commander": "14.0.3",
|
|
23
|
-
"deepmerge": "4.3.1"
|
|
23
|
+
"deepmerge": "4.3.1",
|
|
24
|
+
"shescape": "2.1.12",
|
|
25
|
+
"shell-quote": "1.8.3"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"typescript": "6.0.3",
|
|
27
29
|
"@types/node": "25.6.2",
|
|
28
30
|
"@types/which": "3.0.4",
|
|
31
|
+
"@types/shell-quote": "1.7.5",
|
|
29
32
|
|
|
30
33
|
"@rse/stx": "1.1.5",
|
|
31
34
|
"eslint": "9.39.4",
|
package/stx.conf
CHANGED
package/tmux.conf
CHANGED
|
@@ -175,7 +175,7 @@ set-option -g -s escape-time 50
|
|
|
175
175
|
set-option -g status-keys emacs
|
|
176
176
|
set-option -g status-style fg=default,bg=default,reverse
|
|
177
177
|
set-option -g status-justify right
|
|
178
|
-
set-option -g status-left " claudeX #[fg=blue] ※
|
|
178
|
+
set-option -g status-left " claudeX #[fg=blue] ※ @USER@ #[fg=default] #{?session_attached,#[fg=red] ⚑ #{session_name} #[fg=default],}"
|
|
179
179
|
set-option -g status-left-length 30
|
|
180
180
|
set-option -g status-right ""
|
|
181
181
|
set-option -g status-right-length 90
|
|
@@ -196,12 +196,12 @@ set-option -as terminal-overrides ",*:RGB"
|
|
|
196
196
|
set-option -as terminal-overrides ',*:Tc:sitm=\E[3m:ritm=\E[23m'
|
|
197
197
|
|
|
198
198
|
# claudeX specifics
|
|
199
|
-
bind-key c new-window -c "#{pane_current_path}" -n claude "
|
|
200
|
-
bind-key | split-window -c "#{pane_current_path}" -h "
|
|
201
|
-
bind-key - split-window -c "#{pane_current_path}" -v "
|
|
202
|
-
bind-key g display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Version Control (lazygit) #[noreverse]▶" "
|
|
203
|
-
bind-key s display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Shell #[noreverse]▶" "
|
|
204
|
-
bind-key q display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Task Edit (ase task edit) #[noreverse]▶" "
|
|
199
|
+
bind-key c new-window -c "#{pane_current_path}" -n claude "claudex"
|
|
200
|
+
bind-key | split-window -c "#{pane_current_path}" -h "claudex"
|
|
201
|
+
bind-key - split-window -c "#{pane_current_path}" -v "claudex"
|
|
202
|
+
bind-key g display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Version Control (lazygit) #[noreverse]▶" "claudex internal lazygit"
|
|
203
|
+
bind-key s display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Shell #[noreverse]▶" "claudex internal shell"
|
|
204
|
+
bind-key q display-popup -E -w 95% -h 95% -T "─◀#[reverse] ⧉ Task Edit (ase task edit) #[noreverse]▶" "claudex internal ase-task-edit"
|
|
205
205
|
bind-key t send-keys "/ase:ase-meta-task "
|
|
206
206
|
bind-key p send-keys "/ase:ase-meta-persona "
|
|
207
207
|
|