Skip to content

Commit 52a7a04

Browse files
authored
refactor: replace Bun shell execution with portable Process utilities (#18318)
1 parent 37b8662 commit 52a7a04

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

packages/opencode/src/mcp/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@modelcontextprotocol/sdk/types.js"
1212
import { Config } from "../config/config"
1313
import { Log } from "../util/log"
14+
import { Process } from "../util/process"
1415
import { NamedError } from "@opencode-ai/util/error"
1516
import z from "zod/v4"
1617
import { Instance } from "../project/instance"
@@ -166,14 +167,10 @@ export namespace MCP {
166167
const queue = [pid]
167168
while (queue.length > 0) {
168169
const current = queue.shift()!
169-
const proc = Bun.spawn(["pgrep", "-P", String(current)], { stdout: "pipe", stderr: "pipe" })
170-
const [code, out] = await Promise.all([proc.exited, new Response(proc.stdout).text()]).catch(
171-
() => [-1, ""] as const,
172-
)
173-
if (code !== 0) continue
174-
for (const tok of out.trim().split(/\s+/)) {
170+
const lines = await Process.lines(["pgrep", "-P", String(current)], { nothrow: true })
171+
for (const tok of lines) {
175172
const cpid = parseInt(tok, 10)
176-
if (!isNaN(cpid) && pids.indexOf(cpid) === -1) {
173+
if (!isNaN(cpid) && !pids.includes(cpid)) {
177174
pids.push(cpid)
178175
queue.push(cpid)
179176
}

packages/opencode/src/session/prompt.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { Flag } from "../flag/flag"
3232
import { ulid } from "ulid"
3333
import { spawn } from "child_process"
3434
import { Command } from "../command"
35-
import { $ } from "bun"
3635
import { pathToFileURL, fileURLToPath } from "url"
3736
import { ConfigMarkdown } from "../config/markdown"
3837
import { SessionSummary } from "./summary"
@@ -48,6 +47,7 @@ import { iife } from "@/util/iife"
4847
import { Shell } from "@/shell/shell"
4948
import { Truncate } from "@/tool/truncate"
5049
import { decodeDataUrl } from "@/util/data-url"
50+
import { Process } from "@/util/process"
5151

5252
// @ts-ignore
5353
globalThis.AI_SDK_LOG_WARNINGS = false
@@ -1812,15 +1812,13 @@ NOTE: At any point in time through this workflow you should feel free to ask the
18121812
template = template + "\n\n" + input.arguments
18131813
}
18141814

1815-
const shell = ConfigMarkdown.shell(template)
1816-
if (shell.length > 0) {
1815+
const shellMatches = ConfigMarkdown.shell(template)
1816+
if (shellMatches.length > 0) {
1817+
const sh = Shell.preferred()
18171818
const results = await Promise.all(
1818-
shell.map(async ([, cmd]) => {
1819-
try {
1820-
return await $`${{ raw: cmd }}`.quiet().nothrow().text()
1821-
} catch (error) {
1822-
return `Error executing command: ${error instanceof Error ? error.message : String(error)}`
1823-
}
1819+
shellMatches.map(async ([, cmd]) => {
1820+
const out = await Process.text([cmd], { shell: sh, nothrow: true })
1821+
return out.text
18241822
}),
18251823
)
18261824
let index = 0

0 commit comments

Comments
 (0)