From 151b923d5409975f57d145b82b9c0d15ee772b59 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Thu, 19 Mar 2026 21:21:23 -0400 Subject: [PATCH] fix: include cache bin directory in which() lookups Move Global.Path.bin from the data directory to the cache directory, and append it to PATH in which() so tools installed via npm are discoverable without being on the system PATH. --- packages/opencode/src/global/index.ts | 2 +- packages/opencode/src/util/which.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/global/index.ts b/packages/opencode/src/global/index.ts index 2913ac90fe03..869019e2ce74 100644 --- a/packages/opencode/src/global/index.ts +++ b/packages/opencode/src/global/index.ts @@ -18,7 +18,7 @@ export namespace Global { return process.env.OPENCODE_TEST_HOME || os.homedir() }, data, - bin: path.join(data, "bin"), + bin: path.join(cache, "bin"), log: path.join(data, "log"), cache, config, diff --git a/packages/opencode/src/util/which.ts b/packages/opencode/src/util/which.ts index 81da2572170f..2e40739148a1 100644 --- a/packages/opencode/src/util/which.ts +++ b/packages/opencode/src/util/which.ts @@ -1,9 +1,13 @@ import whichPkg from "which" +import path from "path" +import { Global } from "../global" export function which(cmd: string, env?: NodeJS.ProcessEnv) { + const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? "" + const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin const result = whichPkg.sync(cmd, { nothrow: true, - path: env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path, + path: full, pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt, }) return typeof result === "string" ? result : null