-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Bug
When using opencode attach to connect to a remote OpenCode server, selecting a file via @ mention in the TUI builds a file://... URL using the client machine's process.cwd() (local path), not the remote server's working directory.
This causes the server to resolve the URL on the remote filesystem and try to read a path that only exists on the client (e.g. a macOS path), so the attachment fails / the wrong file is read.
Environment
- OpenCode CLI: 1.2.4
- Client: macOS
- Server: Linux (remote OpenCode server)
Steps to reproduce
- Start an OpenCode server on a remote machine (e.g.
opencode serve). - On the client machine, run:
opencode attach http://<remote-host>:4096 --dir /path/to/project(or attach to a server already running in that project). - In the TUI prompt, type
@and select any file from autocomplete.
Actual
The inserted part uses a file:// URL based on the client's process.cwd() (local path). The server then resolves that URL and tries to read it on the remote filesystem, resulting in file-not-found / incorrect file content.
Expected
@ file mentions during remote attach should resolve against the remote server directory (e.g. the directory returned by path.get() / sync.data.path.directory, or the directory provided via --dir).
Likely cause
packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx currently does:
const fullPath = `${process.cwd()}/${item}`
const urlObj = pathToFileURL(fullPath)When attached, process.cwd() is client-local.
Suggested fix
Use the remote directory from sync (e.g. sync.data.path.directory, sourced from sdk.client.path.get()) as the base directory for pathToFileURL, with a fallback to process.cwd() for local mode.
Example:
const baseDir = (sync.data.path.directory || process.cwd()).replace(/\/+$/, "")
const fullPath = item.startsWith("/") ? item : `${baseDir}/${item}`
const urlObj = pathToFileURL(fullPath)