feat(ui): 实现 @ 文件提及自动补全功能

- Core: 添加 file-index 模块,使用 ripgrep 索引文件,fuzzysort 模糊搜索
- Server: 添加 /api/files/search 端点,支持文件模糊搜索
- Server: WebSocket 消息处理中将 @filepath 转换为 ./filepath 格式
- UI: 新增 FileMenu 组件,显示文件搜索结果列表
- UI: 新增 FileMentionTag 组件,高亮显示文件提及
- UI: 新增 useFileMention hook,管理文件提及状态
- UI: ChatInput 集成 @ 触发的文件自动补全
- UI: ChatMessage 用户消息中高亮显示 @filepath
This commit is contained in:
2025-12-15 16:32:59 +08:00
parent 5b7b0ff1e4
commit 865e0906b9
15 changed files with 1137 additions and 53 deletions
+6 -3
View File
@@ -20,6 +20,7 @@ import { useState, forwardRef } from 'react';
import { cn } from '../utils/cn';
import { fadeInUp, smoothTransition } from '../utils/animations';
import { Markdown } from './Markdown';
import { FileMentionText } from './FileMentionTag';
import type { Message, ToolCallInfo, ToolCallStatus, ToolMessagePart } from '../api/types.js';
interface ChatMessageProps {
@@ -48,8 +49,8 @@ export const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>(
case 'text':
if (!part.text) return null;
return isUser ? (
<div key={part.id} className="whitespace-pre-wrap break-words">
{part.text}
<div key={part.id}>
<FileMentionText text={part.text} />
</div>
) : (
<Markdown key={part.id} content={part.text} />
@@ -78,7 +79,9 @@ export const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>(
)}
<div className="message-content text-fg-secondary">
{isUser ? (
<div className="whitespace-pre-wrap break-words">{message.content ?? ''}</div>
<div>
<FileMentionText text={message.content ?? ''} />
</div>
) : (
<Markdown content={message.content ?? ''} />
)}