* feat: add windows ssh relay base support * feat: support windows ssh relay runtime services * fix: default windows ssh pty cwd to user profile * fix: support windows hosts over system ssh * fix: preserve degraded windows relay native deps * fix: gate windows shell args by relay platform * fix: preserve windows relay fallback pipes * test: align windows native deps relay fixture * fix: build valid windows install lock command * fix: address windows SSH relay review findings Resolve correctness, efficiency, and reuse issues found reviewing the Windows SSH native-host support: - GC liveness on Windows now probes the actual named pipe (via node net.connect against markers + deterministic candidates) instead of substring-matching Win32_Process command lines, which could remove a live relay dir. Reports ALIVE conservatively only when there is no liveness signal at all (no markers and no seed pipes). - Resolve the remote node path once per deploy and thread it through install/repair/launch instead of re-resolving 3-7x. - Replace the 200ms node -e poll loop with a single long-lived remote wait process during Windows relay startup. - Skip the no-op executable command on Windows in uploadRelay. - Make the Windows fallback pipe name deterministic and recoverable (drop the global counter), with an extra reconnect attempt. - Normalize the prepended node bin dir to backslashes on Windows PATH. - Batch the system-SSH Windows directory upload into a single streamed JSON package instead of one ssh process per file. - Extract relay endpoint/marker helpers into ssh-relay-endpoints.ts and consolidate the PowerShell EncodedCommand encoding into the shared powershell-command-encoding module. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Support cancellation and timeouts in Windows port scanning - Propagate the request AbortSignal and a 5-second timeout to both PowerShell and netstat child processes during Windows port scanning. - Avoid spawning the netstat fallback process if the port scan has already been aborted. - Wrap the .NET OSArchitecture check in a try/catch block during SSH Windows platform detection to robustly fall back to environment variables if needed. --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
148 lines
4.0 KiB
TypeScript
148 lines
4.0 KiB
TypeScript
import type { RelayPlatform } from './relay-protocol'
|
|
|
|
export type RemotePathFlavor = 'posix' | 'windows'
|
|
export type RemoteCommandDialect = 'posix' | 'powershell'
|
|
export type RemoteOperatingSystem = 'linux' | 'darwin' | 'win32'
|
|
export type RemoteArchitecture = 'x64' | 'arm64'
|
|
|
|
export type RemoteHostPlatform = {
|
|
relayPlatform: RelayPlatform
|
|
os: RemoteOperatingSystem
|
|
arch: RemoteArchitecture
|
|
pathFlavor: RemotePathFlavor
|
|
commandDialect: RemoteCommandDialect
|
|
pathSeparator: '/' | '\\'
|
|
pathDelimiter: ':' | ';'
|
|
}
|
|
|
|
const PLATFORM_INFO: Record<RelayPlatform, RemoteHostPlatform> = {
|
|
'linux-x64': {
|
|
relayPlatform: 'linux-x64',
|
|
os: 'linux',
|
|
arch: 'x64',
|
|
pathFlavor: 'posix',
|
|
commandDialect: 'posix',
|
|
pathSeparator: '/',
|
|
pathDelimiter: ':'
|
|
},
|
|
'linux-arm64': {
|
|
relayPlatform: 'linux-arm64',
|
|
os: 'linux',
|
|
arch: 'arm64',
|
|
pathFlavor: 'posix',
|
|
commandDialect: 'posix',
|
|
pathSeparator: '/',
|
|
pathDelimiter: ':'
|
|
},
|
|
'darwin-x64': {
|
|
relayPlatform: 'darwin-x64',
|
|
os: 'darwin',
|
|
arch: 'x64',
|
|
pathFlavor: 'posix',
|
|
commandDialect: 'posix',
|
|
pathSeparator: '/',
|
|
pathDelimiter: ':'
|
|
},
|
|
'darwin-arm64': {
|
|
relayPlatform: 'darwin-arm64',
|
|
os: 'darwin',
|
|
arch: 'arm64',
|
|
pathFlavor: 'posix',
|
|
commandDialect: 'posix',
|
|
pathSeparator: '/',
|
|
pathDelimiter: ':'
|
|
},
|
|
'win32-x64': {
|
|
relayPlatform: 'win32-x64',
|
|
os: 'win32',
|
|
arch: 'x64',
|
|
pathFlavor: 'windows',
|
|
commandDialect: 'powershell',
|
|
pathSeparator: '\\',
|
|
pathDelimiter: ';'
|
|
},
|
|
'win32-arm64': {
|
|
relayPlatform: 'win32-arm64',
|
|
os: 'win32',
|
|
arch: 'arm64',
|
|
pathFlavor: 'windows',
|
|
commandDialect: 'powershell',
|
|
pathSeparator: '\\',
|
|
pathDelimiter: ';'
|
|
}
|
|
}
|
|
|
|
export function getRemoteHostPlatform(platform: RelayPlatform): RemoteHostPlatform {
|
|
return PLATFORM_INFO[platform]
|
|
}
|
|
|
|
export function isWindowsRemoteHost(host: RemoteHostPlatform): boolean {
|
|
return host.os === 'win32'
|
|
}
|
|
|
|
export function normalizeWindowsRemotePath(path: string): string {
|
|
return path.replace(/\\/g, '/')
|
|
}
|
|
|
|
export function normalizeRemoteHome(rawHome: string, host: RemoteHostPlatform): string {
|
|
const home = rawHome.trim()
|
|
return isWindowsRemoteHost(host) ? normalizeWindowsRemotePath(home).replace(/\/+$/, '') : home
|
|
}
|
|
|
|
function hasUnsafeRemotePathChar(value: string): boolean {
|
|
for (let i = 0; i < value.length; i += 1) {
|
|
const code = value.charCodeAt(i)
|
|
if (code === 0 || code === 10 || code === 13) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function validateRemoteHome(home: string, host: RemoteHostPlatform): boolean {
|
|
if (!home || hasUnsafeRemotePathChar(home)) {
|
|
return false
|
|
}
|
|
if (host.pathFlavor === 'windows') {
|
|
return /^[a-zA-Z]:\//.test(home) || home.startsWith('//')
|
|
}
|
|
return home.startsWith('/')
|
|
}
|
|
|
|
export function joinRemotePath(host: RemoteHostPlatform, ...segments: string[]): string {
|
|
const cleaned = segments.filter(Boolean)
|
|
if (cleaned.length === 0) {
|
|
return ''
|
|
}
|
|
if (host.pathFlavor === 'windows') {
|
|
const [first, ...rest] = cleaned.map((segment) => normalizeWindowsRemotePath(segment))
|
|
return rest.reduce((acc, segment) => {
|
|
const left = acc.replace(/\/+$/, '')
|
|
const right = segment.replace(/^\/+/, '')
|
|
return `${left}/${right}`
|
|
}, first)
|
|
}
|
|
const [first, ...rest] = cleaned
|
|
return rest.reduce((acc, segment) => {
|
|
const left = acc.replace(/\/+$/, '')
|
|
const right = segment.replace(/^\/+/, '')
|
|
return `${left}/${right}`
|
|
}, first)
|
|
}
|
|
|
|
export function remoteBasename(path: string, host: RemoteHostPlatform): string {
|
|
const normalized = host.pathFlavor === 'windows' ? normalizeWindowsRemotePath(path) : path
|
|
return normalized.split('/').filter(Boolean).pop() ?? ''
|
|
}
|
|
|
|
export function remoteDirname(path: string, host: RemoteHostPlatform): string {
|
|
const normalized = host.pathFlavor === 'windows' ? normalizeWindowsRemotePath(path) : path
|
|
const parts = normalized.split('/')
|
|
parts.pop()
|
|
const joined = parts.join('/')
|
|
if (host.pathFlavor === 'windows') {
|
|
return joined
|
|
}
|
|
return joined || '/'
|
|
}
|