diff --git a/packages/opencode/src/mcp/index.ts b/packages/opencode/src/mcp/index.ts index bf5a0d3ce7..e48a42a8b3 100644 --- a/packages/opencode/src/mcp/index.ts +++ b/packages/opencode/src/mcp/index.ts @@ -11,7 +11,6 @@ import { } from "@modelcontextprotocol/sdk/types.js" import { Config } from "../config/config" import { Log } from "../util/log" -import { Process } from "../util/process" import { NamedError } from "@opencode-ai/util/error" import z from "zod/v4" import { Instance } from "../project/instance" @@ -167,10 +166,14 @@ export namespace MCP { const queue = [pid] while (queue.length > 0) { const current = queue.shift()! - const lines = await Process.lines(["pgrep", "-P", String(current)], { nothrow: true }) - for (const tok of lines) { + const proc = Bun.spawn(["pgrep", "-P", String(current)], { stdout: "pipe", stderr: "pipe" }) + const [code, out] = await Promise.all([proc.exited, new Response(proc.stdout).text()]).catch( + () => [-1, ""] as const, + ) + if (code !== 0) continue + for (const tok of out.trim().split(/\s+/)) { const cpid = parseInt(tok, 10) - if (!isNaN(cpid) && !pids.includes(cpid)) { + if (!isNaN(cpid) && pids.indexOf(cpid) === -1) { pids.push(cpid) queue.push(cpid) } diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 1cc144c8d3..36162656aa 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -32,6 +32,7 @@ import { Flag } from "../flag/flag" import { ulid } from "ulid" import { spawn } from "child_process" import { Command } from "../command" +import { $ } from "bun" import { pathToFileURL, fileURLToPath } from "url" import { ConfigMarkdown } from "../config/markdown" import { SessionSummary } from "./summary" @@ -47,7 +48,6 @@ import { iife } from "@/util/iife" import { Shell } from "@/shell/shell" import { Truncate } from "@/tool/truncate" import { decodeDataUrl } from "@/util/data-url" -import { Process } from "@/util/process" // @ts-ignore globalThis.AI_SDK_LOG_WARNINGS = false @@ -1812,13 +1812,15 @@ NOTE: At any point in time through this workflow you should feel free to ask the template = template + "\n\n" + input.arguments } - const shellMatches = ConfigMarkdown.shell(template) - if (shellMatches.length > 0) { - const sh = Shell.preferred() + const shell = ConfigMarkdown.shell(template) + if (shell.length > 0) { const results = await Promise.all( - shellMatches.map(async ([, cmd]) => { - const out = await Process.text([cmd], { shell: sh, nothrow: true }) - return out.text + shell.map(async ([, cmd]) => { + try { + return await $`${{ raw: cmd }}`.quiet().nothrow().text() + } catch (error) { + return `Error executing command: ${error instanceof Error ? error.message : String(error)}` + } }), ) let index = 0