summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/app/src/components')
-rw-r--r--packages/app/src/components/file-tree.tsx11
-rw-r--r--packages/app/src/components/prompt-input/build-request-parts.test.ts4
-rw-r--r--packages/app/src/components/prompt-input/build-request-parts.ts23
3 files changed, 13 insertions, 25 deletions
diff --git a/packages/app/src/components/file-tree.tsx b/packages/app/src/components/file-tree.tsx
index 4a3e27672..d7b729973 100644
--- a/packages/app/src/components/file-tree.tsx
+++ b/packages/app/src/components/file-tree.tsx
@@ -1,4 +1,5 @@
import { useFile } from "@/context/file"
+import { encodeFilePath } from "@/context/file/path"
import { Collapsible } from "@opencode-ai/ui/collapsible"
import { FileIcon } from "@opencode-ai/ui/file-icon"
import { Icon } from "@opencode-ai/ui/icon"
@@ -20,11 +21,7 @@ import { Dynamic } from "solid-js/web"
import type { FileNode } from "@opencode-ai/sdk/v2"
function pathToFileUrl(filepath: string): string {
- const encodedPath = filepath
- .split("/")
- .map((segment) => encodeURIComponent(segment))
- .join("/")
- return `file://${encodedPath}`
+ return `file://${encodeFilePath(filepath)}`
}
type Kind = "add" | "del" | "mix"
@@ -223,12 +220,14 @@ export default function FileTree(props: {
seen.add(item)
}
- return out.toSorted((a, b) => {
+ out.sort((a, b) => {
if (a.type !== b.type) {
return a.type === "directory" ? -1 : 1
}
return a.name.localeCompare(b.name)
})
+
+ return out
})
const Node = (
diff --git a/packages/app/src/components/prompt-input/build-request-parts.test.ts b/packages/app/src/components/prompt-input/build-request-parts.test.ts
index b0fd3a050..72bdecc01 100644
--- a/packages/app/src/components/prompt-input/build-request-parts.test.ts
+++ b/packages/app/src/components/prompt-input/build-request-parts.test.ts
@@ -112,7 +112,7 @@ describe("buildRequestParts", () => {
// Special chars should be encoded
expect(filePart.url).toContain("file%23name.txt")
// Should have Windows drive letter properly encoded
- expect(filePart.url).toMatch(/file:\/\/\/[A-Z]%3A/)
+ expect(filePart.url).toMatch(/file:\/\/\/[A-Z]:/)
}
})
@@ -210,7 +210,7 @@ describe("buildRequestParts", () => {
if (filePart?.type === "file") {
// Should handle absolute path that differs from sessionDirectory
expect(() => new URL(filePart.url)).not.toThrow()
- expect(filePart.url).toContain("/D%3A/other/project/file.ts")
+ expect(filePart.url).toContain("/D:/other/project/file.ts")
}
})
diff --git a/packages/app/src/components/prompt-input/build-request-parts.ts b/packages/app/src/components/prompt-input/build-request-parts.ts
index 11aec9631..0cc54dc2b 100644
--- a/packages/app/src/components/prompt-input/build-request-parts.ts
+++ b/packages/app/src/components/prompt-input/build-request-parts.ts
@@ -1,6 +1,7 @@
import { getFilename } from "@opencode-ai/util/path"
import { type AgentPartInput, type FilePartInput, type Part, type TextPartInput } from "@opencode-ai/sdk/v2/client"
import type { FileSelection } from "@/context/file"
+import { encodeFilePath } from "@/context/file/path"
import type { AgentPart, FileAttachmentPart, ImageAttachmentPart, Prompt } from "@/context/prompt"
import { Identifier } from "@/utils/id"
@@ -27,23 +28,11 @@ type BuildRequestPartsInput = {
sessionDirectory: string
}
-const absolute = (directory: string, path: string) =>
- path.startsWith("/") ? path : (directory + "/" + path).replace("//", "/")
-
-const encodeFilePath = (filepath: string): string => {
- // Normalize Windows paths: convert backslashes to forward slashes
- let normalized = filepath.replace(/\\/g, "/")
-
- // Handle Windows absolute paths (D:/path -> /D:/path for proper file:// URLs)
- if (/^[A-Za-z]:/.test(normalized)) {
- normalized = "/" + normalized
- }
-
- // Encode each path segment (preserving forward slashes as path separators)
- return normalized
- .split("/")
- .map((segment) => encodeURIComponent(segment))
- .join("/")
+const absolute = (directory: string, path: string) => {
+ if (path.startsWith("/")) return path
+ if (/^[A-Za-z]:[\\/]/.test(path) || /^[A-Za-z]:$/.test(path)) return path
+ if (path.startsWith("\\\\") || path.startsWith("//")) return path
+ return `${directory.replace(/[\\/]+$/, "")}/${path}`
}
const fileQuery = (selection: FileSelection | undefined) =>