From c7a2e7d37620c075f6459b49c5cb37a451b9283b Mon Sep 17 00:00:00 2001 From: puzhen <1303385763@qq.com> Date: Mon, 20 Oct 2025 17:20:07 +0100 Subject: [PATCH] update --- electron/main/fileReader.ts | 21 ++++++++++++--------- src/components/Folder/index.tsx | 13 ++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/electron/main/fileReader.ts b/electron/main/fileReader.ts index bf315d409..82905e383 100644 --- a/electron/main/fileReader.ts +++ b/electron/main/fileReader.ts @@ -832,15 +832,18 @@ export class FileReader { if (stats.isDirectory()) { const taskId = taskDir.replace('task_', ''); const taskFiles = this.getFilesRecursive(taskPath, taskPath); - - // Add task and project context to each file - const enrichedFiles = taskFiles.map(file => ({ - ...file, - task_id: taskId, - project_id: projectId, - // Add relative path from project root - relativePath: path.relative(projectPath, file.path) - })); + + const enrichedFiles = taskFiles.map(file => { + const fileDir = path.dirname(file.path); + const relativeParentPath = path.relative(projectPath, fileDir); + + return { + ...file, + task_id: taskId, + project_id: projectId, + relativePath: relativeParentPath === '.' ? '' : relativeParentPath + }; + }); allFiles.push(...enrichedFiles); } diff --git a/src/components/Folder/index.tsx b/src/components/Folder/index.tsx index 49b5a8b46..e5eb065a5 100644 --- a/src/components/Folder/index.tsx +++ b/src/components/Folder/index.tsx @@ -207,7 +207,6 @@ export default function Folder({ data }: { data?: Agent }) { const [isCollapsed, setIsCollapsed] = useState(false); - // Build tree structure from flat file list const buildFileTree = (files: FileInfo[]): FileTreeNode => { const root: FileTreeNode = { name: "root", @@ -216,17 +215,20 @@ export default function Folder({ data }: { data?: Agent }) { isFolder: true, }; - // Create a map for quick access const nodeMap = new Map(); nodeMap.set("", root); - // Sort files so folders come before files and by path depth const sortedFiles = [...files].sort((a, b) => { const depthA = (a.relativePath || "").split("/").filter(Boolean).length; const depthB = (b.relativePath || "").split("/").filter(Boolean).length; return depthA - depthB; }); + for (const file of sortedFiles) { + const fullRelativePath = file.relativePath + ? `${file.relativePath}/${file.name}` + : file.name; + const parentPath = file.relativePath || ""; const parentNode = nodeMap.get(parentPath) || root; @@ -243,10 +245,7 @@ export default function Folder({ data }: { data?: Agent }) { parentNode.children!.push(node); if (file.isFolder) { - const folderPath = parentPath - ? `${parentPath}/${file.name}` - : file.name; - nodeMap.set(folderPath, node); + nodeMap.set(fullRelativePath, node); } }