opencode
opencode copied to clipboard
How to debug server (worker) code?
Question
I can debug TUI code in two ways:
1 bun run --cwd packages/opencode --conditions=browser --inspect src/index.ts
--------------------- Bun Inspector ---------------------
Listening:
ws://localhost:6499/arzcsfu03h5
Inspect in browser:
https://debug.bun.sh/#localhost:6499/arzcsfu03h5
--------------------- Bun Inspector ---------------------
2 bun run --cwd packages/opencode --conditions=browser src/index.ts in "JavaScript Debug Terminal" in VsCode
However, I don't know how to debug the code in worker.js (/packages/opencode/src/cli/cmd/tui/worker.ts) because the server runs in a separate thread.
What's the recommended method for debugging the server code?
I found a solution to debug server code:
run bun run --cwd packages/opencode --conditions=browser src/index.ts serve --port 4096 --cors in "JavaScript Debug Terminal" in VsCode
bun run --cwd packages/opencode --conditions=browser src/index.ts serve --port 4096 --cors
Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.
opencode server listening on http://127.0.0.1:4096
then use web ui in browser ( http://127.0.0.1:4096 ) as frontend