()
| 134 | } |
| 135 | |
| 136 | private spawnChild(): pty.IPty { |
| 137 | if (this.opts.command.length === 0) { |
| 138 | throw new Error('command must contain at least one argv element'); |
| 139 | } |
| 140 | // win32: resolve the bare CLI name to its real `.exe`, or wrap a `.cmd`/ |
| 141 | // `.ps1` npm shim through cmd.exe — ConPTY's CreateProcess only appends |
| 142 | // `.exe`, so npm-shim CLIs (opencode, pi) otherwise never launch. No-op off |
| 143 | // Windows. The interactive command is flags + launcher/adapter-generated |
| 144 | // ids, so the shell wrap is injection-safe here. See win-command.ts. |
| 145 | const [argv0, ...args] = resolveLaunchCommand(this.opts.command, { |
| 146 | env: this.opts.env, |
| 147 | }).argv; |
| 148 | if (!argv0) throw new Error('command must contain at least one argv element'); |
| 149 | |
| 150 | const term = pty.spawn(argv0, args, { |
| 151 | name: 'xterm-256color', |
| 152 | cols: this.currentCols, |
| 153 | rows: this.currentRows, |
| 154 | cwd: this.opts.cwd, |
| 155 | env: this.opts.env, |
| 156 | // Raw bytes; xterm.js decodes UTF-8 with proper streaming state. |
| 157 | encoding: null, |
| 158 | }); |
| 159 | |
| 160 | term.onData((data) => this.onPtyData(data as unknown as Buffer | string)); |
| 161 | term.onExit(({ exitCode, signal }) => this.onChildExit(term, exitCode, signal)); |
| 162 | return term; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Child process exited but the session itself is sticking around. We tell |
no test coverage detected