| 147 | // Duplicated in `packages/sdk/js/src/process.ts` because the SDK cannot import |
| 148 | // `opencode` without creating a cycle. Keep both copies in sync. |
| 149 | export async function stop(proc: ChildProcess) { |
| 150 | if (proc.exitCode !== null || proc.signalCode !== null) return |
| 151 | |
| 152 | if (process.platform !== "win32" || !proc.pid) { |
| 153 | proc.kill() |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | const out = await run(["taskkill", "/pid", String(proc.pid), "/T", "/F"], { |
| 158 | nothrow: true, |
| 159 | }) |
| 160 | |
| 161 | if (out.code === 0) return |
| 162 | proc.kill() |
| 163 | } |
| 164 | |
| 165 | export async function text(cmd: string[], opts: RunOptions = {}): Promise<TextResult> { |
| 166 | const out = await run(cmd, opts) |