Conversation
Implement file/folder drag payloads from FileTree and handle drops in MessageInput. File drops now add both attachment and context mention chip; folder drops add directory chip. Keep attachment failure fallback by inserting @path and dedupe mention prefixes on send. Fix claude-session-parser unit tests on Windows by using file URL import and deterministic home env overrides. Add spec-coding artifacts under docs/specs for this feature.
70622df to
a73e5d5
Compare
op7418
left a comment
There was a problem hiding this comment.
PR #171 Review: 文件树拖拽到输入框生成 ContextMention
总体评价
功能方向合理,补齐了 FileTree → MessageInput 的拖拽链路。代码结构清晰,有完整的规范文档。但有几个需要关注的问题:
需要改进的地方
1. 规范文档不应随代码提交
docs/specs/ 下的 architecture.md、product.md、tasks.md 是开发过程的辅助文档,不应该合入主仓库。建议移除这些文件,或移至 docs/exec-plans/ 目录下(按项目约定)。
2. hasDragType 函数过度防御
src/components/chat/MessageInput.tsx 中的 hasDragType 函数对 dataTransfer.types 做了三种兼容检查(includes、contains、Array.from)。现代浏览器中 DOMStringList 已经支持 includes,Electron 环境更不需要 contains 的 fallback。建议简化为直接用 Array.from(types).includes(type) 即可。
3. ContextMention chip 使用了固定 5 列网格
<div className="grid w-full grid-cols-5 gap-1.5 px-3 pt-2 pb-0 order-first">当 mention 数量少于 5 个时会有大量空白,超过 5 个时也不会自动换行显示合适。建议改用 flex flex-wrap 布局。
4. 文件扩展名颜色映射可扩展性不足
getMentionColorClasses 中硬编码了 doc/xls/pdf/txt 等扩展名的颜色。建议至少补充常见代码文件扩展名(ts/js/py 等),或者简化为只区分 file/directory 两种颜色。
5. 缺少对 text/x-codepilot-path fallback MIME 的说明
定义了两个 MIME 类型 application/x-codepilot-path 和 text/x-codepilot-path,但没有注释说明为什么需要 fallback。如果是为了某些浏览器兼容性,请补充注释。
6. useEffect 依赖数组中缺少 appendPathMention
拖拽相关的 useEffect 依赖了 addContextMention 但 drop handler 中通过 FileTreeAttachmentBridge 的 onAttachFailed 间接使用了 appendPathMention,如果 appendPathMention 引用变化可能导致闭包过期。
7. i18n 完整性
ContextMention 相关的用户可见文本(如拖拽提示)没有对应的 i18n key。虽然当前没有显式的拖拽提示文本,但 chip 的 tooltip 或 aria-label 应考虑国际化。
优点
- 使用自定义 MIME 类型区分 FileTree 拖拽与外部拖拽,设计合理
- 去重逻辑(发送前过滤已存在的
@path)考虑周全 FileTreeAttachmentBridge的onAttachFailed回退机制完善- 测试文件的
pathToFileURL修复是正确的
变更说明
规格文档
测试与验证
pm run test 通过(85 passed, 0 failed)。
额外修复