Skip to content

feat: 添加 AI 崩溃分析功能及相关配置#2824

Open
MapleLeaf2007 wants to merge 2 commits into
PCL-Community:devfrom
MapleLeaf2007:dev
Open

feat: 添加 AI 崩溃分析功能及相关配置#2824
MapleLeaf2007 wants to merge 2 commits into
PCL-Community:devfrom
MapleLeaf2007:dev

Conversation

@MapleLeaf2007
Copy link
Copy Markdown

@MapleLeaf2007 MapleLeaf2007 commented May 13, 2026

喵喵喵

Summary by Sourcery

添加可配置的 AI 驱动崩溃分析功能,用于 Minecraft 日志,并通过专用对话框和设置页面呈现结果。

新功能:

  • 引入基于 AI 的崩溃分析器,将过滤后的 Minecraft 崩溃日志发送到可配置的、兼容 OpenAI 的 API,并在自定义对话框中显示分析结果。
  • 在“工具”下新增 AI 设置页面,提供启用崩溃分析以及配置 API 类型、基础 URL、模型 ID 和 API 密钥等选项。
  • 将 AI 崩溃分析接入现有崩溃处理流程,在启用时于崩溃对话框中提供 AI 分析按钮。

增强项:

  • 在共享配置系统中持久化 AI 工具配置,并将其集成到安装向导导航和重置逻辑中。
  • 限制导出的实例可选择性包含 PCL 可执行文件,使用现有的复制工具代替已被注释掉的旧代码。
Original summary in English

Summary by Sourcery

Add configurable AI-powered crash analysis for Minecraft logs and surface it through a dedicated dialog and settings page.

New Features:

  • Introduce an AI-based crash analyzer that sends filtered Minecraft crash logs to a configurable OpenAI-compatible API and displays the analysis in a custom dialog.
  • Add a new AI settings page under Tools with options to enable crash analysis and configure API type, base URL, model ID, and API key.
  • Wire AI crash analysis into the existing crash handling flow, offering an AI analysis button in crash dialogs when enabled.

Enhancements:

  • Persist AI tool configuration in the shared config system and integrate it into the setup navigation and reset logic.
  • Limit exported instances to optionally include the PCL executable using the existing copy utility instead of commented legacy code.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XL PR 大小评估:超大型 labels May 13, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 13, 2026

审阅者指南

添加可配置的基于 AI 的崩溃分析(通过兼容 OpenAI 的 API),将其集成到崩溃对话框流程中,并新增 AI 工具设置页以及专门的 AI 分析消息对话框。

基于 AI 的崩溃分析流程时序图

sequenceDiagram
    actor User
    participant ModCrash
    participant CrashAiAnalyzer
    participant ModMain
    participant MyMsgAiAnalysis
    participant Requester

    User->>ModCrash: Output(IsHandAnalyze, ExtraFiles)
    ModCrash->>ModCrash: BuildAiAnalysisText(resultText)
    ModCrash->>CrashAiAnalyzer: Start(aiLogText)
    CrashAiAnalyzer->>ModMain: ShowCrashAiAnalysis(TrimLog(logText))
    ModMain->>MyMsgAiAnalysis: new MyMsgAiAnalysis(converter)
    MyMsgAiAnalysis->>CrashAiAnalyzer: Analyze(logText)
    CrashAiAnalyzer->>Requester: Fetch(endpoint, FetchParam)
    Requester-->>CrashAiAnalyzer: JSON response
    CrashAiAnalyzer-->>MyMsgAiAnalysis: analysisText
    MyMsgAiAnalysis-->>User: Display AI crash analysis
Loading

文件级改动

Change Details Files
将 AI 崩溃分析入口集成到现有崩溃对话框中,并为 AI 构建经过清洗的日志负载。
  • 新增 BuildAiAnalysisText 帮助方法,将本地分析、实例信息和多段日志组合成单一的、便于 AI 使用的文本,并对敏感数据进行过滤。
  • 扩展崩溃 Output 流程,在启用 AI 时显示“AI 分析”主按钮,调整次要按钮行为,并使用准备好的日志文本调用 CrashAiAnalyzer.Start。
  • 引入日志过滤,在发送给 AI 之前屏蔽访问令牌、用户名和 Bearer Authorization 头。
Plain Craft Launcher 2/Modules/Minecraft/ModCrash.cs
引入 CrashAiAnalyzer 工具,用于与兼容 OpenAI 的 API 通信,并在 Responses 与 Chat Completions 端点之间进行选择。
  • 新增 CrashAiAnalyzer,基于配置控制启用状态、API 类型选择以及日志截断逻辑,以限制请求大小。
  • 实现 Analyze 方法,构造 JSON 请求体,调用 /responses 或 /chat/completions 端点,并将多种响应格式解析为统一的文本输出。
  • 规范化基础 URL 以推导正确端点,包括对 api.openai.com 的特殊处理,并在请求失败或响应缺少可用文本时提供健壮的错误报告。
Plain Craft Launcher 2/Modules/Minecraft/ModCrashAi.cs
添加专门的 AI 崩溃分析模态消息控件,以异步方式执行 AI 请求并显示结果或错误。
  • 创建 MyMsgAiAnalysis 控件,启动后台 LoaderTask 调用 CrashAiAnalyzer.Analyze,并将任务状态绑定到加载指示器。
  • 以 markdown 形式渲染 AI 分析结果,提供复制到剪贴板功能,并在错误显示中展开并展示最内层异常消息。
  • 接入模态打开/关闭动画,并与全局消息队列生命周期集成,包括背景虚化以及拖动移动处理。
Plain Craft Launcher 2/Controls/MyMsg/MyMsgAiAnalysis.xaml.cs
Plain Craft Launcher 2/Controls/MyMsg/MyMsgAiAnalysis.xaml
扩展全局消息框基础设施以支持 AI 分析对话框,并暴露用于将其加入队列的辅助方法。
  • 向 MyMsgBoxType 添加 AiAnalysis 值,并在 MyMsgBoxTick 中路由到 MyMsgAiAnalysis 控件的创建。
  • 新增 ModMain.ShowCrashAiAnalysis 辅助方法,使用标题和内容入队一个 AI 分析消息框,并在 UI 线程上触发消息处理。
  • 在 ModMain 中注册 PageSetupAI 引用,用于缓存 AI 设置页面实例。
Plain Craft Launcher 2/Modules/ModMain.cs
在“工具”设置下添加 AI 崩溃分析配置,并通过现有配置系统持久化。
  • 定义 Config.Tool.AI 配置组,包含 Enabled、ApiType、BaseUrl、ModelId 以及加密的 ApiKey 字段。
  • 设置合理的默认值,包括 OpenAI v1 基础 URL 和默认模型 ID,并将 ApiType 以 int 存储,用于映射到不同的 API 风格。
PCL.Core/App/Config.cs
引入新的 AI 设置页,并将其集成到设置导航中,包括重置行为。
  • 创建 PageSetupAI 页面,将 AI 配置绑定到 UI 控件,支持重新加载,并允许通过 Config.Tool.AI.Reset 恢复默认值。
  • 将复选框、文本框和下拉框的变更通过控件 Tag 值挂接到 ModBase.Setup.Set,同时通过 AniControlEnabled 进行保护,以避免在程序化重新加载时写入。
  • 更新 PageSetupLeft,在可见时选择 AI 选项卡,处理 SetupAI 重置流程,将默认 PageID 回退设置为 SetupAI,并将 SetupAI 路由到延迟创建的 PageSetupAI 实例。
Plain Craft Launcher 2/Pages/PageSetup/PageSetupAI.xaml.cs
Plain Craft Launcher 2/Pages/PageSetup/PageSetupAI.xaml
Plain Craft Launcher 2/Pages/PageSetup/PageSetupLeft.xaml.cs
Plain Craft Launcher 2/Pages/PageSetup/PageSetupLeft.xaml
Plain Craft Launcher 2/FormMain.xaml.cs
在发布构建中导出实例时可选地复制 PCL 可执行文件,并复用共享工具。
  • 用 C# 实现替换已注释的 VB 风格导出逻辑,当 IncludePCL 为 true 时有条件地将启动器可执行文件复制到缓存文件夹中,使用 ModBase.CopyFile 和 ExePathWithName。
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.cs

技巧与命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 在回复审阅评论时请求 Sourcery 基于该评论创建一个 issue。你也可以回复审阅评论 @sourcery-ai issue 来从该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写上 @sourcery-ai 以在任何时间生成标题。你也可以在拉取请求中评论 @sourcery-ai title 以在任何时间(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写上 @sourcery-ai summary,即可在指定位置生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary 以在任何时间(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可在任何时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理了所有评论且不想再看到它们,这将非常有用。
  • 忽略所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审阅。特别适用于你想从一个新的审阅重新开始的场景——别忘了再评论 @sourcery-ai review 来触发新的审阅!

自定义你的体验

前往你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Adds configurable AI-based crash analysis using OpenAI-compatible APIs, integrates it into the crash dialog flow, and introduces a new settings page for AI tooling along with a dedicated AI analysis message dialog.

Sequence diagram for AI-based crash analysis flow

sequenceDiagram
    actor User
    participant ModCrash
    participant CrashAiAnalyzer
    participant ModMain
    participant MyMsgAiAnalysis
    participant Requester

    User->>ModCrash: Output(IsHandAnalyze, ExtraFiles)
    ModCrash->>ModCrash: BuildAiAnalysisText(resultText)
    ModCrash->>CrashAiAnalyzer: Start(aiLogText)
    CrashAiAnalyzer->>ModMain: ShowCrashAiAnalysis(TrimLog(logText))
    ModMain->>MyMsgAiAnalysis: new MyMsgAiAnalysis(converter)
    MyMsgAiAnalysis->>CrashAiAnalyzer: Analyze(logText)
    CrashAiAnalyzer->>Requester: Fetch(endpoint, FetchParam)
    Requester-->>CrashAiAnalyzer: JSON response
    CrashAiAnalyzer-->>MyMsgAiAnalysis: analysisText
    MyMsgAiAnalysis-->>User: Display AI crash analysis
Loading

File-Level Changes

Change Details Files
Integrate AI crash analysis entry point into existing crash dialog and build sanitized log payloads for AI.
  • Add BuildAiAnalysisText helper to compose local analysis, instance info, and multiple log sections into a single AI-friendly text with sensitive-data filtering.
  • Extend crash Output flow to show an 'AI 分析' primary button when AI is enabled, adjust secondary button behavior, and invoke CrashAiAnalyzer.Start with the prepared log text.
  • Introduce log filtering that masks access tokens, usernames, and bearer Authorization headers before sending text to AI.
Plain Craft Launcher 2/Modules/Minecraft/ModCrash.cs
Introduce CrashAiAnalyzer utility to talk to OpenAI-compatible APIs and select between Responses and Chat Completions endpoints.
  • Add CrashAiAnalyzer with configuration-driven enablement, API type selection, and log truncation logic to limit request size.
  • Implement Analyze methods that construct JSON payloads, call either /responses or /chat/completions endpoints, and parse varied response formats into a single text output.
  • Normalize base URLs to derive correct endpoints, including special handling for api.openai.com and robust error reporting when requests fail or responses lack usable text.
Plain Craft Launcher 2/Modules/Minecraft/ModCrashAi.cs
Add a dedicated AI crash analysis modal message control that runs the AI request asynchronously and displays results or errors.
  • Create MyMsgAiAnalysis control that starts a background LoaderTask to call CrashAiAnalyzer.Analyze and binds task state to a loading indicator.
  • Render AI analysis results as markdown, provide copy-to-clipboard support, and handle error display with unwrapped innermost exception messages.
  • Wire up modal open/close animations and integrate with the global message queue lifecycle, including background blur and drag-to-move handling.
Plain Craft Launcher 2/Controls/MyMsg/MyMsgAiAnalysis.xaml.cs
Plain Craft Launcher 2/Controls/MyMsg/MyMsgAiAnalysis.xaml
Extend global message box infrastructure to support AI analysis dialogs and expose a helper to enqueue them.
  • Add AiAnalysis value to MyMsgBoxType and route it in MyMsgBoxTick to create a MyMsgAiAnalysis control.
  • Introduce ModMain.ShowCrashAiAnalysis helper that enqueues an AI analysis box with title and content and triggers message processing when on UI thread.
  • Register a PageSetupAI reference in ModMain to cache the AI settings page instance.
Plain Craft Launcher 2/Modules/ModMain.cs
Add AI crash analysis configuration under Tool settings, persisted via existing config system.
  • Define Config.Tool.AI config group with Enabled, ApiType, BaseUrl, ModelId, and encrypted ApiKey fields.
  • Set sensible defaults, including OpenAI v1 base URL and a default model id, and store ApiType as an int for mapping to different API styles.
PCL.Core/App/Config.cs
Introduce a new AI settings page and integrate it into the setup navigation, including reset behavior.
  • Create PageSetupAI page that binds AI config to UI controls, supports reload, and allows resetting to defaults via Config.Tool.AI.Reset.
  • Hook checkbox, textbox, and combo changes to ModBase.Setup.Set using control Tag values, gated by AniControlEnabled to avoid writing during programmatic reloads.
  • Update PageSetupLeft to select AI tab when visible, handle SetupAI reset flow, set default PageID fallback to SetupAI, and route SetupAI to a lazily created PageSetupAI instance.
Plain Craft Launcher 2/Pages/PageSetup/PageSetupAI.xaml.cs
Plain Craft Launcher 2/Pages/PageSetup/PageSetupAI.xaml
Plain Craft Launcher 2/Pages/PageSetup/PageSetupLeft.xaml.cs
Plain Craft Launcher 2/Pages/PageSetup/PageSetupLeft.xaml
Plain Craft Launcher 2/FormMain.xaml.cs
Ensure PCL executable is optionally copied during instance export in release builds using shared utilities.
  • Replace commented VB-style export logic with a C# implementation that conditionally copies the launcher executable into the cache folder when IncludePCL is true, using ModBase.CopyFile and ExePathWithName.
Plain Craft Launcher 2/Pages/PageInstance/PageInstanceExport.xaml.cs

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些高层反馈:

  • 在 ModCrash.Output 中,Button2Action 逻辑现在依赖于字面文本“查看日志”(button2 != "查看日志" ? null : ...);建议使用一个专门的布尔标志来跟踪 Button2 是否应当打开日志,以避免当标签文本发生变化或被以不同方式本地化时产生 bug。
  • PageSetupAI.Reset 会调用两次 Reload()(一次是在 try 块中重置成功之后,另一次是在 catch 之后);你可以删除其中一次调用以避免重复工作。
  • 在 CrashAiAnalyzer.Start 中,初始的 if (!Config.Tool.AI.Enabled) return; 与在调用 Start 前外部的 CrashAiAnalyzer.IsEnabled 检查是重复的;建议将启用检查集中到一个地方,以简化控制流。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- In ModCrash.Output, the Button2Action logic now relies on the literal text "查看日志" (`button2 != "查看日志" ? null : ...`); consider using a dedicated boolean flag to track whether Button2 should open logs to avoid bugs if the label text changes or is localized differently.
- PageSetupAI.Reset calls Reload() twice (once in the try block after successful reset and again after the catch); you can remove one of these calls to avoid redundant work.
- In CrashAiAnalyzer.Start, the initial `if (!Config.Tool.AI.Enabled) return;` is redundant with the external `CrashAiAnalyzer.IsEnabled` check before calling Start; consider centralizing the enabled-check in one place to keep the control flow simpler.

Sourcery 对开源项目免费——如果你喜欢我们的评审,请考虑分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • In ModCrash.Output, the Button2Action logic now relies on the literal text "查看日志" (button2 != "查看日志" ? null : ...); consider using a dedicated boolean flag to track whether Button2 should open logs to avoid bugs if the label text changes or is localized differently.
  • PageSetupAI.Reset calls Reload() twice (once in the try block after successful reset and again after the catch); you can remove one of these calls to avoid redundant work.
  • In CrashAiAnalyzer.Start, the initial if (!Config.Tool.AI.Enabled) return; is redundant with the external CrashAiAnalyzer.IsEnabled check before calling Start; consider centralizing the enabled-check in one place to keep the control flow simpler.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In ModCrash.Output, the Button2Action logic now relies on the literal text "查看日志" (`button2 != "查看日志" ? null : ...`); consider using a dedicated boolean flag to track whether Button2 should open logs to avoid bugs if the label text changes or is localized differently.
- PageSetupAI.Reset calls Reload() twice (once in the try block after successful reset and again after the catch); you can remove one of these calls to avoid redundant work.
- In CrashAiAnalyzer.Start, the initial `if (!Config.Tool.AI.Enabled) return;` is redundant with the external `CrashAiAnalyzer.IsEnabled` check before calling Start; consider centralizing the enabled-check in one place to keep the control flow simpler.

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.

Copy link
Copy Markdown
Member

@MoYuan-CN MoYuan-CN left a comment

Choose a reason for hiding this comment

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

在此 PR 被进一步讨论之前,需要先 Resolve 以下问题:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不应当在一个 PR 内处理多个内容。把这个更改撤销了。

@MapleLeaf2007
Copy link
Copy Markdown
Author

已撤销对于"Plain Craft Launcher 2\Pages\PageInstance\PageInstanceExport.xaml.cs"文件的更改

Copy link
Copy Markdown
Member

@Big-Cake-jpg Big-Cake-jpg left a comment

Choose a reason for hiding this comment

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

怎么感觉这代码像是 AI 写的……

另外就是,我不认为 AI 分析 Minecraft 崩溃时能起到什么作用。高级用户会自行排查错误,用不着填 API Key 和 baseURL 花自己的钱让 AI 分析;普通用户也大概率不了解自行配置 AI 功能所需要的知识。社区也并没有多余资金用于提供这类服务。

如果 AI 能够有效分析 Minecraft 的错误日志而不是胡说八道,那 No AI Guess 这类模组也许就没有存在的必要了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XL PR 大小评估:超大型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants