fix(remote): bootstrap PATH consistently for remote tmux (johoja12/Codeman#15)

This commit is contained in:
Saqeb Akhter authored and Codeman maintainer committed 2026-10-24 14:52:26 +02:00
1 parent 002de32a08
commit 5b9445de9e
8 files changed
+223 -19

No files matched your search

+20 -3
View File
@@ -89,6 +89,19 @@ export function remoteLoginShellCommand(command: string): string {
return `exec ${REMOTE_LOGIN_SHELL} -i -l -c ${shellescape(command)}`;
}
/**
* Remote tmux runs in sshd's non-interactive shell, which may omit Homebrew and
* per-user binaries. Keep every remote tmux operation on the same PATH. Quoting
* the entire assignment preserves spaces in HOME/inherited PATH under dash too.
* CLI commands still use their existing login-shell/configuration handling.
*/
export function withRemoteTmuxPath(command: string): string {
return (
'export PATH="$HOME/.opencode/bin:$HOME/.local/bin:$HOME/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"; ' +
command
);
}
/**
* The CLI text a location overlay should launch for `mode`, or null when this build has no
* entry for it. `overlays.<location>.command` when the entry names one, otherwise the bare
@@ -228,7 +241,11 @@ export function buildRemoteTmuxCheckCommand(
host: Pick<RemoteHost, 'username' | 'host' | 'port'> & RemoteSshOptions
): string {
// ConnectTimeout is now a default of buildSshConnectionArgs (shared with the launch).
return [...buildSshConnectionArgs(host), remoteSshTarget(host), "'command -v tmux'"].join(' ');
return [
...buildSshConnectionArgs(host),
remoteSshTarget(host),
shellescape(withRemoteTmuxPath('command -v tmux')),
].join(' ');
}
export interface RemoteTmuxCheckResult {
@@ -368,7 +385,7 @@ export function buildRemoteSessionAliveCommand(
): string {
const [ssh, ...connectionArgs] = buildSshConnectionArgs(host);
const remoteCmd = `tmux -L codeman-remote has-session -t ${shellescape(remoteSessionName)} 2>/dev/null`;
return [ssh, ...connectionArgs, remoteSshTarget(host), shellescape(remoteCmd)].join(' ');
return [ssh, ...connectionArgs, remoteSshTarget(host), shellescape(withRemoteTmuxPath(remoteCmd))].join(' ');
}
/**
@@ -453,7 +470,7 @@ export function buildRemoteListSessionsCommand(
// separators (tmux expands them); `2>/dev/null` is inside the quoted command.
const remoteCmd =
'tmux -L codeman list-sessions -F "#{session_name}\\t#{session_attached}\\t#{session_created}\\t#{session_windows}" 2>/dev/null';
parts.push(remoteSshTarget(host), shellescape(remoteCmd));
parts.push(remoteSshTarget(host), shellescape(withRemoteTmuxPath(remoteCmd)));
return parts.join(' ');
}