(config: {
cwd?: string
permissionMode?: string
dangerouslySkipPermissions?: boolean
})
| 253 | } |
| 254 | |
| 255 | export async function createLocalSSHSession(config: { |
| 256 | cwd?: string |
| 257 | permissionMode?: string |
| 258 | dangerouslySkipPermissions?: boolean |
| 259 | }): Promise<SSHSession> { |
| 260 | const { proxy, authEnv } = await createAuthProxy() |
| 261 | |
| 262 | const cliArgs: string[] = [ |
| 263 | '--output-format', |
| 264 | 'stream-json', |
| 265 | '--input-format', |
| 266 | 'stream-json', |
| 267 | '-p', |
| 268 | ] |
| 269 | if (config.cwd) { |
| 270 | cliArgs.push('--cwd', config.cwd) |
| 271 | } |
| 272 | if (config.permissionMode) { |
| 273 | cliArgs.push('--permission-mode', config.permissionMode) |
| 274 | } |
| 275 | if (config.dangerouslySkipPermissions) { |
| 276 | cliArgs.push('--dangerously-skip-permissions') |
| 277 | } |
| 278 | |
| 279 | const spec = buildCliLaunch(cliArgs) |
| 280 | |
| 281 | let proc: Subprocess |
| 282 | try { |
| 283 | proc = Bun.spawn([spec.execPath, ...spec.args], { |
| 284 | stdin: 'pipe', |
| 285 | stdout: 'pipe', |
| 286 | stderr: 'pipe', |
| 287 | env: { ...spec.env, ...authEnv }, |
| 288 | }) |
| 289 | } catch (err) { |
| 290 | proxy.stop() |
| 291 | throw new SSHSessionError( |
| 292 | `Failed to spawn local CLI process: ${err instanceof Error ? err.message : String(err)}`, |
| 293 | ) |
| 294 | } |
| 295 | |
| 296 | logForDebugging('[SSH] local session spawned, waiting for init message...') |
| 297 | |
| 298 | const stderrChunks: string[] = [] |
| 299 | collectStderr(proc, stderrChunks) |
| 300 | |
| 301 | let remoteCwd: string |
| 302 | try { |
| 303 | remoteCwd = await waitForInit(proc, config.cwd) |
| 304 | } catch (err) { |
| 305 | proxy.stop() |
| 306 | proc.kill() |
| 307 | throw err |
| 308 | } |
| 309 | |
| 310 | logForDebugging(`[SSH] local session initialized, remoteCwd=${remoteCwd}`) |
| 311 | |
| 312 | let currentProc = proc |
no test coverage detected