Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 09bb819

Browse files
paralinkommander
andauthored
fix(tui): worker path resolution in dev mode (anomalyco#3778)
Signed-off-by: Christian Stewart <christian@cjs.zip> Co-authored-by: Sebastian Herrlinger <hasta84@gmail.com>
1 parent 6f00286 commit 09bb819

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

packages/opencode/script/build.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@ for (const [os, arch] of targets) {
4141

4242
const opentui = `@opentui/core-${os === "windows" ? "win32" : os}-${arch.replace("-baseline", "")}`
4343
await $`mkdir -p ../../node_modules/${opentui}`
44-
await $`npm pack ${opentui}@${pkg.dependencies["@opentui/core"]}`.cwd(path.join(dir, "../../node_modules"))
44+
await $`npm pack ${opentui}@${pkg.dependencies["@opentui/core"]}`.cwd(
45+
path.join(dir, "../../node_modules"),
46+
)
4547
await $`tar -xf ../../node_modules/${opentui.replace("@opentui/", "opentui-")}-*.tgz -C ../../node_modules/${opentui} --strip-components=1`
4648

4749
const watcher = `@parcel/watcher-${os === "windows" ? "win32" : os}-${arch.replace("-baseline", "")}${os === "linux" ? "-glibc" : ""}`
4850
await $`mkdir -p ../../node_modules/${watcher}`
4951
await $`npm pack ${watcher}`.cwd(path.join(dir, "../../node_modules")).quiet()
5052
await $`tar -xf ../../node_modules/${watcher.replace("@parcel/", "parcel-")}-*.tgz -C ../../node_modules/${watcher} --strip-components=1`
5153

52-
const parserWorker = fs.realpathSync(path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"))
54+
const parserWorker = fs.realpathSync(
55+
path.resolve(dir, "./node_modules/@opentui/core/parser.worker.js"),
56+
)
57+
const workerPath = "./src/cli/cmd/tui/worker.ts"
58+
5359
await Bun.build({
5460
conditions: ["browser"],
5561
tsconfig: "./tsconfig.json",
@@ -61,10 +67,11 @@ for (const [os, arch] of targets) {
6167
execArgv: [`--user-agent=opencode/${Script.version}`, `--env-file=""`, `--`],
6268
windows: {},
6369
},
64-
entrypoints: ["./src/index.ts", parserWorker, "./src/cli/cmd/tui/worker.ts"],
70+
entrypoints: ["./src/index.ts", parserWorker, workerPath],
6571
define: {
6672
OPENCODE_VERSION: `'${Script.version}'`,
6773
OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(dir, parserWorker),
74+
OPENCODE_WORKER_PATH: workerPath,
6875
OPENCODE_CHANNEL: `'${Script.channel}'`,
6976
},
7077
})

packages/opencode/src/cli/cmd/tui/thread.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { bootstrap } from "@/cli/bootstrap"
88
import path from "path"
99
import { UI } from "@/cli/ui"
1010

11+
declare global {
12+
const OPENCODE_WORKER_PATH: string
13+
}
14+
1115
export const TuiThreadCommand = cmd({
1216
command: "$0 [project]",
1317
describe: "start opencode tui",
@@ -58,13 +62,21 @@ export const TuiThreadCommand = cmd({
5862
return piped ? piped + "\n" + args.prompt : args.prompt
5963
})()
6064

61-
const cwd = args.project ? path.resolve(args.project) : process.cwd()
65+
// Resolve relative paths against PWD to preserve behavior when using --cwd flag
66+
const baseCwd = process.env.PWD ?? process.cwd()
67+
const cwd = args.project ? path.resolve(baseCwd, args.project) : process.cwd()
68+
let workerPath: string | URL = new URL("./worker.ts", import.meta.url)
69+
70+
if (typeof OPENCODE_WORKER_PATH !== "undefined") {
71+
workerPath = OPENCODE_WORKER_PATH
72+
}
6273
try {
6374
process.chdir(cwd)
6475
} catch (e) {
6576
UI.error("Failed to change directory to " + cwd)
6677
return
6778
}
79+
6880
await bootstrap(cwd, async () => {
6981
upgrade()
7082

@@ -88,7 +100,7 @@ export const TuiThreadCommand = cmd({
88100
return undefined
89101
})()
90102

91-
const worker = new Worker("./src/cli/cmd/tui/worker.ts", {
103+
const worker = new Worker(workerPath, {
92104
env: Object.fromEntries(
93105
Object.entries(process.env).filter(
94106
(entry): entry is [string, string] => entry[1] !== undefined,

0 commit comments

Comments
 (0)