import { resolve as resolvePath } from 'node:path' import { RuntimeClientError } from './runtime-client' function isAbsoluteServerPath(value: string): boolean { return ( value.startsWith('/') || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith('\\\\') || value.startsWith('//') ) } export function resolveRepoPathArgument( inputPath: string, cwd: string, isRemote: boolean, remotePathSubject = 'Remote repo path' ): string { if (!isRemote) { return resolvePath(cwd, inputPath) } // Why: the local CLI cwd is unrelated to a paired runtime's filesystem. // Relative remote paths would silently target the wrong machine. if (!isAbsoluteServerPath(inputPath)) { throw new RuntimeClientError( 'invalid_argument', `${remotePathSubject} requires --path to be an absolute path on the remote server.` ) } return inputPath }