@volter/supercode-terminal 0.2.60 → 0.2.61
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/package.json +1 -1
- package/substrate/tmux.js +14 -3
package/package.json
CHANGED
package/substrate/tmux.js
CHANGED
|
@@ -59,12 +59,22 @@ export async function createSession({ command, cwd, env, name, owner, ownerOptio
|
|
|
59
59
|
// set-options just configured. On an already-running server they are simply
|
|
60
60
|
// reapplied.
|
|
61
61
|
const sessionEnv = env ?? {};
|
|
62
|
+
// A tmux server keeps the environment of whoever started it as its global environment, and every pane inherits
|
|
63
|
+
// it. When an agent's session started the server (or is the launcher), that includes the session's own harness
|
|
64
|
+
// identity, so a new pane would resolve as that session. A pane's identity is only what its own session sets:
|
|
65
|
+
// every identity variable the server or the launcher holds and the session does not set is unset in the pane.
|
|
66
|
+
const identity = /^(CLAUDECODE|CLAUDE_CODE_SESSION_ID|CLAUDE_CODE_ENTRYPOINT|CODEX_THREAD_ID|CODEX_SESSION_ID|SUPERCODE_CALLER|SUPERCODE_CALLER_NAME|SUPERCODE_AGENT_[A-Z_]+)$/;
|
|
67
|
+
const serverNames = await runAsync("tmux", tmuxArgs(socket, ["show-environment", "-g"]))
|
|
68
|
+
.then((out) => out.split("\n").map((line) => /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(line)?.[1]).filter((name) => Boolean(name)))
|
|
69
|
+
.catch(() => []); // no server yet: the one this creates starts from this launcher's environment
|
|
70
|
+
const inherited = [...new Set([...serverNames, ...Object.keys(process.env)])]
|
|
71
|
+
.filter((name) => identity.test(name) && !(name in sessionEnv));
|
|
62
72
|
const bootstrapDirectories = [];
|
|
63
73
|
const paneBootstrapArgs = (pane) => {
|
|
64
74
|
const commandArgs = command === undefined ? [] : [command.program, ...(command.arguments ?? [])];
|
|
65
75
|
// With neither command nor overrides, retain tmux's default-shell and
|
|
66
76
|
// default-command behavior rather than choosing a shell for it.
|
|
67
|
-
if (command === undefined && Object.keys(sessionEnv).length === 0)
|
|
77
|
+
if (command === undefined && Object.keys(sessionEnv).length === 0 && inherited.length === 0)
|
|
68
78
|
return [];
|
|
69
79
|
// The complete command rides the private bootstrap file as well as its
|
|
70
80
|
// environment. tmux's command message is bounded (roughly 16 KiB), much
|
|
@@ -72,7 +82,7 @@ export async function createSession({ command, cwd, env, name, owner, ownerOptio
|
|
|
72
82
|
const directory = mkdtempSync(join(tmpdir(), "tmux-session-env-"));
|
|
73
83
|
bootstrapDirectories.push(directory);
|
|
74
84
|
const shell = process.env.SHELL ?? "/bin/sh";
|
|
75
|
-
return writeSessionEnvironmentBootstrap(directory, pane, sessionEnv, commandArgs.length === 0 ? [shell, "-l"] : commandArgs);
|
|
85
|
+
return writeSessionEnvironmentBootstrap(directory, pane, sessionEnv, inherited, commandArgs.length === 0 ? [shell, "-l"] : commandArgs);
|
|
76
86
|
};
|
|
77
87
|
try {
|
|
78
88
|
const startArgs = [...sessionServerOptionArgs(), "new-session", "-d", "-s", name];
|
|
@@ -395,7 +405,7 @@ function tmuxClientEnvironment(source = process.env) {
|
|
|
395
405
|
}
|
|
396
406
|
return environment;
|
|
397
407
|
}
|
|
398
|
-
function writeSessionEnvironmentBootstrap(directory, pane, environment, command) {
|
|
408
|
+
function writeSessionEnvironmentBootstrap(directory, pane, environment, unset, command) {
|
|
399
409
|
const environmentPath = join(directory, `pane-${pane}.env`);
|
|
400
410
|
const wrapperPath = join(directory, `pane-${pane}.sh`);
|
|
401
411
|
const lines = Object.entries(environment).map(([name, value]) => {
|
|
@@ -404,6 +414,7 @@ function writeSessionEnvironmentBootstrap(directory, pane, environment, command)
|
|
|
404
414
|
}
|
|
405
415
|
return `export ${name}=${shellQuote(value)}`;
|
|
406
416
|
});
|
|
417
|
+
lines.unshift(...unset.map((name) => `unset ${name}`));
|
|
407
418
|
writeFileSync(environmentPath, `${lines.join("\n")}\n`, { flag: "wx", mode: 0o600 });
|
|
408
419
|
writeFileSync(wrapperPath, [
|
|
409
420
|
"#!/bin/sh",
|