Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(explorer): open folder links that lead outside the project again (#36191)
Neila17b6706f542
diff --git a/src/main/ipc/filesystem/filesystem-read-handlers.ts b/src/main/ipc/filesystem/filesystem-read-handlers.tsindex ee039362520..00b734cb4e0 100644--- a/src/main/ipc/filesystem/filesystem-read-handlers.ts+++ b/src/main/ipc/filesystem/filesystem-read-handlers.ts@@ -14,7 +14,8 @@ import { resolveRegisteredWorktreePath } from '../registered-worktree-roots-cachimport type { LocalFileAccess } from '../../../shared/local-file-access'import {resolveDesktopAuthorizedPath,- resolveLocalFileRequestPath+ resolveLocalFileRequestPath,+ resolveLocalListRequestPath} from '../local-file-access-resolution'import { isPathAbsentError } from './filesystem-path-containment'import { listMarkdownDocuments } from '../markdown-documents'@@ -48,6 +49,7 @@ export function registerFilesystemReadHandlers(context: FilesystemHandlerContextfollowSymlinks?: boolean/** A user act (open or Retry); may start a stopped WSL distro. */wakeWslDistro?: boolean+ access?: LocalFileAccess}): Promise<DirEntry[]> => {// Record throw site and redacted path shape because fs:readDir IPC errors otherwise lack context.@@ -60,14 +62,14 @@ export function registerFilesystemReadHandlers(context: FilesystemHandlerContextreturn await guardWslUncPathAccess(args.dirPath,async () => {- const dirPath = await resolveDesktopAuthorizedPath(args.dirPath, store)+ const dirPath = await resolveLocalListRequestPath(args.dirPath, args.access, store)throwSite = 'readdir'const entries = await readdir(windowsFsPath(dirPath), { withFileTypes: true })const mapped = await classifyFilesystemDirectoryEntries(args.dirPath,entries,args.followSymlinks ?? store.getSettings().followSymlinkedDirectories ?? false,- (path) => resolveDesktopAuthorizedPath(path, store)+ (path) => resolveLocalListRequestPath(path, args.access, store))return sortDirEntries(mapped)},diff --git a/src/main/ipc/local-file-access-resolution.test.ts b/src/main/ipc/local-file-access-resolution.test.tsindex 23879fe6b96..0209fd6b475 100644--- a/src/main/ipc/local-file-access-resolution.test.ts+++ b/src/main/ipc/local-file-access-resolution.test.ts@@ -9,6 +9,7 @@ import { resolveAuthorizedPath } from './filesystem/filesystem-auth'import {resolveDesktopAuthorizedPath,resolveLocalFileRequestPath,+ resolveLocalListRequestPath,resolveLocalRenamePaths,resolveLocalRequestPath,resolveLocalWriteRequestPath,@@ -51,6 +52,7 @@ function makeStore({ repoPaths = [], folderPath }: Registration): Store {}const USER_FILE = { kind: 'user-file' } as const+const PROJECT_FOLDER_LINK = { kind: 'project-folder-link' } as constconst documentResource = (documentPath: string) =>({ kind: 'document-resource', documentPath }) as constconst documentFolder = (documentPath: string) =>@@ -470,3 +472,63 @@ describe('chat-image requests', () => {})})++describe('project-folder-link listings', () => {+ beforeEach(async () => {+ await mkdir(join(outside, 'guides'))+ await symlink(outside, join(project, 'linked'), 'dir')+ })++ it('list a project folder link that leads out, and folders under it', async () => {+ const store = makeStore({ repoPaths: [project] })+ const linked = join(project, 'linked')++ await expect(resolveLocalListRequestPath(linked, undefined, store)).rejects.toThrow(+ 'outside allowed directories'+ )+ await expect(resolveLocalListRequestPath(linked, PROJECT_FOLDER_LINK, store)).resolves.toBe(+ outside+ )+ await expect(+ resolveLocalListRequestPath(join(linked, 'guides'), PROJECT_FOLDER_LINK, store)+ ).resolves.toBe(join(outside, 'guides'))+ })++ it('refuse folders not reached through a project link', async () => {+ const store = makeStore({ repoPaths: [project] })+ await mkdir(join(base, 'unregistered', 'src'), { recursive: true })++ for (const dirPath of [outside, join(base, 'unregistered', 'src')]) {+ expect(await settles(resolveLocalListRequestPath(dirPath, PROJECT_FOLDER_LINK, store))).toBe(+ 'denied'+ )+ }+ // Other access kinds never list outside folders.+ expect(+ await settles(resolveLocalListRequestPath(join(project, 'linked'), USER_FILE, store))+ ).toBe('denied')+ })++ it('refuse links in Orca floating folder, which is not a project', async () => {+ const floatingLink = join(userData.path, 'floating-workspace', 'linked')+ await symlink(outside, floatingLink, 'dir')++ expect(+ await settles(resolveLocalListRequestPath(floatingLink, PROJECT_FOLDER_LINK, makeStore({})))+ ).toBe('denied')+ })++ it('grant listing only, never file reads', async () => {+ const store = makeStore({ repoPaths: [project] })++ expect(+ await settles(+ resolveLocalFileRequestPath(+ join(project, 'linked', 'notes.txt'),+ PROJECT_FOLDER_LINK,+ store+ )+ )+ ).toBe('denied')+ })+})diff --git a/src/main/ipc/local-file-access-resolution.ts b/src/main/ipc/local-file-access-resolution.tsindex 614950efb50..07c9cac78b4 100644--- a/src/main/ipc/local-file-access-resolution.ts+++ b/src/main/ipc/local-file-access-resolution.ts@@ -17,6 +17,7 @@ import {} from './automatic-load-path-text'import { NOT_A_REGULAR_FILE_MESSAGE } from './filesystem/local-regular-file-read'import { realpathAcrossWslDriveMount, windowsFsPath } from '../wsl/wsl-unc-drive-fs-path'+import { resolveProjectFolderLinkPath } from './project-folder-link-path'const USER_FILE_NEEDS_ABSOLUTE_PATH_MESSAGE ='Access denied: a file opened by name needs an absolute path.'@@ -182,6 +183,9 @@ function parseLocalFileAccess(access: unknown): LocalFileAccess | undefined {) {return { kind: 'document-folder', documentPath: access.documentPath }}+ if (access.kind === 'project-folder-link') {+ return { kind: 'project-folder-link' }+ }if (access.kind === 'document-resource' &&'documentPath' in access &&@@ -192,7 +196,13 @@ function parseLocalFileAccess(access: unknown): LocalFileAccess | undefined {return undefined}-export type LocalRequestOperation = 'read' | 'write' | 'rename-from' | 'rename-to' | 'import-into'+export type LocalRequestOperation =+ | 'read'+ | 'list'+ | 'write'+ | 'rename-from'+ | 'rename-to'+ | 'import-into'type KindRule = (targetPath: string) => Promise<string>@@ -203,8 +213,8 @@ function declaredKindRule(): KindRule | undefined {switch (fileAccess.kind) {case 'user-file':- // Only the opened document itself receives this rename access.- return operation !== 'import-into'+ // Only the opened document itself receives rename access; listings need a project folder link.+ return operation !== 'import-into' && operation !== 'list'? async (targetPath) => resolveUserNamedLocalPath(targetPath): undefinedcase 'document-resource':@@ -219,6 +229,12 @@ function declaredKindRule(return operation === 'import-into'? (targetPath) => resolveDocumentFolderPath(targetPath, fileAccess.documentPath): undefined+ case 'project-folder-link':+ return operation === 'list'+ ? (targetPath) =>+ // Why project roots only: Orca's floating folder is not a project a link can lead out of.+ resolveProjectFolderLinkPath(targetPath, (path) => resolveAuthorizedPath(path, store))+ : undefined}}@@ -283,6 +299,15 @@ export function resolveLocalFileRequestPath(return resolveLocalRequestPath(targetPath, access, store, 'read')}+/** Folder listings accept only project-folder-link access beyond project roots. */+export function resolveLocalListRequestPath(+ targetPath: string,+ access: unknown,+ store: RuntimeStore+): Promise<string> {+ return resolveLocalRequestPath(targetPath, access, store, 'list')+}+export function resolveLocalWriteRequestPath(targetPath: string,access: unknown,diff --git a/src/main/ipc/project-folder-link-path.ts b/src/main/ipc/project-folder-link-path.tsnew file mode 100644index 00000000000..9ac6e30724a--- /dev/null+++ b/src/main/ipc/project-folder-link-path.ts@@ -0,0 +1,32 @@+import { basename, dirname, isAbsolute, join, resolve } from 'node:path'+import { lstat } from 'node:fs/promises'+import { PATH_ACCESS_DENIED_MESSAGE } from './filesystem/filesystem-auth'+import { realpathAcrossWslDriveMount, windowsFsPath } from '../wsl/wsl-unc-drive-fs-path'++/** List only folders reached through a symlink whose own folder is inside a project. */+export async function resolveProjectFolderLinkPath(+ targetPath: string,+ authorizeProjectPath: (path: string) => Promise<string>+): Promise<string> {+ if (typeof targetPath !== 'string' || !isAbsolute(targetPath)) {+ throw new Error(PATH_ACCESS_DENIED_MESSAGE)+ }+ const resolvedTarget = resolve(targetPath)+ for (+ let child = resolvedTarget, parent = dirname(child);+ parent !== child;+ child = parent, parent = dirname(parent)+ ) {+ const insideRoots = await authorizeProjectPath(parent).catch(() => undefined)+ if (insideRoots === undefined) {+ continue+ }+ // A refused ordinary folder (e.g. an unregistered root's child) is not a link out of the project.+ const entry = await lstat(windowsFsPath(join(insideRoots, basename(child))))+ if (!entry.isSymbolicLink()) {+ throw new Error(PATH_ACCESS_DENIED_MESSAGE)+ }+ return resolve(await realpathAcrossWslDriveMount(resolvedTarget))+ }+ throw new Error(PATH_ACCESS_DENIED_MESSAGE)+}diff --git a/src/preload/api/filesystem-api.ts b/src/preload/api/filesystem-api.tsindex b94cc3a5ba2..d7779947776 100644--- a/src/preload/api/filesystem-api.ts+++ b/src/preload/api/filesystem-api.ts@@ -65,6 +65,7 @@ export type FilesystemApi = {followSymlinks?: boolean/** A user act (open or Retry); may start a stopped WSL distro. */wakeWslDistro?: boolean+ access?: LocalFileAccess}) => Promise<DirEntry[]>readFile: (args: {filePath: stringdiff --git a/src/preload/api/fs-bridge.ts b/src/preload/api/fs-bridge.tsindex 644887856ab..66369593210 100644--- a/src/preload/api/fs-bridge.ts+++ b/src/preload/api/fs-bridge.ts@@ -49,6 +49,7 @@ export const fsApi = {connectionId?: stringfollowSymlinks?: booleanwakeWslDistro?: boolean+ access?: LocalFileAccess}): Promise<{ name: string; isDirectory: boolean; isSymlink: boolean }[]> =>ipcRenderer.invoke('fs:readDir', args),readFile: (args: {diff --git a/src/renderer/src/components/right-sidebar/FileExplorerRow.tsx b/src/renderer/src/components/right-sidebar/FileExplorerRow.tsxindex dc7eab106d3..7139bedd0a8 100644--- a/src/renderer/src/components/right-sidebar/FileExplorerRow.tsx+++ b/src/renderer/src/components/right-sidebar/FileExplorerRow.tsx@@ -242,6 +242,10 @@ export function FileExplorerRow({: undefined}onDoubleClick={(e) => {+ // Outside-link rows are browse-only, so their name double-click pins the preview instead.+ if (node.outsideProject) {+ return+ }// Keep icon/empty-row double-clicks available for pin preview and directory toggling.e.stopPropagation()onStartRename(node)diff --git a/src/renderer/src/components/right-sidebar/file-explorer-dir-pages.ts b/src/renderer/src/components/right-sidebar/file-explorer-dir-pages.tsindex 7d63a4ae717..2b787354a28 100644--- a/src/renderer/src/components/right-sidebar/file-explorer-dir-pages.ts+++ b/src/renderer/src/components/right-sidebar/file-explorer-dir-pages.ts@@ -35,11 +35,13 @@ export function fileExplorerListingToDirCache(dirPath,depth,worktreePath,- listing.operationOwner+ listing.operationOwner,+ listing.outsideProject === true),operationOwner: listing.operationOwner,...(listing.more ? { more: listing.more } : {}),- ...(listing.paged ? { paged: true } : {})+ ...(listing.paged ? { paged: true } : {}),+ ...(listing.outsideProject ? { outsideProject: true } : {})}}diff --git a/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.test.ts b/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.test.tsindex 96a8e7e4345..1429825522c 100644--- a/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.test.ts+++ b/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.test.ts@@ -17,8 +17,10 @@ vi.mock('./file-explorer-operation-owner', () => ({import {keepOpenedDirectoryLinks,clearFailedOpenedDirectoryLink,+ canFollowFolderLink,readFileExplorerDirectory} from './file-explorer-directory-listing'+import { fileExplorerListingToDirCache } from './file-explorer-dir-pages'import type { DirCache, TreeNode } from './file-explorer-types'describe('readFileExplorerDirectory', () => {@@ -57,6 +59,55 @@ it('forwards the WSL wake flag of a user act to the directory read', async () =>})})+describe('outside-project folder links', () => {+ it('marks a folder listed through a project link and its rows as outside the project', async () => {+ readRuntimeDirectory.mockImplementation(+ async (_context: unknown, _path: string, options: { access?: unknown }) => {+ if (!options.access) {+ throw new Error('Access denied: path resolves outside allowed directories.')+ }+ return [{ name: 'notes.md', isDirectory: false, isSymlink: false }]+ }+ )++ const listing = await readFileExplorerDirectory('wt-1', '/w', '/w/linked', {+ followProjectFolderLink: true+ })+ const cache = fileExplorerListingToDirCache(listing, '/w/linked', 0, '/w')++ expect(cache.outsideProject).toBe(true)+ expect(cache.children).toEqual([+ expect.objectContaining({ path: '/w/linked/notes.md', outsideProject: true })+ ])+ readRuntimeDirectory.mockReset()+ })++ it('follows links only on a gesture, a listed link row, or under an outside listing', () => {+ const cache: Record<string, DirCache> = {+ '/w': {+ children: [+ { name: 'src', path: '/w/src', relativePath: 'src', isDirectory: true, depth: 0 },+ {+ name: 'docs',+ path: '/w/docs',+ relativePath: 'docs',+ isDirectory: true,+ isSymlink: true,+ depth: 0+ }+ ]+ },+ '/w/linked': { children: [], outsideProject: true }+ }++ expect(canFollowFolderLink(cache, '/w/src', false)).toBe(false)+ expect(canFollowFolderLink(cache, '/w/src', true)).toBe(true)+ expect(canFollowFolderLink(cache, '/w/docs', false)).toBe(true)+ expect(canFollowFolderLink(cache, '/w/linked', false)).toBe(true)+ expect(canFollowFolderLink(cache, '/w/linked/guides', false)).toBe(true)+ })+})+describe('keepOpenedDirectoryLinks', () => {const node = (name: string, overrides: Partial<TreeNode> = {}): TreeNode => ({name,diff --git a/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.ts b/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.tsindex 7ae0f9e59db..a2495a0b16a 100644--- a/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.ts+++ b/src/renderer/src/components/right-sidebar/file-explorer-directory-listing.ts@@ -6,7 +6,7 @@ import {readRuntimeDirectoryPage,runtimeDirectoryPagesSupported} from '@/runtime/runtime-directory-page-client'-import { readRuntimeDirectory } from '@/runtime/runtime-file-mutation-client'+import { readUserOpenedDirectory } from '@/lib/user-opened-local-path'import {FILE_READ_DIR_MAX_PAGE_ENTRIES,isDirListingTooLargeForRemoteError,@@ -34,6 +34,8 @@ export type FileExplorerDirectoryListing = {operationOwner: FileExplorerOperationOwnermore?: FileExplorerDirMorepaged?: true+ /** Listed through a folder link that leads out of the project. */+ outsideProject?: true}export function fileExplorerEntriesToTreeNodes(@@ -41,7 +43,8 @@ export function fileExplorerEntriesToTreeNodes(dirPath: string,depth: number,worktreePath: string | null,- operationOwner: FileExplorerOperationOwner+ operationOwner: FileExplorerOperationOwner,+ outsideProject = false): TreeNode[] {return entries.filter(shouldIncludeFileExplorerEntry).map((entry) => {const path = joinPath(dirPath, entry.name)@@ -52,7 +55,8 @@ export function fileExplorerEntriesToTreeNodes(isDirectory: entry.isDirectory,isSymlink: entry.isSymlink,depth: depth + 1,- operationOwner+ operationOwner,+ ...(outsideProject ? { outsideProject: true as const } : {})}})}@@ -112,6 +116,26 @@ export function clearFailedOpenedDirectoryLink(return changed ? { ...cache, [parentPath]: { ...parent, children } } : cache}+/** A gesture, a listed link row, or an already-outside listing may follow a project folder link; a folder that only became a link stays refused until clicked. */+export function canFollowFolderLink(+ cache: Readonly<Record<string, DirCache>>,+ dirPath: string,+ gesture: boolean | undefined+): boolean {+ const parent = cache[parentDirForWatchPath(dirPath)]+ return (+ gesture === true ||+ cache[dirPath]?.outsideProject === true ||+ parent?.outsideProject === true ||+ parent?.children.some((child) => child.path === dirPath && child.isSymlink === true) === true+ )+}++/** Explorer-opened tabs for outside-project rows store absolute paths so they keep user-named access. */+export function fileExplorerNodeTabRelativePath(node: TreeNode): string {+ return node.outsideProject ? node.path : node.relativePath+}+/*** Lists `dirPath` whole, as always. Only a remote folder too big for one reply is listed in pages:* from just after `after` until at least `minEntries` are read, so a refresh does not shrink the tree.@@ -125,6 +149,7 @@ export async function readFileExplorerDirectory(paged?: booleanafter?: DirEntryCursorminEntries?: number+ followProjectFolderLink?: boolean} = {}): Promise<FileExplorerDirectoryListing> {const operationOwner = getFileExplorerOperationOwner(activeWorktreeId)@@ -147,8 +172,15 @@ export async function readFileExplorerDirectory(if (!options.paged && !options.after) {try {// Older remote hosts may return lexical order; adaptive sorting keeps already-sorted local listings cheap.- const whole = await readRuntimeDirectory(context, dirPath, readOptions)- return { entries: sortDirEntries(whole), operationOwner }+ const whole = await readUserOpenedDirectory(context, dirPath, {+ ...readOptions,+ ...(options.followProjectFolderLink ? { followProjectFolderLink: true } : {})+ })+ return {+ entries: sortDirEntries(whole.entries),+ operationOwner,+ ...(whole.escapesWorktree ? { outsideProject: true as const } : {})+ }} catch (error) {if (!isDirListingTooLargeForRemoteError(error) ||diff --git a/src/renderer/src/components/right-sidebar/file-explorer-row-context-menu.tsx b/src/renderer/src/components/right-sidebar/file-explorer-row-context-menu.tsxindex ea683abc421..7746d01661b 100644--- a/src/renderer/src/components/right-sidebar/file-explorer-row-context-menu.tsx+++ b/src/renderer/src/components/right-sidebar/file-explorer-row-context-menu.tsx@@ -45,6 +45,7 @@ import {shouldShowViewFileAction} from './file-explorer-row-action-visibility'import { copyFileToOsClipboard, downloadRemoteFile } from './file-explorer-row-file-transfer'+import { fileExplorerNodeTabRelativePath } from './file-explorer-directory-listing'const isMac = navigator.userAgent.includes('Mac')@@ -126,6 +127,8 @@ export function FileExplorerRowContextMenu({}))const revealBlocked = isRevealOrEditorOpenBlocked(revealOwner)+ // Why: only opened files save outside projects; main refuses tree edits under an outside folder link.+ const writesBlocked = node.outsideProject === trueconst handleOpenInOrcaBrowser = useCallback(() => {if (!activeWorktreeId) {return@@ -152,11 +155,17 @@ export function FileExplorerRowContextMenu({onPointerUpCapture={stopRightButtonMenuSelection}onCloseAutoFocus={(e) => e.preventDefault()}>- <ContextMenuItem onSelect={() => onStartNew('file', targetDir, targetDepth)}>+ <ContextMenuItem+ disabled={writesBlocked}+ onSelect={() => onStartNew('file', targetDir, targetDepth)}+ ><FilePlus />{translate('auto.components.right.sidebar.FileExplorerRow.37c875d827', 'New File')}</ContextMenuItem>- <ContextMenuItem onSelect={() => onStartNew('folder', targetDir, targetDepth)}>+ <ContextMenuItem+ disabled={writesBlocked}+ onSelect={() => onStartNew('folder', targetDir, targetDepth)}+ ><FolderPlus />{translate('auto.components.right.sidebar.FileExplorerRow.f61af83316', 'New Folder')}</ContextMenuItem>@@ -192,7 +201,7 @@ export function FileExplorerRowContextMenu({) : null}</ContextMenuItem>{!node.isDirectory && (- <ContextMenuItem onSelect={() => onDuplicate(node)}>+ <ContextMenuItem disabled={writesBlocked} onSelect={() => onDuplicate(node)}><Files />{translate('auto.components.right.sidebar.FileExplorerRow.0fec99bfd7', 'Duplicate')}</ContextMenuItem>@@ -235,7 +244,7 @@ export function FileExplorerRowContextMenu({onSelect={() =>openMarkdownPreview({filePath: node.path,- relativePath: node.relativePath,+ relativePath: fileExplorerNodeTabRelativePath(node),worktreeId: activeWorktreeId,language: 'markdown'})@@ -283,7 +292,7 @@ export function FileExplorerRowContextMenu({{revealBlocked ? <LocalOnlyMenuHint /> : null}</ContextMenuItem><ContextMenuSeparator />- <ContextMenuItem onSelect={() => onStartRename(node)}>+ <ContextMenuItem disabled={writesBlocked} onSelect={() => onStartRename(node)}><Pencil />{translate('auto.components.right.sidebar.FileExplorerRow.fc747429bf', 'Rename')}<ContextMenuShortcut>@@ -292,7 +301,7 @@ export function FileExplorerRowContextMenu({: translate('auto.components.right.sidebar.FileExplorerRow.a06551beee', 'Enter')}</ContextMenuShortcut></ContextMenuItem>- <ContextMenuItem variant="destructive" onSelect={onRequestDelete}>+ <ContextMenuItem variant="destructive" disabled={writesBlocked} onSelect={onRequestDelete}><Trash2 />{translate('auto.components.right.sidebar.FileExplorerRow.addc01145f', 'Delete')}<ContextMenuShortcut>{deleteShortcutLabel}</ContextMenuShortcut>diff --git a/src/renderer/src/components/right-sidebar/file-explorer-types.ts b/src/renderer/src/components/right-sidebar/file-explorer-types.tsindex 9c4c4ab4a91..0eff9a74d10 100644--- a/src/renderer/src/components/right-sidebar/file-explorer-types.ts+++ b/src/renderer/src/components/right-sidebar/file-explorer-types.ts@@ -16,6 +16,8 @@ export type TreeNode = {/** Inferred from an opened link, not the parent's latest host listing. */isDirectoryFromOpenedLink?: booleandepth: number+ /** Listed through a folder link that leads out of the project, so it opens by absolute path. */+ outsideProject?: true/** Host snapshot that produced this node. Destructive actions fail closed without it. */operationOwner?: FileExplorerOperationOwner}@@ -32,6 +34,8 @@ export type DirCache = {more?: FileExplorerDirMore/** Listed in pages because it is too big for one remote reply; a refresh pages straight away. */paged?: true+ /** Listed through a project folder link that leads out of the project. */+ outsideProject?: true}/** Retry covered dir reads after supersession, but not unreadable roots, which would add one dead transport timeout per dir. */diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts b/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.tsindex 314d27d78d1..d4d8f057555 100644--- a/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts+++ b/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.test.ts@@ -76,25 +76,62 @@ describe('activateFileExplorerNode', () => {expect(openFile).not.toHaveBeenCalled()})- it('does not follow a folder link that leads out of the project', async () => {- const loadDir = vi.fn()- const openFile = vi.fn()+ it('follows a folder link that leads out of the project', async () => {+ const loadDir = vi.fn().mockResolvedValue(true)+ const toggleDir = vi.fn()await activateFileExplorerNode({node: { ...symlinkNode, operationOwner: { kind: 'local' } },activeWorktreeId: 'wt-1',- openFile,- toggleDir: vi.fn(),+ openFile: vi.fn(),+ toggleDir,loadDir,statPath: vi.fn().mockResolvedValue({ isDirectory: true, escapesWorktree: true }),markPathAsDirectory: vi.fn(),setSelectedPath: vi.fn()})- expect(loadDir).not.toHaveBeenCalled()- expect(openFile).not.toHaveBeenCalled()- expect(toastError).toHaveBeenCalledWith(- "This folder links outside the project, so it can't be opened here."+ expect(loadDir).toHaveBeenCalledTimes(1)+ expect(toggleDir).toHaveBeenCalledWith('wt-1', '/repo/linked-docs')+ expect(toastError).not.toHaveBeenCalled()+ })++ it('opens a file listed through an outside folder link by its absolute path', async () => {+ const openFile = vi.fn()+ const statPath = vi.fn()+ useAppStore.setState({+ worktreesByRepo: {+ 'repo-1': [{ id: 'wt-1', repoId: 'repo-1', path: '/repo', hostId: 'local' } as never]+ }+ })++ await activateFileExplorerNode({+ node: {+ name: 'notes.md',+ path: '/repo/linked-docs/notes.md',+ relativePath: 'linked-docs/notes.md',+ isDirectory: false,+ depth: 1,+ outsideProject: true,+ operationOwner: { kind: 'local' }+ },+ activeWorktreeId: 'wt-1',+ runtimeEnvironmentId: null,+ openFile,+ toggleDir: vi.fn(),+ loadDir: vi.fn(),+ statPath,+ markPathAsDirectory: vi.fn(),+ setSelectedPath: vi.fn()+ })++ expect(statPath).not.toHaveBeenCalled()+ expect(openFile).toHaveBeenCalledWith(+ expect.objectContaining({+ filePath: '/repo/linked-docs/notes.md',+ relativePath: '/repo/linked-docs/notes.md'+ }),+ expect.anything())})diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.ts b/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.tsindex 08ef2ef1072..18c92059f73 100644--- a/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.ts+++ b/src/renderer/src/components/right-sidebar/useFileExplorerHandlers.ts@@ -12,6 +12,7 @@ import {requireMatchingFileExplorerOperationRoute} from './file-explorer-operation-owner'import { runtimeTargetEnvironmentId } from '@/runtime/runtime-client-target'+import { fileExplorerNodeTabRelativePath } from './file-explorer-directory-listing'type UseFileExplorerHandlersParams = {activeWorktreeId: string | null@@ -98,15 +99,6 @@ export async function activateFileExplorerNode(args: {// Let the editor report unresolved target errors instead of dead-ending the click.}escapesWorktree = target?.escapesWorktree === true- if (target?.isDirectory && escapesWorktree) {- toast.error(- translate(- 'auto.components.right.sidebar.useFileExplorerHandlers.folderLinksOutsideProject',- "This folder links outside the project, so it can't be opened here."- )- )- return- }if (target?.isDirectory) {// A user's expand may start a stopped WSL distro.const loadedAsDirectory = await loadDir(node.path, node.depth, {@@ -142,7 +134,7 @@ export async function activateFileExplorerNode(args: {{filePath: node.path,// Outside-project links use user-named absolute paths so reopening after restart preserves authorization.- relativePath: escapesWorktree ? node.path : node.relativePath,+ relativePath: escapesWorktree ? node.path : fileExplorerNodeTabRelativePath(node),worktreeId: activeWorktreeId,runtimeEnvironmentId: fileRuntimeEnvironmentId ?? undefined,language: detectLanguage(node.name),diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts b/src/renderer/src/components/right-sidebar/useFileExplorerKeys.tsindex bce5de974ab..c8395cb93a1 100644--- a/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts+++ b/src/renderer/src/components/right-sidebar/useFileExplorerKeys.ts@@ -216,7 +216,8 @@ export function useFileExplorerKeys(opts: {const node =(focused !== null ? rowProjectionRef.current.getRowAtIndex(focused) : null) ??selectedNodeRef.current- if (node) {+ // Rows listed through an outside folder link are browse-only; main refuses their writes.+ if (node && !node.outsideProject) {if (e.key === 'Enter' && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey) {e.preventDefault()startRenameRef.current(node)@@ -230,7 +231,9 @@ export function useFileExplorerKeys(opts: {)if (wantsDelete) {e.preventDefault()- const selectedNodes = rowProjectionRef.current.getRowsByPaths(selectedPathsRef.current)+ const selectedNodes = rowProjectionRef.current+ .getRowsByPaths(selectedPathsRef.current)+ .filter((selected) => !selected.outsideProject)requestDeleteAllRef.current(selectedNodes.length > 1 ? selectedNodes : [node])return}diff --git a/src/renderer/src/components/right-sidebar/useFileExplorerTree.ts b/src/renderer/src/components/right-sidebar/useFileExplorerTree.tsindex 236c55d3855..a13dad726e6 100644--- a/src/renderer/src/components/right-sidebar/useFileExplorerTree.ts+++ b/src/renderer/src/components/right-sidebar/useFileExplorerTree.ts@@ -10,6 +10,7 @@ import {import {keepOpenedDirectoryLinks,clearFailedOpenedDirectoryLink,+ canFollowFolderLink,readFileExplorerDirectory} from './file-explorer-directory-listing'import { fileExplorerDirDepth, fileExplorerListingToDirCache } from './file-explorer-dir-pages'@@ -53,6 +54,8 @@ type UseFileExplorerTreeResult = {}/** Owns worktree-addressed directory caches and load tokens; display scoping changes traversal rather than cache identity. */+const FOLLOW_LINK = { followProjectFolderLink: true } as const+export function useFileExplorerTree(worktreePath: string | null,expanded: Set<string>,@@ -122,7 +125,8 @@ export function useFileExplorerTree(const listing = await readFileExplorerDirectory(activeWorktreeId, worktreePath, dirPath, {wakeWslDistro: options?.wakeWslDistro,paged,- minEntries+ minEntries,+ ...(canFollowFolderLink(cache, dirPath, options?.wakeWslDistro) ? FOLLOW_LINK : {})})// Only the current read may clear loading; superseded reads must preserve their replacement’s spinner.if (!dirLoadTrackerRef.current.isCurrent(loadToken)) {@@ -253,7 +257,8 @@ export function useFileExplorerTree(readDirectory: (dirPath) =>readFileExplorerDirectory(activeWorktreeId, worktreePath, dirPath, {paged: dirCacheRef.current[dirPath]?.paged,- minEntries: dirCacheRef.current[dirPath]?.children.length+ minEntries: dirCacheRef.current[dirPath]?.children.length,+ ...(canFollowFolderLink(dirCacheRef.current, dirPath, false) ? FOLLOW_LINK : {})}),maxConcurrentReads: fileExplorerRefreshConcurrency(getFileExplorerOperationOwner(activeWorktreeId)diff --git a/src/renderer/src/i18n/locales/de.json b/src/renderer/src/i18n/locales/de.jsonindex c01f3526d13..bb87673d468 100644--- a/src/renderer/src/i18n/locales/de.json+++ b/src/renderer/src/i18n/locales/de.json@@ -14111,8 +14111,7 @@"trashFailed": "„{{name}}“ konnte nicht in den Papierkorb verschoben werden."},"useFileExplorerHandlers": {- "32cd9fd991": "Ziel des symbolischen Links kann nicht geöffnet werden",- "folderLinksOutsideProject": "Dieser Ordner verweist auf ein Ziel außerhalb des Projekts und kann daher hier nicht geöffnet werden."+ "32cd9fd991": "Ziel des symbolischen Links kann nicht geöffnet werden"},"useFileExplorerImport": {"importFailedCount_one": "Import von {{count}} Datei fehlgeschlagen.",diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.jsonindex d7e366baa09..0d6347e81b4 100644--- a/src/renderer/src/i18n/locales/en.json+++ b/src/renderer/src/i18n/locales/en.json@@ -14516,8 +14516,7 @@"permanentlyDeleteItems_one": "Permanently delete {{count}} item?"},"useFileExplorerHandlers": {- "32cd9fd991": "Cannot open symlink target",- "folderLinksOutsideProject": "This folder links outside the project, so it can't be opened here."+ "32cd9fd991": "Cannot open symlink target"},"useFileExplorerImport": {"importFailedCount_one": "Failed to import {{count}} file.",diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.jsonindex 900b4ce78a6..932ac34747a 100644--- a/src/renderer/src/i18n/locales/es.json+++ b/src/renderer/src/i18n/locales/es.json@@ -14101,8 +14101,7 @@"trashFailed": "No se pudo mover '{{name}}' a la Papelera."},"useFileExplorerHandlers": {- "32cd9fd991": "No se puede abrir el destino del enlace simbólico",- "folderLinksOutsideProject": "Esta carpeta enlaza fuera del proyecto, así que no se puede abrir aquí."+ "32cd9fd991": "No se puede abrir el destino del enlace simbólico"},"useFileExplorerImport": {"importFailedCount_one": "No se pudo importar {{count}} archivo.",diff --git a/src/renderer/src/i18n/locales/fr.json b/src/renderer/src/i18n/locales/fr.jsonindex 115f7153b92..384706ccebe 100644--- a/src/renderer/src/i18n/locales/fr.json+++ b/src/renderer/src/i18n/locales/fr.json@@ -14325,8 +14325,7 @@"trashFailed": "Impossible de déplacer « {{name}} » vers la Corbeille."},"useFileExplorerHandlers": {- "32cd9fd991": "Impossible d'ouvrir la cible du symlink",- "folderLinksOutsideProject": "Ce dossier pointe en dehors du projet ; il ne peut pas être ouvert ici."+ "32cd9fd991": "Impossible d'ouvrir la cible du symlink"},"useFileExplorerImport": {"importFailedCount_one": "Échec de l'importation de {{count}} fichier.",diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.jsonindex 2beea7b418e..92d3898fbb1 100644--- a/src/renderer/src/i18n/locales/ja.json+++ b/src/renderer/src/i18n/locales/ja.json@@ -13747,8 +13747,7 @@"trashFailed": "「{{name}}」をごみ箱に移動できませんでした。"},"useFileExplorerHandlers": {- "32cd9fd991": "シンボリックリンクターゲットを開けません",- "folderLinksOutsideProject": "このフォルダーはプロジェクト外へのリンクのため、ここでは開けません。"+ "32cd9fd991": "シンボリックリンクターゲットを開けません"},"useFileExplorerImport": {"importFailedCount_other": "{{count}} 個のファイルのインポートに失敗しました。",diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.jsonindex e387027fbc4..89218372bd4 100644--- a/src/renderer/src/i18n/locales/ko.json+++ b/src/renderer/src/i18n/locales/ko.json@@ -13747,8 +13747,7 @@"trashFailed": "'{{name}}'을(를) 휴지통으로 이동하지 못했습니다."},"useFileExplorerHandlers": {- "32cd9fd991": "심볼릭 링크 대상을 열 수 없습니다",- "folderLinksOutsideProject": "이 폴더는 프로젝트 외부로 연결되어 있어 여기에서 열 수 없습니다."+ "32cd9fd991": "심볼릭 링크 대상을 열 수 없습니다"},"useFileExplorerImport": {"importFailedCount_other": "파일 {{count}}개를 가져오지 못했습니다.",diff --git a/src/renderer/src/i18n/locales/pt.json b/src/renderer/src/i18n/locales/pt.jsonindex 074f5c7d449..e3ac3f9d94d 100644--- a/src/renderer/src/i18n/locales/pt.json+++ b/src/renderer/src/i18n/locales/pt.json@@ -10828,8 +10828,7 @@"unresolved": "Não foi possível determinar qual host possui este espaço de trabalho. Verifique a conexão e tente novamente."},"useFileExplorerHandlers": {- "32cd9fd991": "Não é possível abrir o destino do link simbólico",- "folderLinksOutsideProject": "Esta pasta aponta para fora do projeto, então não pode ser aberta aqui."+ "32cd9fd991": "Não é possível abrir o destino do link simbólico"},"useFileExplorerKeys": {"8adb953095": "Falha na operação"diff --git a/src/renderer/src/i18n/locales/ru.json b/src/renderer/src/i18n/locales/ru.jsonindex fda2f5a4267..6c3defe7293 100644--- a/src/renderer/src/i18n/locales/ru.json+++ b/src/renderer/src/i18n/locales/ru.json@@ -14539,8 +14539,7 @@"permanentlyDeleteItems_many": "Безвозвратно удалить {{count}} элементов?"},"useFileExplorerHandlers": {- "32cd9fd991": "Не удалось открыть цель символической ссылки",- "folderLinksOutsideProject": "Эта папка ссылается за пределы проекта, поэтому её нельзя открыть здесь."+ "32cd9fd991": "Не удалось открыть цель символической ссылки"},"useFileExplorerImport": {"importFailedCount_one": "Не удалось импортировать {{count}} файл.",diff --git a/src/renderer/src/i18n/locales/tr.json b/src/renderer/src/i18n/locales/tr.jsonindex f16139f160c..de6b24466b1 100644--- a/src/renderer/src/i18n/locales/tr.json+++ b/src/renderer/src/i18n/locales/tr.json@@ -14097,8 +14097,7 @@"trashFailed": "'{{name}}' çöp kutusuna taşınamadı."},"useFileExplorerHandlers": {- "32cd9fd991": "Sembolik bağlantı hedefi açılamıyor",- "folderLinksOutsideProject": "Bu klasör proje dışına bağlantı verdiği için burada açılamıyor."+ "32cd9fd991": "Sembolik bağlantı hedefi açılamıyor"},"useFileExplorerImport": {"importFailedCount_other": "{{count}} dosya içe aktarılamadı.",diff --git a/src/renderer/src/i18n/locales/zh-Hant.json b/src/renderer/src/i18n/locales/zh-Hant.jsonindex 01437e38e09..2395e9f1591 100644--- a/src/renderer/src/i18n/locales/zh-Hant.json+++ b/src/renderer/src/i18n/locales/zh-Hant.json@@ -13916,8 +13916,7 @@"trashFailed": "無法將「{{name}}」移至垃圾桶。"},"useFileExplorerHandlers": {- "32cd9fd991": "無法開啟符號連結目標",- "folderLinksOutsideProject": "此資料夾連結到專案之外,無法在此開啟。"+ "32cd9fd991": "無法開啟符號連結目標"},"useFileExplorerImport": {"importFailedCount_other": "無法匯入 {{count}} 個檔案。",diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.jsonindex 017a84faa7f..ad189e0ed99 100644--- a/src/renderer/src/i18n/locales/zh.json+++ b/src/renderer/src/i18n/locales/zh.json@@ -13747,8 +13747,7 @@"trashFailed": "无法将“{{name}}”移到废纸篓。"},"useFileExplorerHandlers": {- "32cd9fd991": "无法打开符号链接目标",- "folderLinksOutsideProject": "此文件夹链接到项目之外,无法在此打开。"+ "32cd9fd991": "无法打开符号链接目标"},"useFileExplorerImport": {"importFailedCount_other": "无法导入 {{count}} 个文件。",diff --git a/src/renderer/src/lib/local-file-access.ts b/src/renderer/src/lib/local-file-access.tsindex d7b21d7defd..505a2254cd7 100644--- a/src/renderer/src/lib/local-file-access.ts+++ b/src/renderer/src/lib/local-file-access.ts@@ -7,12 +7,18 @@ import type { WorktreeRuntimeOwnerState } from './worktree-runtime-owner-state'const USER_FILE_ACCESS: LocalFileAccess = { kind: 'user-file' }const CHAT_IMAGE_ACCESS: LocalFileAccess = { kind: 'chat-image' }+const PROJECT_FOLDER_LINK_ACCESS: LocalFileAccess = { kind: 'project-folder-link' }/** For a path the user named by a gesture (click, drop, typed path); never for document content. */export function userNamedFileAccess(): LocalFileAccess {return USER_FILE_ACCESS}+/** List a folder reached through a project symlink that leads outside; main verifies the link. */+export function projectFolderLinkAccess(): LocalFileAccess {+ return PROJECT_FOLDER_LINK_ACCESS+}+/** Read content-referenced local images by actual type; main refuses network shares even without a user gesture. */export function chatImageAccess(): LocalFileAccess {return CHAT_IMAGE_ACCESSdiff --git a/src/renderer/src/lib/user-opened-local-path.test.ts b/src/renderer/src/lib/user-opened-local-path.test.tsindex f5665def7c4..b8cc7422cf0 100644--- a/src/renderer/src/lib/user-opened-local-path.test.ts+++ b/src/renderer/src/lib/user-opened-local-path.test.ts@@ -13,14 +13,17 @@ vi.mock('@/lib/connection-context', () => ({getConnectionIdForFile: boundaryMocks.getConnectionIdForFile}))-const mocks = vi.hoisted(() => ({ statRuntimePath: vi.fn() }))+const mocks = vi.hoisted(() => ({ statRuntimePath: vi.fn(), readRuntimeDirectory: vi.fn() }))vi.mock('@/runtime/runtime-file-routing', () => ({ isRemoteRuntimeFileOperation: () => false }))vi.mock('@/runtime/runtime-file-metadata-client', () => ({statRuntimePath: mocks.statRuntimePath}))+vi.mock('@/runtime/runtime-file-mutation-client', () => ({+ readRuntimeDirectory: mocks.readRuntimeDirectory+}))-import { statUserOpenedPath } from './user-opened-local-path'+import { readUserOpenedDirectory, statUserOpenedPath } from './user-opened-local-path'const project: RuntimeFileOperationArgs = {target: { kind: 'local' as const },@@ -127,3 +130,60 @@ describe('statUserOpenedPath', () => {)})})++describe('readUserOpenedDirectory', () => {+ const OUTSIDE = 'Access denied: path resolves outside allowed directories.'+ const entries = [{ name: 'notes.md', isDirectory: false, isSymlink: false }]+ const FOLLOW = { followProjectFolderLink: true }++ /** Main's answers: contained listings refuse; a project-folder-link listing answers `linkAnswer`. */+ function answerList(containedError: Error, linkAnswer: Error | typeof entries): void {+ mocks.readRuntimeDirectory.mockImplementation(+ async (_context: unknown, _path: string, options: { access?: unknown }) => {+ if (!options.access) {+ throw containedError+ }+ if (linkAnswer instanceof Error) {+ throw linkAnswer+ }+ return linkAnswer+ }+ )+ }++ beforeEach(() => {+ mocks.readRuntimeDirectory.mockReset()+ })++ it('lists a project folder link that leads outside as one', async () => {+ answerList(new Error(OUTSIDE), entries)++ await expect(readUserOpenedDirectory(project, '/repo/linked', FOLLOW)).resolves.toEqual({+ entries,+ escapesWorktree: true+ })+ expect(mocks.readRuntimeDirectory).toHaveBeenLastCalledWith(project, '/repo/linked', {+ access: { kind: 'project-folder-link' }+ })+ })++ it('never follows a link unless the caller allows it', async () => {+ answerList(new Error(OUTSIDE), entries)++ await expect(readUserOpenedDirectory(project, '/repo/linked', {})).rejects.toThrow(OUTSIDE)+ })++ it('keeps other failures and paths outside the project as they are', async () => {+ answerList(new Error('ENOENT: no such directory'), entries)+ await expect(readUserOpenedDirectory(project, '/repo/gone', FOLLOW)).rejects.toThrow('ENOENT')++ answerList(new Error(OUTSIDE), entries)+ await expect(readUserOpenedDirectory(project, '/elsewhere', FOLLOW)).rejects.toThrow(OUTSIDE)+ })++ it('shows why a link target cannot be listed', async () => {+ answerList(new Error(OUTSIDE), new Error('EPERM: operation not permitted'))++ await expect(readUserOpenedDirectory(project, '/repo/linked', FOLLOW)).rejects.toThrow('EPERM')+ })+})diff --git a/src/renderer/src/lib/user-opened-local-path.ts b/src/renderer/src/lib/user-opened-local-path.tsindex 31d6bda0729..0f861fb0c5d 100644--- a/src/renderer/src/lib/user-opened-local-path.ts+++ b/src/renderer/src/lib/user-opened-local-path.ts@@ -2,9 +2,11 @@ import { FLOATING_TERMINAL_WORKTREE_ID } from '../../../shared/constants'import { isPathOutsideAllowedDirectoriesError } from '../../../shared/local-file-access'import { isRemoteRuntimeFileOperation } from '@/runtime/runtime-file-routing'import { statRuntimePath } from '@/runtime/runtime-file-metadata-client'+import { readRuntimeDirectory } from '@/runtime/runtime-file-mutation-client'import type { RuntimeFileOperationArgs } from '@/runtime/runtime-file-client-types'-import { userNamedFileAccess } from './local-file-access'+import { projectFolderLinkAccess, userNamedFileAccess } from './local-file-access'import { isPathInsideWorktree } from '../../../shared/terminal-links'+import type { DirEntry } from '../../../shared/filesystem-entry-types'export type UserOpenedPathStat = {isDirectory: boolean@@ -15,18 +17,22 @@ export type UserOpenedPathStat = {// Opening a path is a user act, so its stat may start a stopped WSL distro.const USER_ACT = { wakeWslDistro: true }-/** Stat user-opened local paths inside the project boundary first. If only user-named access succeeds, open externally: symlinks can lead outside despite lexical containment. */-export async function statUserOpenedPath(- context: RuntimeFileOperationArgs,- filePath: string-): Promise<UserOpenedPathStat> {+function isInsideLocalWorktree(context: RuntimeFileOperationArgs, filePath: string): boolean {// Why the floating workspace is skipped: its folder (~ by default) is not a project root.- const insideLocalWorktree =+ return (context.worktreeId !== FLOATING_TERMINAL_WORKTREE_ID &&!context.connectionId &&!isRemoteRuntimeFileOperation(context, filePath) &&Boolean(context.worktreePath && isPathInsideWorktree(filePath, context.worktreePath))- if (!insideLocalWorktree) {+ )+}++/** Stat user-opened local paths inside the project boundary first. If only user-named access succeeds, open externally: symlinks can lead outside despite lexical containment. */+export async function statUserOpenedPath(+ context: RuntimeFileOperationArgs,+ filePath: string+): Promise<UserOpenedPathStat> {+ if (!isInsideLocalWorktree(context, filePath)) {const stat = await statRuntimePath(context, filePath, userNamedFileAccess(), USER_ACT)return { isDirectory: stat.isDirectory, escapesWorktree: false }}@@ -47,3 +53,36 @@ export async function statUserOpenedPath(return { isDirectory: stat.isDirectory, escapesWorktree: true }}}++/** List a project folder contained first; with `followProjectFolderLink`, a refusal as outside retries as a project folder link. */+export async function readUserOpenedDirectory(+ context: RuntimeFileOperationArgs,+ dirPath: string,+ options: { followSymlinks?: boolean; wakeWslDistro?: boolean; followProjectFolderLink?: boolean }+): Promise<{ entries: DirEntry[]; escapesWorktree: boolean }> {+ const { followProjectFolderLink, ...readOptions } = options+ try {+ return {+ entries: await readRuntimeDirectory(context, dirPath, readOptions),+ escapesWorktree: false+ }+ } catch (containedError) {+ if (+ !followProjectFolderLink ||+ !isPathOutsideAllowedDirectoriesError(containedError) ||+ !isInsideLocalWorktree(context, dirPath)+ ) {+ throw containedError+ }+ try {+ const entries = await readRuntimeDirectory(context, dirPath, {+ ...readOptions,+ access: projectFolderLinkAccess()+ })+ return { entries, escapesWorktree: true }+ } catch (linkError) {+ // Why: a non-link refusal keeps its original error; a real link failure (EPERM, ENOENT) shows its own.+ throw isPathOutsideAllowedDirectoriesError(linkError) ? containedError : linkError+ }+ }+}diff --git a/src/renderer/src/runtime/runtime-file-mutation-client.ts b/src/renderer/src/runtime/runtime-file-mutation-client.tsindex c84baf02104..06e83139754 100644--- a/src/renderer/src/runtime/runtime-file-mutation-client.ts+++ b/src/renderer/src/runtime/runtime-file-mutation-client.ts@@ -48,7 +48,11 @@ export function assertRemoteWriteFitsOneRequest(content: string): void {export async function readRuntimeDirectory(context: RuntimeFileOperationArgs,dirPath: string,- { wakeWslDistro, ...options }: { followSymlinks?: boolean; wakeWslDistro?: boolean } = {}+ {+ wakeWslDistro,+ access,+ ...options+ }: { followSymlinks?: boolean; wakeWslDistro?: boolean; access?: LocalFileAccess } = {}): Promise<DirEntry[]> {const remoteArgs = getRemoteFileArgs(context, dirPath)if (!remoteArgs) {@@ -57,7 +61,8 @@ export async function readRuntimeDirectory(dirPath,connectionId: context.connectionId,...options,- ...(wakeWslDistro ? { wakeWslDistro } : {})+ ...(wakeWslDistro ? { wakeWslDistro } : {}),+ ...(access ? { access } : {})})}return callRuntimeRpc<DirEntry[]>(diff --git a/src/shared/local-file-access.ts b/src/shared/local-file-access.tsindex a9653624d58..5f2d176bbdd 100644--- a/src/shared/local-file-access.ts+++ b/src/shared/local-file-access.ts@@ -8,6 +8,8 @@ export type LocalFileAccess =| { kind: 'chat-image' }/** A document the user opened: renaming it to any path, or adding files in its own folder. */| { kind: 'document-folder'; documentPath: string }+ /** A folder listed through a symlink inside a project that leads out of it; listing only. */+ | { kind: 'project-folder-link' }/** Main's refusal of a request that resolves outside every root it may serve. */export const PATH_OUTSIDE_ALLOWED_DIRECTORIES =