LofiSu
4f9d1d524e
feat(frontend): unify citation logic and prevent half-finished citations
...
- Add SafeCitationContent as single component for citation-aware body:
useParsedCitations + shouldShowCitationLoading; show loading until
citations complete, then render body with createCitationMarkdownComponents.
Supports optional remarkPlugins, rehypePlugins, isHuman, img.
- Refactor MessageListItem: assistant message body now uses
SafeCitationContent only; remove duplicate useParsedCitations,
shouldShowCitationLoading, createCitationMarkdownComponents and
CitationsLoadingIndicator logic. Human messages keep plain
AIElementMessageResponse (no citation parsing).
- Use SafeCitationContent for clarification, present-files (message-list),
thinking steps and write_file loading (message-group), subtask result
(subtask-card). Artifact markdown preview keeps same guard
(shouldShowCitationLoading) with ArtifactFilePreview.
- Unify loading condition: shouldShowCitationLoading(rawContent,
cleanContent, isLoading) is the single source of truth. Show loading when
(isLoading && hasCitationsBlock(rawContent)) or when
(hasCitationsBlock(rawContent) && hasUnreplacedCitationRefs(cleanContent))
so Pro/Ultra modes also show "loading citations" and half-finished
[cite-N] never appear.
- message-group write_file: replace hasCitationsBlock + threadIsLoading
with shouldShowCitationLoading(fileContent, cleanContent,
threadIsLoading && isLast) for consistency.
- citations/utils: parse incomplete <citations> during streaming;
remove isCitationsBlockIncomplete; keep hasUnreplacedCitationRefs
internal; document display rule in file header.
Co-authored-by: Cursor <cursoragent@cursor.com >
---
feat(前端): 统一引用逻辑并杜绝半成品引用
- 新增 SafeCitationContent 作为引用正文的唯一出口:内部使用
useParsedCitations + shouldShowCitationLoading,在引用未就绪时只显示
「正在整理引用」,就绪后用 createCitationMarkdownComponents 渲染正文;
支持可选 remarkPlugins、rehypePlugins、isHuman、img。
- 重构 MessageListItem:助手消息正文仅通过 SafeCitationContent 渲染,
删除重复的 useParsedCitations、shouldShowCitationLoading、
createCitationMarkdownComponents、CitationsLoadingIndicator 等逻辑;
用户消息仍用 AIElementMessageResponse,不做引用解析。
- 澄清、present-files(message-list)、思考步骤与 write_file 加载
(message-group)、子任务结果(subtask-card)均使用
SafeCitationContent;Artifact 的 markdown 预览仍用同一 guard
shouldShowCitationLoading,正文由 ArtifactFilePreview 渲染。
- 统一加载条件:shouldShowCitationLoading(rawContent, cleanContent,
isLoading) 为唯一判断。在「流式中且已有引用块」或「有引用块且
cleanContent 中仍有未替换的 [cite-N]」时仅显示加载,从而在 Pro/Ultra
下也能看到「正在整理引用」,且永不出现半成品 [cite-N]。
- message-group 的 write_file:用 shouldShowCitationLoading(
fileContent, cleanContent, threadIsLoading && isLast) 替代
hasCitationsBlock + threadIsLoading,与其他场景一致。
- citations/utils:流式时解析未闭合的 <citations>;移除
isCitationsBlockIncomplete;hasUnreplacedCitationRefs 保持内部使用;
在文件头注释中说明展示规则。
2026-02-09 15:01:51 +08:00
LofiSu
0fff2880d3
Merge upstream/experimental and resolve conflicts; citations + path_utils + mode-hover
...
## 冲突解决 (Resolve conflicts)
- input-box.tsx: 保留 ModeHoverGuide 包裹的模式选择器(PR #26 的 mode-hover-guide)
- message-group.tsx: 保留 getCleanContent / hasCitationsBlock / useParsedCitations
- message-list-item.tsx: 保留 useParsedCitations,移除重复的 MessageLink(使用 CitationAwareLink)
- artifact-file-detail.tsx: 保留 CitationAwareLink、useParsedCitations、contentWithoutCitationsFromParsed
- artifacts.py: 保留 path_utils 与 _extract_citation_urls + remove_citations_block 精简实现
- citations/index.ts: 保留并补充 contentWithoutCitationsFromParsed 导出
- en-US.ts: 保留 Ultra 模式描述 "Reasoning, planning and execution with subagents..."
- zh-CN.ts: 保留「超级」标签,描述保留「思考、计划并执行,可调用子代理分工协作...」
## PR #26 代码改动汇总
### 1. Citations(引用)
- lead_agent prompt: 增加 Web search 与子代理合成时的 citation 提示
- general_purpose: 子代理 system prompt 增加 <citations_format> 说明
- frontend utils: 新增 contentWithoutCitationsFromParsed,removeAllCitations 基于单次解析
- frontend artifact: 使用 contentWithoutCitationsFromParsed(parsed) 避免对同一内容解析两次
- backend artifacts: _extract_citation_urls + remove_citations_block,json 提到顶部
### 2. path_utils(路径解析)
- 新增 backend/src/gateway/path_utils.py:resolve_thread_virtual_path,防 path traversal
- artifacts.py / skills.py:删除内联路径解析,统一使用 path_utils
### 3. Mode hover guide
- input-box: 模式选择器外包 ModeHoverGuide,悬停展示模式说明
### 4. i18n
- en: ultraModeDescription 与 zh: ultraMode / ultraModeDescription 与上游对齐并保留 PR 文案
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-02-09 13:01:01 +08:00
LofiSu
2a39947830
feat: citations prompts, path_utils, and citation code cleanup
...
- Prompt: add citation reminders for web_search and subagent synthesis (lead_agent, general_purpose)
- Gateway: add path_utils for shared thread virtual path resolution; refactor artifacts and skills to use it
- Citations: simplify removeAllCitations (single parse); backend _extract_citation_urls and remove_citations_block cleanup
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-02-09 12:55:12 +08:00
LofiSu
30e1760211
refactor(frontend): simplify and deduplicate Citation-related code
...
- Extract removeCitationsBlocks in utils, reuse in parseCitations and removeAllCitations
- Add hasCitationsBlock; isCitationsBlockIncomplete now uses it
- Add useParsedCitations hook (parseCitations + buildCitationMap) for message/artifact
- Add CitationAwareLink to unify link rendering (message-list-item + artifact-file-detail)
- Add getCleanContent helper; message-group uses it and useParsedCitations
- ArtifactFileDetail: single useParsedCitations, pass cleanContent/citationMap to Preview
- Stop exporting buildCitationMap and removeCitationsBlocks from citations index
- Remove duplicate MessageLink and inline link logic in artifact preview
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-02-09 12:13:06 +08:00
LofiSu
2d70aaa969
fix(frontend): citations display + refactor link/citation utils
...
- Citations: no underline while streaming (message links); artifact markdown external links as citation cards
- Refactor: add isExternalUrl, syntheticCitationFromLink in core/citations; shared externalLinkClass in lib/utils; simplify message-list-item and artifact-file-detail link rendering
修复引用展示并抽离链接/引用工具
- 引用:流式输出时链接不这下划线;Artifact 内 Markdown 外链以引用卡片展示
- 重构:core/citations 新增 isExternalUrl、syntheticCitationFromLink;lib/utils 共享 externalLinkClass;精简消息与 Artifact 中的链接渲染逻辑
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-02-09 04:03:15 +08:00
LofiSu
644229f968
feat(citations): add shared citation components and optimize code
...
## New Features
- Add `CitationLink` shared component for rendering citation hover cards
- Add `CitationsLoadingIndicator` component for showing loading state
- Add `removeAllCitations` utility to strip all citations from content
- Add backend support for removing citations when downloading markdown files
- Add i18n support for citation loading messages (en-US, zh-CN)
## Code Optimizations
- Remove duplicate `ExternalLinkBadge` component, reuse `CitationLink` instead
- Consolidate `remarkPlugins` config in `streamdownPlugins` to avoid duplication
- Remove unused imports: `Citation`, `buildCitationMap`, `extractDomainFromUrl`, etc.
- Remove unused `messages` parameter from `ToolCall` component
- Remove unused `isWriteFile` parameter from `ArtifactFilePreview` component
- Remove unused `useI18n` hook from `MessageContent` component
## Bug Fixes
- Fix `remarkGfm` plugin configuration that prevented table rendering
- Fix React Hooks rule violation: move `useMemo` to component top level
- Replace `||` with `??` for nullish coalescing in clipboard data
## Code Cleanup
- Remove debug console.log/info statements from:
- `threads/hooks.ts`
- `notification/hooks.ts`
- `memory-settings-page.tsx`
- Fix import order in `message-group.tsx`
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-02-04 11:56:10 +08:00
LofiSu
e2e0fbf114
fix: hide incomplete citations block during streaming
...
Improve UX by hiding citations block while it's being streamed:
- Remove complete citations blocks (existing logic)
- Also remove incomplete citations blocks during streaming
- Prevents flickering of raw citations XML in the UI
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-01-29 12:50:09 +08:00
LofiSu
c14378a312
feat: refine citations format and improve content presentation
...
Backend:
- Simplify citations prompt format and rules
- Add clear distinction between chat responses and file content
- Enforce full URL usage in markdown links, prohibit [cite-1] format
- Require content-first approach: write full content, then add citations at end
Frontend:
- Hide <citations> block in both chat messages and markdown preview
- Remove top-level Citations/Sources list for cleaner UI
- Auto-remove <citations> block in code editor view for markdown files
- Keep inline citation hover cards for reference details
This ensures citations are presented like Claude: clean content with inline reference badges.
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-01-29 12:29:13 +08:00
LofiSu
ad85b72064
feat: add inline citations and thread management features
...
Citations:
- Add citations parsing utilities for extracting source references from AI responses
- Render inline citations as hover card badges in message content
- Display citation cards with title, URL, and description on hover
- Add citation badge rendering in artifact markdown preview
- Update prompt to guide AI to output citations in correct format
Thread Management:
- Add rename functionality for chat threads with dialog UI
- Add share functionality to copy thread link to clipboard
- Share links use Vercel URL for production accessibility
- Add useRenameThread hook for thread title updates
i18n:
- Add translations for rename, share, cancel, save, and linkCopied
Co-authored-by: Cursor <cursoragent@cursor.com >
2026-01-28 19:15:11 +08:00