Skip to content

模板规则变更检测 — 启动聊天时比对选项变更并弹窗确认#195

Open
Mizushima-Mihane wants to merge 4 commits into
RachelForster:mainfrom
Mizushima-Mihane:feat/template-change-confirmation
Open

模板规则变更检测 — 启动聊天时比对选项变更并弹窗确认#195
Mizushima-Mihane wants to merge 4 commits into
RachelForster:mainfrom
Mizushima-Mihane:feat/template-change-confirmation

Conversation

@Mizushima-Mihane

@Mizushima-Mihane Mizushima-Mihane commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
  • 新增 ruleChangeDialogOpen 状态,启动聊天时遍历 templateOptionsState 与 launchSession 逐一比对,检测 LLM 翻译/旁白规则等开关变更
  • AlertDialog 新增可选 onClose / cancelTitle 属性
  • 弹窗选项:是→快速重启,否→沿用旧规则启动,X→关闭不启动
  • 动态比对:新增选项自动纳入检测,无需手动更新判断列表
  • 新增中/英/日三语翻译

Summary by Sourcery

在启动聊天时,如果模板内容规则与上一次启动的会话不同,则添加一个确认对话框,让用户在快速重启和继续使用之前规则之间进行选择。

新功能:

  • 在聊天启动时引入规则变更检测,通过将当前模板选项与上一次启动的会话进行比较,并在确认对话框后才允许继续启动。
  • 扩展共享的 AlertDialog 组件,增加可选的关闭处理逻辑,以及用于取消操作的提示文本(tooltip)。
  • 为新的规则变更对话框新增本地化文案,支持英文、日文和简体中文。

增强改进:

  • 改进对话框行为,允许使用与 onCancel 分离的专用 onClose 处理函数,以更好地反映用户意图。
Original summary in English

Summary by Sourcery

Add a confirmation dialog when launching a chat if template content rules differ from the last launched session, allowing users to choose between quick restart or continuing with previous rules.

New Features:

  • Introduce rule-change detection on chat launch by comparing current template options against the last launched session and gating launch behind a confirmation dialog.
  • Extend the shared AlertDialog component with optional close handling and tooltip text for the cancel action.
  • Add localized copy for the new rule-change dialog in English, Japanese, and Simplified Chinese.

Enhancements:

  • Improve dialog behavior by allowing a distinct onClose handler separate from onCancel to better reflect user intent.

- 新增 ruleChangeDialogOpen 状态,启动聊天时遍历 templateOptionsState
  与 launchSession 逐一比对,检测 LLM 翻译/旁白规则等开关变更
- AlertDialog 新增可选 onClose / cancelTitle 属性
- 弹窗选项:是→快速重启,否→沿用旧规则启动,X→关闭不启动
- 动态比对:新增选项自动纳入检测,无需手动更新判断列表
- 新增中/英/日三语翻译

Co-Authored-By: Claude <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

审查者指南

在启动聊天时实现模板选项规则变更的动态检测,新增确认对话框,让用户在“快速重新开始”和“继续使用旧规则”之间进行选择,并扩展共享的 AlertDialog/i18n,使其支持这一流程及多语言文案。

规则变更检测与启动流程的时序图

sequenceDiagram
  actor User
  participant TemplateEditorPage
  participant AlertDialog
  participant launchMutation

  User->>TemplateEditorPage: click AsyncButton launch
  TemplateEditorPage->>TemplateEditorPage: compare templateOptionsState with launchSession
  alt rules_changed
    TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(true)
    TemplateEditorPage->>AlertDialog: render with open=true
    alt User clicks Yes (confirm)
      AlertDialog->>TemplateEditorPage: onConfirm()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
      TemplateEditorPage->>launchMutation: mutate(resetHistory=true)
    else User clicks No (cancel)
      AlertDialog->>TemplateEditorPage: onCancel()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
      TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
    else User clicks Close (X)
      AlertDialog->>TemplateEditorPage: onClose()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
    end
  else rules_unchanged
    TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
  end
Loading

文件级变更

Change Details Files
在启动会话前增加规则变更检测,并将其接入新的确认对话框流程。
  • 在 TemplateEditorPage 中引入 ruleChangeDialogOpen React 状态以控制新的规则变更对话框。
  • 更新启动按钮的处理逻辑,对比 launchSession 与 templateOptionsState 的各个键,当任意选项不同时打开规则变更对话框。
  • 配置 AlertDialog 实例以映射对话框行为:确认触发快速重新开始(resetHistory: true),取消则继续使用旧规则(resetHistory: false),关闭仅关闭对话框而不启动会话。
frontend/src/features/template-editor/TemplateEditorPage.tsx
扩展 AlertDialog,使其可以为取消按钮显示 tooltip,并区分取消与关闭行为。
  • 在 AlertDialogProps 中新增可选的 cancelTitle 和 onClose 属性。
  • 在渲染取消按钮时,当提供 cancelTitle 时,用其作为 tooltip 绑定。
  • 更改 Dialog 的 onClose 行为:当提供 onClose 时使用 onClose,否则回退为 onCancel。
frontend/src/shared/ui/Dialog.tsx
为新的规则变更对话框在英文、日文和简体中文中添加本地化消息键。
  • 为 MessageKey 联合类型扩展 template.ruleChangeDialog 的 body/title/toast 键。
  • 为规则变更对话框的正文、标题和 tooltip 文本提供 en/ja/zh_CN 翻译。
frontend/src/shared/i18n/messages.ts
frontend/src/shared/i18n/messages/en.ts
frontend/src/shared/i18n/messages/ja.ts
frontend/src/shared/i18n/messages/zh_CN.ts

提示与命令

与 Sourcery 交互

  • 触发新审查: 在 Pull Request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复审查评论来请求 Sourcery 从该评论创建一个 issue。你也可以在某条审查评论下回复 @sourcery-ai issue 来从中创建一个 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 描述正文中任意位置写上 @sourcery-ai summary,即可在你指定的位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审查者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理了所有评论且不再希望看到它们,这将非常有用。
  • 撤销所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 审查。特别适用于你希望以一次全新的审查重新开始的场景——别忘了再评论 @sourcery-ai review 来触发新的审查!

自定义你的体验

访问你的控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 Pull Request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implements dynamic detection of template option rule changes when launching a chat, adds a confirmation dialog that lets users choose between quick restart or continuing with old rules, and extends the shared AlertDialog/i18n to support this flow with multi-language copy.

Sequence diagram for rule-change detection and launch flow

sequenceDiagram
  actor User
  participant TemplateEditorPage
  participant AlertDialog
  participant launchMutation

  User->>TemplateEditorPage: click AsyncButton launch
  TemplateEditorPage->>TemplateEditorPage: compare templateOptionsState with launchSession
  alt rules_changed
    TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(true)
    TemplateEditorPage->>AlertDialog: render with open=true
    alt User clicks Yes (confirm)
      AlertDialog->>TemplateEditorPage: onConfirm()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
      TemplateEditorPage->>launchMutation: mutate(resetHistory=true)
    else User clicks No (cancel)
      AlertDialog->>TemplateEditorPage: onCancel()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
      TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
    else User clicks Close (X)
      AlertDialog->>TemplateEditorPage: onClose()
      TemplateEditorPage->>TemplateEditorPage: setRuleChangeDialogOpen(false)
    end
  else rules_unchanged
    TemplateEditorPage->>launchMutation: mutate(resetHistory=false)
  end
Loading

File-Level Changes

Change Details Files
Add rule-change detection before launching a session and wire it to a new confirmation dialog flow.
  • Introduce ruleChangeDialogOpen React state in TemplateEditorPage to control a new rule-change dialog.
  • Update launch button handler to compare launchSession against templateOptionsState keys and open the rule-change dialog when any option differs.
  • Configure AlertDialog instance to map dialog actions: confirm triggers quick restart (resetHistory: true), cancel continues with old rules (resetHistory: false), close just dismisses without launching.
frontend/src/features/template-editor/TemplateEditorPage.tsx
Extend AlertDialog so it can display a tooltip for the cancel button and distinguish between cancel and close behaviors.
  • Add optional cancelTitle and onClose props to AlertDialogProps.
  • Render cancel button with tooltip bound to cancelTitle, if provided.
  • Change Dialog onClose behavior to use onClose when present, otherwise fall back to onCancel.
frontend/src/shared/ui/Dialog.tsx
Add localized message keys for the new rule-change dialog in English, Japanese, and Simplified Chinese.
  • Extend MessageKey union type with template.ruleChangeDialog body/title/toast keys.
  • Provide en/ja/zh_CN translations for the rule-change dialog body, title, and tooltip text.
frontend/src/shared/i18n/messages.ts
frontend/src/shared/i18n/messages/en.ts
frontend/src/shared/i18n/messages/ja.ts
frontend/src/shared/i18n/messages/zh_CN.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我发现了一个问题,并留下了一些高层次的反馈:

  • 启动按钮点击处理器中的规则变更检测逻辑有点臃肿;可以考虑把比较逻辑提取到一个小的辅助函数中(例如 hasTemplateRulesChanged(launchSession, templateOptionsState)),这样能让组件更易读,也便于将来修改比较逻辑。
  • 你正在对 templateOptionsState 的所有键直接使用 launchSession[key] !== templateOptionsState[key] 进行比较;如果这些值中有任何一个将来变成对象或数组,即使其逻辑内容相同,这种比较也总会报告为发生了变化。因此,更安全的做法可能是:要么将检查的键限制为已知的原始类型标志,要么使用能够体现预期语义的比较方式。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g. `hasTemplateRulesChanged(launchSession, templateOptionsState)`) to keep the component more readable and make future changes to the comparison logic easier.
- You are directly comparing `launchSession[key] !== templateOptionsState[key]` for all keys of `templateOptionsState`; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.

## Individual Comments

### Comment 1
<location path="frontend/src/shared/i18n/messages/en.ts" line_range="916" />
<code_context>
   "template.noEffect": "No effect",
   "template.quickRestart.body": "Clear the selected/default chat history and launch a fresh chat?",
   "template.quickRestart.title": "Quick restart",
+  "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to quick restart?",
+  "template.ruleChangeDialog.title": "Content Rule Changed",
+  "template.ruleChangeDialog.toast": "Chat will continue using previously saved rules",
</code_context>
<issue_to_address>
**nitpick (typo):** Minor wording issue in the new English message string.

The phrase "Do you want to quick restart?" is ungrammatical. Please update to something more natural, e.g. "Do you want to quick-restart?" or "Do you want to perform a quick restart?".

```suggestion
  "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to perform a quick restart?",
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据这些反馈不断改进我的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g. hasTemplateRulesChanged(launchSession, templateOptionsState)) to keep the component more readable and make future changes to the comparison logic easier.
  • You are directly comparing launchSession[key] !== templateOptionsState[key] for all keys of templateOptionsState; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The rule-change detection logic in the launch button click handler is getting a bit dense; consider extracting the comparison into a small helper (e.g. `hasTemplateRulesChanged(launchSession, templateOptionsState)`) to keep the component more readable and make future changes to the comparison logic easier.
- You are directly comparing `launchSession[key] !== templateOptionsState[key]` for all keys of `templateOptionsState`; if any of these values ever become objects/arrays, this will always report a change even when the logical content is the same, so it might be safer to either restrict the checked keys to known primitive flags or use a comparison that reflects the intended semantics.

## Individual Comments

### Comment 1
<location path="frontend/src/shared/i18n/messages/en.ts" line_range="916" />
<code_context>
   "template.noEffect": "No effect",
   "template.quickRestart.body": "Clear the selected/default chat history and launch a fresh chat?",
   "template.quickRestart.title": "Quick restart",
+  "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to quick restart?",
+  "template.ruleChangeDialog.title": "Content Rule Changed",
+  "template.ruleChangeDialog.toast": "Chat will continue using previously saved rules",
</code_context>
<issue_to_address>
**nitpick (typo):** Minor wording issue in the new English message string.

The phrase "Do you want to quick restart?" is ungrammatical. Please update to something more natural, e.g. "Do you want to quick-restart?" or "Do you want to perform a quick restart?".

```suggestion
  "template.ruleChangeDialog.body": "Content rule changes detected. Do you want to perform a quick restart?",
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread frontend/src/shared/i18n/messages/en.ts Outdated
Mizushima-Mihane and others added 3 commits June 26, 2026 23:07
- 将内联比对逻辑提取为 hasTemplateRulesChanged(session, options)
- 加 typeof boolean 守卫:非原始值直接跳过,避免未来对象/数组误报变更
- 修 en.ts 语法:Do you want to quick restart → perform a quick restart

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
session as Record<string, unknown> → session as unknown as Record<string, unknown>
TemplateLaunchSession 缺少索引签名,直接 cast 在 --pretty false 模式下报 TS2352

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants