fix: expose user tool path in ssh scripts

This commit is contained in:
Codex
2026-05-31 07:46:47 +00:00
parent 0542eb98f7
commit b6d088a3cc
2 changed files with 38 additions and 4 deletions
+18 -3
View File
@@ -89,6 +89,16 @@ const defaultSshSlowWarningMs = 10_000;
const defaultSshRuntimeTimeoutMs = 60_000;
const maxSshRuntimeTimeoutMs = 60_000;
export const sshShellCompatibilityPrelude = 'printf(){ if [ "${1+x}" = x ] && [ "$1" = "-v" ] && [ -n "${BASH_VERSION:-}" ]; then command printf "$@"; return $?; fi; if [ "${1+x}" = x ] && [ "$1" = "--" ]; then shift; fi; command printf -- "$@"; }';
export const sshUserToolPathPrelude = [
'for unidesk_path_dir in "$HOME/.bun/bin" "$HOME/.local/bin" "$HOME/bin" "/root/.bun/bin"; do',
' [ -d "$unidesk_path_dir" ] || continue',
' case ":$PATH:" in',
' *":$unidesk_path_dir:"*) ;;',
' *) PATH="$unidesk_path_dir:$PATH" ;;',
" esac",
"done",
"export PATH",
].join("\n");
const k3sResourceKindAliases = new Set(["pod", "po", "pods", "deployment", "deploy", "deployments", "statefulset", "sts", "daemonset", "ds", "job", "jobs"]);
const k3sPodRoutePrefixes = ["pod:", "po:", "pods:"];
const legacyK3sOperationRouteSegments = new Set([
@@ -1857,12 +1867,16 @@ function k3sScriptShell(value: string, option: string): string {
return value;
}
function shellScriptPrelude(): string {
return `${sshUserToolPathPrelude}\n${sshShellCompatibilityPrelude}`;
}
function shellScriptWithCompatibility(command: string): string {
return `${sshShellCompatibilityPrelude}\n${command}`;
return `${shellScriptPrelude()}\n${command}`;
}
function shellScriptStdinPrefix(): string {
return `${sshShellCompatibilityPrelude}\n`;
return `${shellScriptPrelude()}\n`;
}
function buildShellCommand(args: string[]): ParsedSshArgs {
@@ -1963,7 +1977,8 @@ function remoteToolBootstrapCommand(helpers: readonly SshHelperName[] = []): str
export function wrapSshRemoteCommand(command: string | null, helpers: readonly SshHelperName[] = []): string {
const bootstrap = remoteToolBootstrapCommand(helpers);
const prefix = bootstrap.length > 0 ? `${bootstrap}; ` : "";
const prelude = [sshUserToolPathPrelude, bootstrap].filter((part) => part.length > 0).join("; ");
const prefix = prelude.length > 0 ? `${prelude}; ` : "";
if (command === null) return `${prefix}exec "\${SHELL:-/bin/bash}" -l`;
return `${prefix}stty -echo 2>/dev/null || true; ${command}`;
}