From b18b646f8e50bb0d11bc57d424c3c1920ddaa657 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Sun, 27 Jul 2025 12:21:31 -0500 Subject: [PATCH] fix: attachment bugs (#1335) --- packages/opencode/src/session/index.ts | 6 ++---- packages/tui/internal/components/chat/editor.go | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 0884c658..5ad6e7da 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -419,9 +419,7 @@ export namespace Session { case "file:": // have to normalize, symbol search returns absolute paths // 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) + const filePath = decodeURIComponent(url.pathname) if (part.mime === "text/plain") { let offset: number | undefined = undefined @@ -501,7 +499,7 @@ export namespace Session { messageID: userMsg.id, sessionID: input.sessionID, type: "text", - text: `Called the Read tool with the following input: {\"filePath\":\"${pathname}\"}`, + text: `Called the Read tool with the following input: {\"filePath\":\"${filePath}\"}`, synthetic: true, }, { diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 4311a4ca..009a7ab6 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "fmt" "log/slog" - "net/url" "os" "path/filepath" "strconv" @@ -732,7 +731,7 @@ func (m *editorComponent) createAttachmentFromFile(filePath string) *attachment. ID: uuid.NewString(), Type: "file", Display: "@" + filePath, - URL: fmt.Sprintf("file://./%s", filePath), + URL: fmt.Sprintf("file://%s", absolutePath), Filename: filePath, MediaType: mediaType, Source: &attachment.FileSource{ @@ -783,7 +782,7 @@ func (m *editorComponent) createAttachmentFromPath(filePath string) *attachment. ID: uuid.NewString(), Type: "file", Display: "@" + filePath, - URL: fmt.Sprintf("file://./%s", url.PathEscape(filePath)), + URL: fmt.Sprintf("file://%s", absolutePath), Filename: filePath, MediaType: mediaType, Source: &attachment.FileSource{