Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/opencode/src/acp/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ export function contentBlockToParts(block: ContentBlock): PromptPart[] {

case "resource":
if ("text" in block.resource) {
return [{ type: "text", text: block.resource.text }]
const { uri, text } = block.resource
let source = uri
try {
if (uri.startsWith("zed://")) {
source = new URL(uri).searchParams.get("path") ?? uri
} else if (uri.startsWith("file://")) {
const u = new URL(uri)
source = u.pathname + u.hash
}
} catch {
// keep uri as-is
}
return [{ type: "text", text: `${source}\n${text}` }]
}
if (block.resource.mimeType) {
return [
Expand Down
28 changes: 26 additions & 2 deletions packages/opencode/test/acp/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("acp content conversion", () => {
])
})

test("resource with text becomes a text part", () => {
test("resource with text includes file path prefix so LLM knows the source", () => {
expect(
contentBlockToParts({
type: "resource",
Expand All @@ -109,7 +109,31 @@ describe("acp content conversion", () => {
text: "context",
},
}),
).toEqual([{ type: "text", text: "context" }])
).toEqual([{ type: "text", text: "/tmp/context.txt\ncontext" }])
})

test("resource with zed:// uri decodes path for the prefix", () => {
expect(
contentBlockToParts({
type: "resource",
resource: {
uri: "zed://workspace?path=/home/user/project/src/main.ts",
text: "export function main() {}",
},
}),
).toEqual([{ type: "text", text: "/home/user/project/src/main.ts\nexport function main() {}" }])
})

test("resource with file:// uri preserves line-range fragment in prefix", () => {
expect(
contentBlockToParts({
type: "resource",
resource: {
uri: "file:///src/app.ts#L10-L20",
text: "const x = 1",
},
}),
).toEqual([{ type: "text", text: "/src/app.ts#L10-L20\nconst x = 1" }])
})

test("resource with blob and mimeType becomes a data URL file part", () => {
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/components/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const VIRTUALIZE_BYTES = 500_000
const codeMetrics = {
...DEFAULT_VIRTUAL_FILE_METRICS,
lineHeight: 24,
spacing: 0,
} satisfies Partial<VirtualFileMetrics>

type SharedProps<T> = {
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/pierre/virtualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const cache = new WeakMap<Document | HTMLElement, Entry>()
export const virtualMetrics: Partial<VirtualFileMetrics> = {
lineHeight: 24,
hunkSeparatorHeight: 24,
spacing: 0,
}

function scrollable(value: string) {
Expand Down
Loading