fix(galgame): 统一 JSON 修正提示并新增 locale 检查工具#1461
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough新增 RapidOCR 语言切换的多语言文案、将 LLM 后端 JSON 纠错提示英文化并同步测试哈希,同时新增 compare_locales.py 脚本以校验 locale 键与占位符一致性喵。 Changes本地化增强与校验工具完善
Sequence Diagram(s)sequenceDiagram
participant User as CLI 用户
participant Main as main()
participant ArgParse as argparse 参数解析
participant DefaultDirs as _default_locale_dirs()
participant CompareDir as _compare_locale_dir()
participant LoadFile as _load_locale_file()
participant Flatten as _flatten_json()
participant Report as _report_results()
User->>Main: 运行 compare_locales.py [locale_dirs] [--strict-all]
Main->>ArgParse: 解析命令行参数
ArgParse-->>Main: (locale_dirs, strict_all)
alt locale_dirs 为空
Main->>DefaultDirs: 获取默认 locale 目录
DefaultDirs-->>Main: [static/locales, plugin/*/i18n]
else 有自定义目录
Main-->>Main: 使用用户指定目录
end
loop 对每个 locale_dir
alt 目录存在
Main->>CompareDir: 检查该 locale_dir
loop 对每个预期语言(en, ja, ko...)
CompareDir->>LoadFile: 加载 {locale}.json
LoadFile->>Flatten: 递归展平 JSON
Flatten-->>LoadFile: {path.to.key: value}
LoadFile-->>CompareDir: 扁平化映射
end
CompareDir->>CompareDir: 计算 key 并集
CompareDir->>CompareDir: 检测缺失 key(按语言)
CompareDir->>CompareDir: 统计占位符{...}多重集
CompareDir->>CompareDir: 对比占位符一致性
CompareDir-->>Main: [warnings, errors]
else 目录不存在
Main-->>Main: 标记为 SKIP
end
end
Main->>Report: 汇总检查结果并打印
Report->>Report: 输出 SKIP/WARNING/ERROR 列表
Report->>Report: 输出检查/跳过统计
Report-->>Main: 返回退出码(0 或 1)
Main->>User: sys.exit(返回码)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 44f67ea914
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if not _has_expected_locale_files(locale_dir): | ||
| skipped.append(locale_dir) | ||
| continue |
There was a problem hiding this comment.
Fail when expected locale files are missing
Do not skip directories that are missing one or more expected locale files. In main, directories failing _has_expected_locale_files(...) are added to skipped and never reported as errors, so deleting es.json/pt.json from the required Galgame i18n directory would still let the tool exit successfully (Locale comparison passed) and silently bypass the consistency check this script is meant to enforce.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
README.MD (2)
79-82: ⚖️ Poor tradeoff建议提升安全警告的可见性喵~
这段安全警告非常重要,但目前只是作为一个引用块放在快速开始部分之后,用户可能会忽略掉喵。考虑以下改进建议喵:
- 添加醒目的警告图标: 在标题前加上
⚠️ 或 🔒 等图标- 考虑独立的安全章节: 如果后续还有其他安全相关的内容,可以创建专门的"🔒 安全注意事项"章节
- 澄清适用范围: 明确说明这是否适用于所有插件,还是仅针对特定插件(当前措辞有点模糊喵)
💡 改进示例喵
-> **插件安装安全**:插件安装类端点(例如 `plugin/plugins/galgame_plugin/install_routes.py` +> ⚠️ **插件安装安全(重要)**:所有插件安装类端点(例如 `plugin/plugins/galgame_plugin/install_routes.py` > 中的安装启动 API)必须只在已认证/已授权的插件服务中暴露,或确保服务仅绑定到 > `localhost`。不要将未加认证的安装端点暴露给 LAN 或公网,避免未授权主机触发 > 二进制下载或安装流程。或者创建独立章节:
## 🔒 安全注意事项 ### 插件安装端点安全 插件安装类端点必须采取以下安全措施之一: - 启用认证和授权机制 - 仅绑定到 `localhost` (127.0.0.1) **⚠️ 重要**: 请勿将未加认证的安装端点暴露到局域网或公网,这可能导致: - 未授权的二进制文件下载 - 恶意软件安装 - 系统安全风险 **示例**: `plugin/plugins/galgame_plugin/install_routes.py` 中的安装 API🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.MD` around lines 79 - 82, The security warning about plugin installation endpoints is easy to miss; update README.MD by elevating that quoted block into a more prominent, dedicated "🔒 安全注意事项" section (or at least prepend a warning icon like ⚠️/🔒 to the heading), clarify its scope (state whether it applies to all plugins vs specific ones), and include the concrete example reference to plugin/plugins/galgame_plugin/install_routes.py so readers know which install_route endpoints are sensitive; ensure the text explicitly lists required mitigations (authentication/authorization or binding to localhost) and a short "DO NOT expose to LAN/Internet" admonition.
79-82: ⚡ Quick win确认 README 的安装端点示例路径准确无误,并建议提升文案清晰度喵
plugin/plugins/galgame_plugin/install_routes.py在仓库中存在,且确实包含安装相关路由(例如/plugin/{plugin_id}/ui-api/textractor/install、/ui-api/tesseract/install、/ui-api/rapidocr-models的 POST(启动)与 GET(latest/stream)等)喵- README 里“安装启动 API”与该文件中对应的 POST
/.../install路由语义匹配;可考虑把“安装启动 API”再点名到具体资源(textractor/tesseract 任一)以减少读者误解喵- 目前该安全警告放在 Windows/macOS 快速启动之后、Docker 之前,整体顺序合理;如需更醒目,可考虑把它独立成“安全注意事项”小节喵
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@README.MD` around lines 79 - 82, Update README.MD to confirm the example path and clarify the wording: verify that plugin/plugins/galgame_plugin/install_routes.py is the correct example and explicitly reference one of the POST install routes (e.g., /plugin/{plugin_id}/ui-api/textractor/install or /ui-api/tesseract/install) when mentioning the “安装启动 API” so readers know which resource is meant, and consider moving or elevating the warning into a distinct “安全注意事项” subsection to make the guidance about binding to localhost or restricting install endpoints to authenticated/authorized plugin services more prominent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@README.MD`:
- Around line 79-82: The security warning about plugin installation endpoints is
easy to miss; update README.MD by elevating that quoted block into a more
prominent, dedicated "🔒 安全注意事项" section (or at least prepend a warning icon
like ⚠️/🔒 to the heading), clarify its scope (state whether it applies to all
plugins vs specific ones), and include the concrete example reference to
plugin/plugins/galgame_plugin/install_routes.py so readers know which
install_route endpoints are sensitive; ensure the text explicitly lists required
mitigations (authentication/authorization or binding to localhost) and a short
"DO NOT expose to LAN/Internet" admonition.
- Around line 79-82: Update README.MD to confirm the example path and clarify
the wording: verify that plugin/plugins/galgame_plugin/install_routes.py is the
correct example and explicitly reference one of the POST install routes (e.g.,
/plugin/{plugin_id}/ui-api/textractor/install or /ui-api/tesseract/install) when
mentioning the “安装启动 API” so readers know which resource is meant, and consider
moving or elevating the warning into a distinct “安全注意事项” subsection to make the
guidance about binding to localhost or restricting install endpoints to
authenticated/authorized plugin services more prominent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 27ba2d31-e95d-47e0-9fe8-934277fa766e
📒 Files selected for processing (12)
README.MDplugin/plugins/galgame_plugin/i18n/en.jsonplugin/plugins/galgame_plugin/i18n/ja.jsonplugin/plugins/galgame_plugin/i18n/ko.jsonplugin/plugins/galgame_plugin/i18n/ru.jsonplugin/plugins/galgame_plugin/i18n/zh-CN.jsonplugin/plugins/galgame_plugin/i18n/zh-TW.jsonplugin/plugins/galgame_plugin/llm_backend.pyplugin/tests/unit/plugins/test_galgame_i18n.pyplugin/tests/unit/plugins/test_galgame_llm_backend.pyplugin/tests/unit/plugins/test_galgame_llm_json_correction.pyplugin/tools/compare_locales.py
44f67ea to
a523e23
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a523e236cb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if not locale_dir.exists(): | ||
| skipped.append(locale_dir) | ||
| continue |
There was a problem hiding this comment.
Fail on missing user-specified locale directories
When a path is passed via locale_dirs, a typo or stale CI path is silently treated as SKIP and the script can still exit 0 (Locale comparison passed). This makes explicit checks unreliable because the requested directory is never validated; for example, python plugin/tools/compare_locales.py /tmp/not_exists_dir currently succeeds. Since custom_locale_dirs already switches other checks to strict mode, nonexistent user-supplied directories should also be reported as errors.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugin/tools/compare_locales.py`:
- Around line 233-237: _wrap the call to _compare_locale_dir(locale_dir) in a
try/except so a RuntimeError from one locale file doesn’t abort the whole scan;
catch RuntimeError as e, create a descriptive issue string referencing
locale_dir and the exception, and then extend either errors or warnings with
that single-item list using the same decision logic currently based on
args.strict_all, custom_locale_dirs, or _is_default_required_dir(root,
locale_dir) (keep using the same variables: issues, errors, warnings,
_compare_locale_dir, args.strict_all, custom_locale_dirs,
_is_default_required_dir, root, locale_dir), then continue to the next
directory.
- Around line 218-220: The code currently treats a non-existent locale_dir as
quietly skipped by appending to skipped; change this so missing custom
directories are treated as an error: in the loop where locale_dir is checked
(the block referencing locale_dir and skipped), detect if the path does not
exist and record/log it as an error (e.g., add to an errors list or call
logger.error/raise ValueError/exit with a clear message) instead of appending to
skipped; ensure downstream logic that reports failures will surface this
missing-path condition rather than hiding it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 60ed98ad-7b36-4ca2-9b68-54d95d3a05c7
📒 Files selected for processing (11)
plugin/plugins/galgame_plugin/i18n/en.jsonplugin/plugins/galgame_plugin/i18n/ja.jsonplugin/plugins/galgame_plugin/i18n/ko.jsonplugin/plugins/galgame_plugin/i18n/ru.jsonplugin/plugins/galgame_plugin/i18n/zh-CN.jsonplugin/plugins/galgame_plugin/i18n/zh-TW.jsonplugin/plugins/galgame_plugin/llm_backend.pyplugin/tests/unit/plugins/test_galgame_i18n.pyplugin/tests/unit/plugins/test_galgame_llm_backend.pyplugin/tests/unit/plugins/test_galgame_llm_json_correction.pyplugin/tools/compare_locales.py
✅ Files skipped from review due to trivial changes (5)
- plugin/plugins/galgame_plugin/i18n/en.json
- plugin/plugins/galgame_plugin/i18n/zh-CN.json
- plugin/plugins/galgame_plugin/llm_backend.py
- plugin/plugins/galgame_plugin/i18n/ru.json
- plugin/tests/unit/plugins/test_galgame_llm_json_correction.py
a523e23 to
49da423
Compare
- use an English JSON correction prompt and update prompt tests - add locale consistency checker with strict handling for required/custom dirs - fill missing galgame RapidOCR language locale entries
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49da423023
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| warnings.append(issue) | ||
| continue | ||
| checked.append(locale_dir) | ||
| issues = _compare_locale_dir(locale_dir) |
There was a problem hiding this comment.
Catch locale parse errors instead of crashing scan
Wrap _compare_locale_dir(locale_dir) in error handling and convert RuntimeError into an issue entry, because _load_locale_file can raise on malformed/unreadable JSON and main currently lets that exception escape. In that case the script prints a traceback and stops scanning remaining directories, which bypasses the warning/error policy (notably for non-required plugin locales that are intended to be warning-only by default) and makes CI output much less actionable.
Useful? React with 👍 / 👎.
49da423 to
43228de
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43228de10c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if project_locale_dir.exists(): | ||
| dirs.append(project_locale_dir) |
There was a problem hiding this comment.
Report missing required locale directories
_default_locale_dirs only returns locale directories that already exist, so the default scan never sees a required path if it was deleted. In that case (for example static/locales or plugin/plugins/galgame_plugin/i18n missing), main() has nothing to validate for that path and can still exit successfully, which defeats this tool’s role as a CI guard for required locale trees.
Useful? React with 👍 / 👎.
变更内容
本 PR 按
galgame-pr6-misc-fixes实施 3 项独立小修:统一 JSON 修正提示词语言
llm_backend.py中"JSON 修正请求"改为"JSON correction attempt"新增 locale 一致性检查工具
plugin/tools/compare_locales.pystatic/locales/、plugin/plugins/*/locales/、plugin/plugins/*/i18n/{placeholder}一致性补充安装端点安全说明
localhost额外修复
galgame_set_rapidocr_lang在 6 个 locale 中缺失的 i18n 文案验证
uv run python -m py_compile plugin/tools/compare_locales.pyuv run python plugin/tools/compare_locales.pyuv run python plugin/tools/compare_locales.py plugin/plugins/galgame_plugin/i18nuv run python -m pytest plugin/tests/unit/plugins/test_galgame_i18n.py plugin/tests/unit/plugins/test_galgame_llm_backend.py plugin/tests/unit/plugins/test_galgame_llm_json_correction.py -q结果:相关测试
29 passed。Summary by CodeRabbit