-
Notifications
You must be signed in to change notification settings - Fork 614
fix: move_files newPath 参数计算规则 #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthroughmove_files now prefetches destination metadata and, per source, chooses validation path based on whether the destination is a file or directory (using destInfo.isFile). Each source is validated and renamed accordingly; errors and success messages are reported per-source. Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant Presenter as mcpPresenter
participant FS as FileSystem
Client->>Presenter: move_files(sources[], destination)
Presenter->>FS: getFileStats(destination) --> destInfo
alt destInfo.isFile == true
Presenter->>Presenter: for each source -> validDest = validate(destination)
else destInfo.isFile == false
Presenter->>Presenter: for each source -> validDest = validate(destination + "/" + basename(source))
end
loop for each source (parallel)
Presenter->>FS: rename(source, validDest)
FS-->>Presenter: success / error
Presenter-->>Client: per-source success/error message
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts (1)
1031-1040: Critical: destination handling now breaks multi-source moves and directory semanticsUsing
parsed.data.destinationas the exact target for every source means:
- All sources are renamed to the same path (data loss or immediate failures).
- Moving into an existing directory no longer works, since
fs.renamerequires the final target path (directory + basename), not the directory path itself.This regresses the previously correct behavior of moving multiple sources into a directory. Also, validating the same destination inside the loop is redundant.
Proposed fix: validate destination once, detect whether it is an existing directory, enforce directory requirement for multi-source moves, and compute a per-source target path accordingly. Also return meaningful error messages instead of
JSON.stringify(e)(which yields{}forError).Apply this diff to the
move_filescase:case 'move_files': { const parsed = MoveFilesArgsSchema.safeParse(args) if (!parsed.success) { throw new Error(`Invalid arguments for move_files: ${parsed.error}`) } - const results = await Promise.all( - parsed.data.sources.map(async (source) => { - const validSourcePath = await this.validatePath(source) - const validDestPath = await this.validatePath(parsed.data.destination) - try { - await fs.rename(validSourcePath, validDestPath) - return `Successfully moved ${source} to ${parsed.data.destination}` - } catch (e) { - return `Move ${source} to ${parsed.data.destination} failed: ${JSON.stringify(e)}` - } - }) - ) + const destinationInput = parsed.data.destination + // Validate destination once and determine whether it's an existing directory + const validatedDestination = await this.validatePath(destinationInput) + let destinationIsDirectory = false + try { + const destStat = await fs.stat(validatedDestination) + destinationIsDirectory = destStat.isDirectory() + } catch { + // Destination does not exist yet (allowed when moving a single source only) + destinationIsDirectory = false + } + + // If multiple sources, destination must be an existing directory + if (parsed.data.sources.length > 1 && !destinationIsDirectory) { + return { + content: [ + { + type: 'text', + text: `Destination must be an existing directory when moving multiple sources: ${destinationInput}` + } + ], + isError: true + } + } + + const results = await Promise.all( + parsed.data.sources.map(async (source) => { + try { + const validSourcePath = await this.validatePath(source) + const destPathForSource = destinationIsDirectory + ? path.join(validatedDestination, path.basename(validSourcePath)) + : validatedDestination + await fs.rename(validSourcePath, destPathForSource) + const renderedDest = destinationIsDirectory + ? path.join(destinationInput, path.basename(source)) + : destinationInput + return `Successfully moved ${source} to ${renderedDest}` + } catch (e) { + const errMsg = e instanceof Error ? e.message : String(e) + return `Move ${source} to ${destinationInput} failed: ${errMsg}` + } + }) + ) return { content: [ { type: 'text', text: results.join('\n') } ] } }
🧹 Nitpick comments (1)
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts (1)
1025-1030: Confirm intended semantics and update schema/description accordinglyIf the goal of this PR is to allow specifying a full target path for a single-source rename (without implicit basename join), we should explicitly document and enforce:
- When sources.length > 1: destination MUST be an existing directory.
- When sources.length === 1: destination may be a directory (auto-join basename) or a full target file path (rename).
Consider updating the
MoveFilesArgsSchemadescription and the tool description to reflect this rule for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx,js,jsx,vue}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Use English for logs and comments
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (CLAUDE.md)
Strict type checking enabled for TypeScript
**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
src/main/**/*.ts
📄 CodeRabbit Inference Engine (CLAUDE.md)
Main to Renderer: Use EventBus to broadcast events via mainWindow.webContents.send()
Use Electron's built-in APIs for file system and native dialogs
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
src/main/presenter/**/*.ts
📄 CodeRabbit Inference Engine (CLAUDE.md)
One presenter per functional domain
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
src/main/presenter/mcpPresenter/inMemoryServers/*.ts
📄 CodeRabbit Inference Engine (CLAUDE.md)
Implement new MCP tool in src/main/presenter/mcpPresenter/inMemoryServers/ when adding a new MCP tool
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development-setup.mdc)
**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
src/{main,renderer}/**/*.ts
📄 CodeRabbit Inference Engine (.cursor/rules/electron-best-practices.mdc)
src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
src/main/**/*.{ts,js,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)
主进程代码放在
src/main
Files:
src/main/presenter/mcpPresenter/inMemoryServers/filesystem.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T01:45:33.790Z
Learning: Applies to src/main/presenter/mcpPresenter/inMemoryServers/*.ts : Implement new MCP tool in src/main/presenter/mcpPresenter/inMemoryServers/ when adding a new MCP tool
* fix: add AlertDialogDescription to resolve accessibility warning (#706) * fix: resolve focus flicker when creating new windows with Ctrl+Shift+N (#707) * feat: enhance window management by implementing main window ID handling (#709) * docs: update zhipu developer doc website link (#715) Co-authored-by: gongchao <chao.gong@aminer.cn> * refactor: better translate (#716) * chore: en-us i18n * chore(i18n): polish ja-JP translations across UI; keep chat.input.placeholder unchanged * chore(i18n): polish fr-FR translations; keep chat.input.placeholder unchanged * chore(i18n): refine fr-FR MCP & Settings copy; idiomatic, concise, brand-consistent * chore(i18n): polish ru-RU translations across UI; keep chat.input.placeholder unchanged * chore(i18n): polish fa-IR translations across UI; keep chat.input.placeholder unchanged * chore: fix format * chore: fix i18n * chore: lock rolldown-vite version * feat: add GPT-5 series model support (#717) * ci(vite): Bundle the main file into a single file to speed up loading. (#718) * fix(math): parser by upgrade vue-renderer-markdown (#722) * chore: bump deps (#721) * chore: bump deps * fix: rolldown-vite 7.1.0 and duckdb bundle issue * chore: back to vite * chore: update electron * chore: update versions * fix(math): parser by upgrade vue-renderer-markdown (#722) * chore: bump deps --------- Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com> * fix: add scrollable support to PopoverContent to prevent overflow (#720) * feat: implement floating chat window system with performance optimization (#724) * feat: add mcp sync and modelscope provider #615 (#723) * wip: add modelscope provider * feat: add mcp sync to modelscope * fix: add scrollable support to PopoverContent to prevent overflow (#720) * feat: implement floating chat window system with performance optimization (#724) * chore: i18n and format * feat: better style * fix: mcp tool display --------- Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com> * fix: move_files newPath parse issue (#725) * fix: move_files newPath 参数计算规则 * fix: move_files 移动前需要判断dest是目录还是文件 * feat: add Claude Opus 4.1 to anthropic default model list (#726) * feat: Add mcprouter's MCP marketplace api support (#727) * wip: add mcp market * feat: mcp market install * wip: mcp install status sync * feat: mcp server config mask * chore: remove working doc * chore: add translate * feat: add ESC key to close floating chat window (#728) * feat: add floating button position persistence with boundary validation (#729) * feat: add floating button position persistence with boundary validation * feat: refactor floating button to use electron-window-state * chore: bump to 0.3.0 * feat: add reasoning_effort parameter support for gpt-oss models (#731) * feat: add reasoning_effort parameter support for gpt-oss models - add reasoning effort UI support across all components * fix: preserve user reasoning effort settings and improve display logic * fix: artifacts code not streaming (#732) * fix: artifact react load failed * chore: remove log * fix: artifacts code not stream * fix: format --------- Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com> Co-authored-by: hllshiro <40970081+hllshiro@users.noreply.github.com> Co-authored-by: tomsun28 <tomsun28@outlook.com> Co-authored-by: gongchao <chao.gong@aminer.cn> Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com> Co-authored-by: wanna <wanna.w@binarywalk.com>
* fix: add AlertDialogDescription to resolve accessibility warning (#706) * fix: resolve focus flicker when creating new windows with Ctrl+Shift+N (#707) * feat: enhance window management by implementing main window ID handling (#709) * docs: update zhipu developer doc website link (#715) Co-authored-by: gongchao <chao.gong@aminer.cn> * refactor: better translate (#716) * chore: en-us i18n * chore(i18n): polish ja-JP translations across UI; keep chat.input.placeholder unchanged * chore(i18n): polish fr-FR translations; keep chat.input.placeholder unchanged * chore(i18n): refine fr-FR MCP & Settings copy; idiomatic, concise, brand-consistent * chore(i18n): polish ru-RU translations across UI; keep chat.input.placeholder unchanged * chore(i18n): polish fa-IR translations across UI; keep chat.input.placeholder unchanged * chore: fix format * chore: fix i18n * chore: lock rolldown-vite version * feat: add GPT-5 series model support (#717) * ci(vite): Bundle the main file into a single file to speed up loading. (#718) * fix(math): parser by upgrade vue-renderer-markdown (#722) * chore: bump deps (#721) * chore: bump deps * fix: rolldown-vite 7.1.0 and duckdb bundle issue * chore: back to vite * chore: update electron * chore: update versions * fix(math): parser by upgrade vue-renderer-markdown (#722) * chore: bump deps --------- Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com> * fix: add scrollable support to PopoverContent to prevent overflow (#720) * feat: implement floating chat window system with performance optimization (#724) * feat: add mcp sync and modelscope provider #615 (#723) * wip: add modelscope provider * feat: add mcp sync to modelscope * fix: add scrollable support to PopoverContent to prevent overflow (#720) * feat: implement floating chat window system with performance optimization (#724) * chore: i18n and format * feat: better style * fix: mcp tool display --------- Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com> * fix: move_files newPath parse issue (#725) * fix: move_files newPath 参数计算规则 * fix: move_files 移动前需要判断dest是目录还是文件 * feat: add Claude Opus 4.1 to anthropic default model list (#726) * feat: Add mcprouter's MCP marketplace api support (#727) * wip: add mcp market * feat: mcp market install * wip: mcp install status sync * feat: mcp server config mask * chore: remove working doc * chore: add translate * feat: add ESC key to close floating chat window (#728) * feat: add floating button position persistence with boundary validation (#729) * feat: add floating button position persistence with boundary validation * feat: refactor floating button to use electron-window-state * chore: bump to 0.3.0 * feat: add reasoning_effort parameter support for gpt-oss models (#731) * feat: add reasoning_effort parameter support for gpt-oss models - add reasoning effort UI support across all components * fix: preserve user reasoning effort settings and improve display logic * fix: artifacts code not streaming (#732) * fix: artifact react load failed * chore: remove log * fix: artifacts code not stream * fix: format * feat: disable automatic model enabling for better UX (#734) * feat: sync provider sorting from settings to model selection (#736) * feat: sync provider sorting from settings to model selection * feat: refactor ModelSelect to use computed providers for better reactivity --------- Co-authored-by: yyhhyyyyyy <yyhhyyyyyy8@gmail.com> Co-authored-by: hllshiro <40970081+hllshiro@users.noreply.github.com> Co-authored-by: tomsun28 <tomsun28@outlook.com> Co-authored-by: gongchao <chao.gong@aminer.cn> Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com> Co-authored-by: wanna <wanna.w@binarywalk.com>
fix: move_files newPath 参数计算规则
Summary by CodeRabbit
New Features
Improvements