summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChristian Stewart <[email protected]>2025-11-04 08:38:11 -0800
committerGitHub <[email protected]>2025-11-04 17:38:11 +0100
commit09bb8190640dabd12908b77e2f6a0390fb7fafd6 (patch)
tree3f1c2496be25962e87973a41f764550c9953ec7b
parent6f0028644e12686f1c7282e08126c9da0d0752fe (diff)
downloadopencode-09bb8190640dabd12908b77e2f6a0390fb7fafd6.tar.gz
opencode-09bb8190640dabd12908b77e2f6a0390fb7fafd6.zip
fix(tui): worker path resolution in dev mode (#3778)
Signed-off-by: Christian Stewart <[email protected]> Co-authored-by: Sebastian Herrlinger <[email protected]>
-rwxr-xr-xpackages/opencode/script/build.ts13
-rw-r--r--packages/opencode/src/cli/cmd/tui/thread.ts16
2 files changed, 24 insertions, 5 deletions
diff --git a/packages/opencode/script/build.ts b/packages/opencode/script/build.ts
index 1d3a3face..4ce8bfbad 100755
--- a/packages/opencode/script/build.ts
+++ b/packages/opencode/script/build.ts
@@ -41,7 +41,9 @@ for (const [os, arch] of targets) {
const opentui = `@opentui/core-${os === "windows" ? "win32" : os}-${arch.replace("-baseline", "")}`
await $`mkdir -p ../../node_modules/${opentui}`
- await $`npm pack ${opentui}@${pkg.dependencies["@opentui/core"]}`.cwd(path.join(dir, "../../node_modules"))
+ await $`npm pack ${opentui}@${pkg.dependencies["@opentui/core"]}`.cwd(
+ path.join(dir, "../../node_modules"),
+ )
await $`tar -xf ../../node_modules/${opentui.replace("@opentui/", "opentui-")}-*.tgz -C ../../node_modules/${opentui} --strip-components=1`
const watcher = `@parcel/watcher-${os === "windows" ? "win32" : os}-${arch.replace("-baseline", "")}${os === "linux" ? "-glibc" : ""}`
@@ -49,7 +51,11 @@ for (const [os, arch] of targets) {
await $`npm pack ${watcher}`.cwd(path.join(dir, "../../node_modules")).quiet()
await $`tar -xf ../../node_modules/${watcher.replace("@parcel/", "parcel-")}-*.tgz -C ../../node_modules/${watcher} --strip-components=1`
- const parserWorker = fs.realpathSync(path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"))
+ const parserWorker = fs.realpathSync(
+ path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"),
+ )
+ const workerPath = "./src/cli/cmd/tui/worker.ts"
+
await Bun.build({
conditions: ["browser"],
tsconfig: "./tsconfig.json",
@@ -61,10 +67,11 @@ for (const [os, arch] of targets) {
execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`],
windows: {},
},
- entrypoints: ["./src/index.ts", parserWorker, "./src/cli/cmd/tui/worker.ts"],
+ entrypoints: ["./src/index.ts", parserWorker, workerPath],
define: {
OPENCODE_VERSION: `'${Script.version}'`,
OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(dir, parserWorker),
+ OPENCODE_WORKER_PATH: workerPath,
OPENCODE_CHANNEL: `'${Script.channel}'`,
},
})
diff --git a/packages/opencode/src/cli/cmd/tui/thread.ts b/packages/opencode/src/cli/cmd/tui/thread.ts
index 0ceb87ea6..b05bb5829 100644
--- a/packages/opencode/src/cli/cmd/tui/thread.ts
+++ b/packages/opencode/src/cli/cmd/tui/thread.ts
@@ -8,6 +8,10 @@ import { bootstrap } from "@/cli/bootstrap"
import path from "path"
import { UI } from "@/cli/ui"
+declare global {
+ const OPENCODE_WORKER_PATH: string
+}
+
export const TuiThreadCommand = cmd({
command: "$0 [project]",
describe: "start opencode tui",
@@ -58,13 +62,21 @@ export const TuiThreadCommand = cmd({
return piped ? piped + "\n" + args.prompt : args.prompt
})()
- const cwd = args.project ? path.resolve(args.project) : process.cwd()
+ // Resolve relative paths against PWD to preserve behavior when using --cwd flag
+ const baseCwd = process.env.PWD ?? process.cwd()
+ const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
+ let workerPath: string | URL = new URL("./worker.ts", import.meta.url)
+
+ if (typeof OPENCODE_WORKER_PATH !== "undefined") {
+ workerPath = OPENCODE_WORKER_PATH
+ }
try {
process.chdir(cwd)
} catch (e) {
UI.error("Failed to change directory to " + cwd)
return
}
+
await bootstrap(cwd, async () => {
upgrade()
@@ -88,7 +100,7 @@ export const TuiThreadCommand = cmd({
return undefined
})()
- const worker = new Worker("./src/cli/cmd/tui/worker.ts", {
+ const worker = new Worker(workerPath, {
env: Object.fromEntries(
Object.entries(process.env).filter(
(entry): entry is [string, string] => entry[1] !== undefined,