Skip to content

feat(core): refine config schema and fix emgas lint#782

Merged
dingyi222666 merged 2 commits intoChatLunaLab:v1-devfrom
PinkElysiaDev:v1-dev
Mar 15, 2026
Merged

feat(core): refine config schema and fix emgas lint#782
dingyi222666 merged 2 commits intoChatLunaLab:v1-devfrom
PinkElysiaDev:v1-dev

Conversation

@PinkElysiaDev
Copy link
Contributor

将 isReplyWithAt 从单纯布尔开关改为“开关 + 阈值分支”配置
新增 replyQuoteThreshold,用于按响应耗时决定是否引用原消息
将 isForwardMsg 同样改为“开关 + 阈值分支”配置
forwardMsgMinLength 仅在启用合并消息时显示
调整 schema 结构,使两个分支配置分别紧跟各自开关显示
同步更新中英文 locales 文案
优化 includeQuoteReply 与 replyQuoteThreshold 的中文描述,使其语义更准确、表达更统一
修复了lint问题

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

将聊天链的上下文(含 options.startedAt)在线程中传递到发送器与碎片构建逻辑中;基于该时间戳和新增配置 replyQuoteThreshold 决定引用前缀;配置校验重构为条件交叉模式;以及将 ASCII 检查改为逐字符判断以兼容非 ASCII 内容。

Changes

Cohort / File(s) Summary
聊天链与发送器
packages/core/src/chains/chain.ts
在 ChatChain.receiveMessage / receiveCommand 中初始化 context(含 options.startedAt)并绑定 send;将 ChatChain.sendMessage、ChatChainSender 类型、DefaultChatChainSender.send / sendAsNormal / buildMessageFragment 等签名改为接受可选 context?: ChainMiddlewareContext,并在线程中传递该 context(用于计时/引用逻辑与错误/中间件路径)。
引用计时与阈值逻辑
packages/core/src/chains/... (相关引用构建逻辑散布于同文件)
引用构建(quote)改为使用 context?.options?.startedAt 计算 elapsed 时间,并对比配置的 replyQuoteThreshold 决定是否添加引用前缀。
配置与校验模式
packages/core/src/config.ts
新增 replyQuoteThreshold?: number;将 isReplyWithAt/replyQuoteThresholdisForwardMsg/forwardMsgMinLength 的约束从主配置对象拆出为基于布尔标志的条件交叉(intersect)模式,实现按开关启用额外字段的验证。
长期记忆提取器
packages/extension-long-memory/src/layers/emgas/extractor.ts
将 ASCII 判定从整体正则改为逐字符检查(Array.from(...).every(char => char.charCodeAt(0) <= 0x7f)),仅对纯 ASCII 字符串进行小写化,其余保持不变。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User as Client (User)
    participant Chain as ChatChain
    participant Sender as DefaultChatChainSender
    participant Fragment as MessageFragmentBuilder

    User->>Chain: receiveMessage / receiveCommand(...)
    Note right of Chain: context = { options: { startedAt: Date.now() }, send: bound }
    Chain->>Sender: sendMessage(session, messages, context)
    Sender->>Fragment: buildMessageFragment(session, message, context)
    Fragment-->>Sender: fragment (uses context.options.startedAt)
    Sender->>Chain: send/dispatch(fragment, context)
    Chain-->>User: delivered
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🐰✨ 我是一只忙碌兔,线路里穿上下文,
计时带来引用舞,阈值决定谁入幕,
ASCII 细细看一遍,字符友好不惊慌,
配置有门有条件,消息流里更分明。

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了主要变化:配置架构优化和emgas代码检查修复,与文件改动相符。
Description check ✅ Passed 描述内容与变更集相关联,详细说明了配置字段的调整和功能改进,尽管使用中文,但内容清晰。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过引入基于阈值的条件逻辑来增强消息回复和转发功能,从而优化核心配置架构。它将 isReplyWithAtisForwardMsg 从简单的布尔开关升级为更灵活的“开关 + 阈值分支”配置,允许用户根据响应时间等因素精细控制消息行为。此外,还对配置 schema 进行了重构,以提高其清晰度和用户体验,并同步更新了多语言文案。最后,修复了 emgas 模块中的一个 lint 问题,提升了代码质量。

Highlights

  • 配置架构优化: 将 isReplyWithAtisForwardMsg 配置从简单的布尔开关升级为支持“开关 + 阈值分支”的模式,允许更精细的控制。
  • 引入响应时间阈值: 新增 replyQuoteThreshold 配置,使得引用原消息的行为可以根据响应耗时动态决定。
  • 配置显示逻辑改进: 优化了配置 schema 结构,确保 forwardMsgMinLengthreplyQuoteThreshold 等相关配置项仅在其主开关启用时才显示,提升了用户体验。
  • 多语言文案更新: 同步更新了中英文本地化文案,使配置描述更加准确和统一。
  • 代码质量提升: 修复了 emgas 模块中的 lint 问题,改进了字符串处理逻辑。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/core/src/chains/chain.ts
    • 更新了 sendMessage 方法和 ChatChainSender 类型定义,以包含可选的 context 参数。
    • 在创建 ChainMiddlewareContext 时,初始化了 requestStartedAt 选项。
    • 修改了 buildMessageFragment 方法,利用 context 中的 requestStartedAtreplyQuoteThreshold 来计算 elapsedTime,并据此决定是否引用消息。
  • packages/core/src/config.ts
    • 引入了 replyQuoteThreshold 配置项。
    • 重构了 isReplyWithAtisForwardMsg 配置项,使其相关子配置(replyQuoteThresholdforwardMsgMinLength)能够条件显示。
    • 调整了配置 schema 的整体结构,以更好地组织相关设置。
  • packages/core/src/locales/en-US.schema.yml
    • 更新了 includeQuoteReply 的描述。
    • isReplyWithAtreplyQuoteThreshold 添加了新的描述,并重新组织了配置组。
  • packages/core/src/locales/zh-CN.schema.yml
    • 更新了 includeQuoteReply 的描述。
    • isReplyWithAtreplyQuoteThreshold 添加了新的描述,并重新组织了配置组。
  • packages/extension-long-memory/src/layers/emgas/extractor.ts
    • 添加了 isAscii 辅助函数。
    • 修改了 format 函数,使用 isAscii 来判断字符串是否为 ASCII,并据此决定是否转换为小写,修复了 lint 问题。
Activity
  • 自创建以来,此拉取请求尚未有任何人工活动记录。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 主要重构了配置项 isReplyWithAtisForwardMsg 的 schema,使其支持条件化配置,并引入了 replyQuoteThreshold 以根据响应耗时决定是否引用原消息。相关的函数签名和调用都已更新,以传递 context 对象来计算耗时。同时,中英文 locale 文案也得到了同步更新,使其描述更准确。代码中还修复了一个 lint 问题。

整体来看,代码实现清晰,符合预期功能。我只在 emgas/extractor.ts 中发现一个可以改进的地方,即使用 codePointAt() 来更健壮地处理 Unicode 字符。具体建议请见行内评论。

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/config.ts (1)

8-9: ⚠️ Potential issue | 🟡 Minor

类型定义与 Schema 不一致

forwardMsgMinLength 在接口中定义为必填 (number),但在 Schema 中仅当 isForwardMsgtrue 时才存在。当 isForwardMsgfalse 时,运行时该字段为 undefined,与类型定义冲突。

建议将其改为可选类型以保持一致:

建议修复
     isForwardMsg: boolean
-    forwardMsgMinLength: number
+    forwardMsgMinLength?: number
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/config.ts` around lines 8 - 9, The interface in config.ts
declares forwardMsgMinLength as a required number while the runtime Schema only
provides it when isForwardMsg is true; update the interface where isForwardMsg
and forwardMsgMinLength are declared so forwardMsgMinLength is optional (change
to forwardMsgMinLength?: number) and adjust any related type usages/call sites
or casts to handle undefined accordingly to keep types consistent with the
Schema.
🧹 Nitpick comments (1)
packages/core/src/chains/chain.ts (1)

742-748: 验证 forwardMsgMinLengthisForwardMsgfalse 时的行为

根据新的 Schema 配置,当 isForwardMsgfalse 时,forwardMsgMinLength 将为 undefined。虽然运行时短路求值 (&&) 可以保护此访问,但建议添加空值合并以增强健壮性,与 replyQuoteThreshold 的处理方式保持一致。

建议修复
         if (
             this.config.isForwardMsg &&
             this.getMessageText(messages).length >
-                this.config.forwardMsgMinLength
+                (this.config.forwardMsgMinLength ?? 0)
         ) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/core/src/chains/chain.ts` around lines 742 - 748, The guard uses
this.config.isForwardMsg && this.getMessageText(messages).length >
this.config.forwardMsgMinLength which relies on short-circuiting but should
mirror replyQuoteThreshold handling; update the comparison to use a
nullish-coalescing default for forwardMsgMinLength (e.g.,
this.config.forwardMsgMinLength ?? 0) so when isForwardMsg is false or
forwardMsgMinLength is undefined it behaves safely, keeping the overall
condition and calls to getMessageText(messages) and sendAsForward(session,
messages) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/core/src/config.ts`:
- Around line 8-9: The interface in config.ts declares forwardMsgMinLength as a
required number while the runtime Schema only provides it when isForwardMsg is
true; update the interface where isForwardMsg and forwardMsgMinLength are
declared so forwardMsgMinLength is optional (change to forwardMsgMinLength?:
number) and adjust any related type usages/call sites or casts to handle
undefined accordingly to keep types consistent with the Schema.

---

Nitpick comments:
In `@packages/core/src/chains/chain.ts`:
- Around line 742-748: The guard uses this.config.isForwardMsg &&
this.getMessageText(messages).length > this.config.forwardMsgMinLength which
relies on short-circuiting but should mirror replyQuoteThreshold handling;
update the comparison to use a nullish-coalescing default for
forwardMsgMinLength (e.g., this.config.forwardMsgMinLength ?? 0) so when
isForwardMsg is false or forwardMsgMinLength is undefined it behaves safely,
keeping the overall condition and calls to getMessageText(messages) and
sendAsForward(session, messages) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4cd3bfd7-7c49-4bb8-8352-0a32138c10be

📥 Commits

Reviewing files that changed from the base of the PR and between 8b2c31a and f6460f6.

⛔ Files ignored due to path filters (2)
  • packages/core/src/locales/en-US.schema.yml is excluded by !**/*.yml
  • packages/core/src/locales/zh-CN.schema.yml is excluded by !**/*.yml
📒 Files selected for processing (3)
  • packages/core/src/chains/chain.ts
  • packages/core/src/config.ts
  • packages/extension-long-memory/src/layers/emgas/extractor.ts

@dingyi222666 dingyi222666 merged commit 58881ca into ChatLunaLab:v1-dev Mar 15, 2026
4 of 5 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