Skip to content

Commit 9c46c39

Browse files
committed
fix: show absolute path for files outside project directory
1 parent 4d2e62c commit 9c46c39

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

packages/opencode/src/tool/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const EditTool = Tool.define("edit", {
167167
diff,
168168
filediff,
169169
},
170-
title: `${path.relative(Instance.worktree, filePath)}`,
170+
title: Filesystem.displayPath(Instance.worktree, filePath),
171171
output,
172172
}
173173
},

packages/opencode/src/tool/patch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const PatchTool = Tool.define("patch", {
219219
}
220220

221221
// Generate output summary
222-
const relativePaths = changedFiles.map((filePath) => path.relative(Instance.worktree, filePath))
222+
const relativePaths = changedFiles.map((filePath) => Filesystem.displayPath(Instance.worktree, filePath))
223223
const summary = `${fileChanges.length} files changed`
224224

225225
return {

packages/opencode/src/tool/read.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const ReadTool = Tool.define("read", {
2727
if (!path.isAbsolute(filepath)) {
2828
filepath = path.join(process.cwd(), filepath)
2929
}
30-
const title = path.relative(Instance.worktree, filepath)
30+
const title = Filesystem.displayPath(Instance.worktree, filepath)
3131
const agent = await Agent.get(ctx.agent)
3232

3333
if (!ctx.extra?.["bypassCwdCheck"] && !Filesystem.isAllowedPath(Instance.directory, filepath)) {

packages/opencode/src/tool/write.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const WriteTool = Tool.define("write", {
8787
}
8888

8989
return {
90-
title: path.relative(Instance.worktree, filepath),
90+
title: Filesystem.displayPath(Instance.worktree, filepath),
9191
metadata: {
9292
diagnostics,
9393
filepath,

packages/opencode/src/util/filesystem.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export namespace Filesystem {
3232
return !relative(parent, child).startsWith("..")
3333
}
3434

35+
export function displayPath(projectDir: string, filepath: string) {
36+
if (contains(projectDir, filepath)) return relative(projectDir, filepath)
37+
return filepath
38+
}
39+
3540
export async function findUp(target: string, start: string, stop?: string) {
3641
let current = start
3742
const result = []

0 commit comments

Comments
 (0)