Skip to content

Conversation

@bigyao25
Copy link
Contributor

@bigyao25 bigyao25 commented Jul 7, 2025

Pull Request Description

Is your feature request related to a problem? Please describe.
When synthesizing the conversation context message, the system prompt word is spliced ​​twice. You can observe this by uncommenting the preparePromptContent log in the code.

Describe the solution you'd like
Fix the above bug.

UI/UX changes for Desktop Application
None

Platform Compatibility Notes
None

Additional context
None


Pull Request Description (中文)

你的功能请求是否与某个问题有关?请描述一下。
在合成对话上下文消息时,系统提示词被合并了两次。取消代码中 preparePromptContent 这条log的注释可以观察到。

请描述你希望的解决方案
修复以上问题。

桌面应用程序的 UI/UX 更改

平台兼容性注意事项

附加背景

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted the order of system prompt and context messages to ensure the system prompt appears first in message sequences.
  • Other

    • Enabled additional logging for prompt preparation details.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

Walkthrough

The update modifies the ThreadPresenter class by enabling a debug log in prompt preparation, reordering how system and context messages are arranged for completions, and refactoring the addContextMessages method to simplify its parameters and internal logic.

Changes

File(s) Change Summary
src/main/presenter/threadPresenter/index.ts Enabled a debug log in prompt preparation; changed the order of system/context messages; refactored addContextMessages method to remove an input parameter and simplify its logic.

Poem

In burrows deep where messages blend,
The order shifts, new logs now send.
Context first, then system’s say,
Refactored code to clear the way.
With simpler paths and tokens bright,
The thread hops forward, prompt and light!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
src/main/presenter/threadPresenter/index.ts (1)

1747-1747: Consider removing debug log or making it conditional for production.

This debug log was uncommented to help observe the system prompt duplication issue mentioned in the PR. However, it logs potentially sensitive conversation data that should not be exposed in production environments.

Consider making this conditional based on a debug flag:

-    console.log('preparePromptContent', mergedMessages, promptTokens)
+    if (process.env.NODE_ENV === 'development') {
+      console.log('preparePromptContent', mergedMessages, promptTokens)
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb931ca and bad5c4e.

📒 Files selected for processing (1)
  • src/main/presenter/threadPresenter/index.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
`**/*.{js,jsx,ts,tsx}`: 使用 OxLint 进行代码检查 Log和注释使用英文书写

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development-setup.mdc)

List of files the instruction was applied to:

  • src/main/presenter/threadPresenter/index.ts
`src/main/presenter/**/*.ts`: Use context isolation for improved security Use El...

src/main/presenter/**/*.ts: Use context isolation for improved security
Use Electron's built-in APIs for file system and native dialogs
Optimize application startup time with lazy loading

📄 Source: CodeRabbit Inference Engine (.cursor/rules/electron-best-practices.mdc)

List of files the instruction was applied to:

  • src/main/presenter/threadPresenter/index.ts
`{src/main/presenter/**/*.ts,src/renderer/stores/**/*.ts}`: Implement proper inter-process communication (IPC) patterns Implement proper error handling and logging for debugging

{src/main/presenter/**/*.ts,src/renderer/stores/**/*.ts}: Implement proper inter-process communication (IPC) patterns
Implement proper error handling and logging for debugging

📄 Source: CodeRabbit Inference Engine (.cursor/rules/electron-best-practices.mdc)

List of files the instruction was applied to:

  • src/main/presenter/threadPresenter/index.ts
`**/*.{ts,tsx}`: 始终使用 try-catch 处理可能的错误 提供有意义的错误信息 记录详细的错误日志 优雅降级处理 日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息 使用结构化日志 避免记录敏感信息 设置适当的日志级别 不要吞掉错误 提供用户友好的错误信息 实现错误重试机制

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
使用结构化日志
避免记录敏感信息
设置适当的日志级别
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制

📄 Source: CodeRabbit Inference Engine (.cursor/rules/error-logging.mdc)

List of files the instruction was applied to:

  • src/main/presenter/threadPresenter/index.ts
`src/main/**`: 主进程代码放在 `src/main`

src/main/**: 主进程代码放在 src/main

📄 Source: CodeRabbit Inference Engine (.cursor/rules/project-structure.mdc)

List of files the instruction was applied to:

  • src/main/presenter/threadPresenter/index.ts
🧠 Learnings (1)
src/main/presenter/threadPresenter/index.ts (10)
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-06-30T12:24:03.565Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Provider files should include provider-specific helper functions such as `formatMessages`, `convertToProviderTools`, `parseFunctionCalls`, and `prepareFunctionCallPrompt` as needed.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-06-30T12:24:03.565Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : `src/main/presenter/llmProviderPresenter/index.ts` should manage the overall Agent loop, conversation history, tool execution via `McpPresenter`, and communication with the frontend via `eventBus`.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-06-30T12:24:03.565Z
Learning: Applies to src/main/presenter/llmProviderPresenter/index.ts : The main Agent loop, including the `while` loop for conversation flow, state management, provider interaction, event handling, and frontend communication, must be implemented in `src/main/presenter/llmProviderPresenter/index.ts`.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-06-30T12:24:03.565Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Each file in `src/main/presenter/llmProviderPresenter/providers/*.ts` should handle interaction with a specific LLM API, including request/response formatting, tool definition conversion, management of native/non-native tool call mechanisms (prompt wrapping), and standardizing output streams to a common event format.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-06-30T12:23:13.338Z
Learning: Applies to src/main/presenter/**/*.ts : Use context isolation for improved security
Learnt from: neoragex2002
PR: ThinkInAIXYZ/deepchat#550
File: src/renderer/src/stores/chat.ts:1011-1035
Timestamp: 2025-06-21T15:49:17.044Z
Learning: In src/renderer/src/stores/chat.ts, the user prefers to keep both `text` and `content` properties in the `handleMeetingInstruction` function's `sendMessage` call, even though they are redundant, rather than removing the `content` property.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/llm-agent-loop.mdc:0-0
Timestamp: 2025-06-30T12:24:03.565Z
Learning: Applies to src/main/presenter/llmProviderPresenter/providers/*.ts : Provider files must implement the `coreStream(messages, modelId, temperature, maxTokens)` method, which receives formatted messages and generation parameters, handles tool support (native or via prompt wrapping), makes a single streaming API call, parses provider-specific data, and yields standardized stream events.
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-06-30T12:23:13.338Z
Learning: Applies to src/renderer/src/composables/usePresenter.ts : The IPC in the renderer process is implemented in usePresenter.ts, allowing direct calls to the presenter-related interfaces exposed by the main process
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-06-30T12:23:13.338Z
Learning: Applies to {src/main/presenter/**/*.ts,src/renderer/stores/**/*.ts} : Implement proper error handling and logging for debugging
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: .cursor/rules/electron-best-practices.mdc:0-0
Timestamp: 2025-06-30T12:23:13.338Z
Learning: Applies to {src/main/presenter/**/*.ts,src/renderer/stores/**/*.ts} : Implement proper inter-process communication (IPC) patterns
🧬 Code Graph Analysis (1)
src/main/presenter/threadPresenter/index.ts (1)
src/shared/presenter.d.ts (1)
  • ChatMessage (1066-1078)
🔇 Additional comments (2)
src/main/presenter/threadPresenter/index.ts (2)

1818-1831: Good fix for the system prompt duplication issue.

The reordering correctly addresses the bug mentioned in the PR objectives:

  1. Context messages are added first (lines 1818-1821)
  2. System prompt is inserted at the front using unshift (line 1826)

This ensures the system prompt appears first in the conversation without duplication, replacing the commented addSystemPrompt method that was likely causing the issue.


1874-1879: Good refactoring of method signature.

The simplified signature removes the unnecessary formattedMessages parameter and makes the method more self-contained by initializing its own result array. This improves the method's interface while maintaining the same functionality.

@zerob13
Copy link
Collaborator

zerob13 commented Jul 7, 2025

LGTM
i will remove the console log after merged

@zerob13 zerob13 merged commit fa987bb into ThinkInAIXYZ:dev Jul 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants