Skip to content

Commit b18b646

Browse files
authored
fix: attachment bugs (anomalyco#1335)
1 parent 9741a67 commit b18b646

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

packages/opencode/src/session/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,7 @@ export namespace Session {
419419
case "file:":
420420
// have to normalize, symbol search returns absolute paths
421421
// Decode the pathname since URL constructor doesn't automatically decode it
422-
const pathname = decodeURIComponent(url.pathname)
423-
const relativePath = pathname.replace(app.path.cwd, ".")
424-
const filePath = path.join(app.path.cwd, relativePath)
422+
const filePath = decodeURIComponent(url.pathname)
425423

426424
if (part.mime === "text/plain") {
427425
let offset: number | undefined = undefined
@@ -501,7 +499,7 @@ export namespace Session {
501499
messageID: userMsg.id,
502500
sessionID: input.sessionID,
503501
type: "text",
504-
text: `Called the Read tool with the following input: {\"filePath\":\"${pathname}\"}`,
502+
text: `Called the Read tool with the following input: {\"filePath\":\"${filePath}\"}`,
505503
synthetic: true,
506504
},
507505
{

packages/tui/internal/components/chat/editor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/base64"
55
"fmt"
66
"log/slog"
7-
"net/url"
87
"os"
98
"path/filepath"
109
"strconv"
@@ -732,7 +731,7 @@ func (m *editorComponent) createAttachmentFromFile(filePath string) *attachment.
732731
ID: uuid.NewString(),
733732
Type: "file",
734733
Display: "@" + filePath,
735-
URL: fmt.Sprintf("file://./%s", filePath),
734+
URL: fmt.Sprintf("file://%s", absolutePath),
736735
Filename: filePath,
737736
MediaType: mediaType,
738737
Source: &attachment.FileSource{
@@ -783,7 +782,7 @@ func (m *editorComponent) createAttachmentFromPath(filePath string) *attachment.
783782
ID: uuid.NewString(),
784783
Type: "file",
785784
Display: "@" + filePath,
786-
URL: fmt.Sprintf("file://./%s", url.PathEscape(filePath)),
785+
URL: fmt.Sprintf("file://%s", absolutePath),
787786
Filename: filePath,
788787
MediaType: mediaType,
789788
Source: &attachment.FileSource{

0 commit comments

Comments
 (0)