Fix Agent Manager open file button for local sessions (#6544)

This commit is contained in:
Marius
2026-03-03 10:21:09 +01:00
committed by GitHub
parent 691b914260
commit 0dfff06bef
@@ -1419,20 +1419,20 @@ export class AgentManagerProvider implements vscode.Disposable {
// Diff polling
// ---------------------------------------------------------------------------
/** Open a file from a worktree session in the VS Code editor. */
/** Open a file from a worktree or local session in the VS Code editor. */
private openWorktreeFile(sessionId: string, relativePath: string): void {
const state = this.getStateManager()
if (!state) return
const session = state.getSession(sessionId)
if (!session?.worktreeId) return
const worktree = state.getWorktree(session.worktreeId)
if (!worktree) return
if (!session) return
const base = session.worktreeId ? state.getWorktree(session.worktreeId)?.path : this.getWorkspaceRoot()
if (!base) return
// Resolve real paths to prevent symlink traversal and normalize for
// consistent comparison on both Unix and Windows.
let resolved: string
try {
const root = fs.realpathSync(worktree.path)
resolved = fs.realpathSync(path.resolve(worktree.path, relativePath))
const root = fs.realpathSync(base)
resolved = fs.realpathSync(path.resolve(base, relativePath))
// Directory-boundary check: append path.sep so "/foo/bar" won't match "/foo/bar2/..."
if (resolved !== root && !resolved.startsWith(root + path.sep)) return
} catch (err) {