summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-07-10 11:19:54 -0500
committerGitHub <[email protected]>2025-07-10 11:19:54 -0500
commit8b2a909e1f29b7c024d70b6eb5da7d73e9307941 (patch)
tree52a2243d7c0c38e9cd9af251e3a341dd3530b68e
parente9c954d45e0417f2633f2f627a2ceee08db6b4c2 (diff)
downloadopencode-8b2a909e1f29b7c024d70b6eb5da7d73e9307941.tar.gz
opencode-8b2a909e1f29b7c024d70b6eb5da7d73e9307941.zip
fix: encode & decode file paths (#843)
-rw-r--r--packages/opencode/src/session/index.ts6
-rw-r--r--packages/tui/internal/components/chat/editor.go3
2 files changed, 6 insertions, 3 deletions
diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts
index d49726d84..6ca120512 100644
--- a/packages/opencode/src/session/index.ts
+++ b/packages/opencode/src/session/index.ts
@@ -350,7 +350,9 @@ export namespace Session {
switch (url.protocol) {
case "file:":
// have to normalize, symbol search returns absolute paths
- const relativePath = url.pathname.replace(app.path.cwd, ".")
+ // Decode the pathname since URL constructor doesn't automatically decode it
+ const pathname = decodeURIComponent(url.pathname)
+ const relativePath = pathname.replace(app.path.cwd, ".")
const filePath = path.join(app.path.cwd, relativePath)
if (part.mime === "text/plain") {
@@ -414,7 +416,7 @@ export namespace Session {
return [
{
type: "text",
- text: `Called the Read tool with the following input: {\"filePath\":\"${url.pathname}\"}`,
+ text: `Called the Read tool with the following input: {\"filePath\":\"${pathname}\"}`,
synthetic: true,
},
{
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go
index 3bf11b231..2ed2a9079 100644
--- a/packages/tui/internal/components/chat/editor.go
+++ b/packages/tui/internal/components/chat/editor.go
@@ -4,6 +4,7 @@ import (
"encoding/base64"
"fmt"
"log/slog"
+ "net/url"
"os"
"path/filepath"
"strconv"
@@ -180,7 +181,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
attachment := &textarea.Attachment{
ID: uuid.NewString(),
Display: "@" + filePath,
- URL: fmt.Sprintf("file://./%s", filePath),
+ URL: fmt.Sprintf("file://./%s", url.PathEscape(filePath)),
Filename: filePath,
MediaType: mediaType,
}