Skip to content

feat(BetterGI): 「脚本配置」来源共享脚本级一条龙编排 - #796

Open
TCddddd wants to merge 5 commits into
AUTO-MAS-Project:devfrom
TCddddd:feat/bettergi-script-config-source
Open

TCddddd wants to merge 5 commits into
AUTO-MAS-Project:devfrom
TCddddd:feat/bettergi-script-config-source

Conversation

@TCddddd

@TCddddd TCddddd commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

概述

补齐 BetterGI 的「脚本配置」来源:此前 Info.Mode = '脚本' 可以选、可以存,但运行时从不判断脚本与用户的区别,选了等于「用户独立配置」。本 PR 让「脚本」来源真正生效——该来源的用户共用脚本级的一份一条龙编排,改一处所有选它的用户一起变。

用户可见的改动

  • 来源选「脚本配置」的用户:队列、内置分组、自定义分组、队伍与战斗策略、任务设置(含秘境/幽境危战的副本设置)在 MAS 侧只维护一份,所有选该来源的用户共用
  • 来源选「用户独立配置」的用户:行为与改动前逐字不变
  • 直控用户:行为不变(仍走 BGI 原生配置)
  • 任务配置卡片内新增一条说明提示,避免用户误以为改动只影响自己

设计

一条龙编排与用户级设置分开存放,只有编排走脚本级:

配置段 来源「脚本」 来源「用户」
OneDragon(队列 / 内置分组 / 自定义分组 / 队伍与战斗策略 / 任务设置) 脚本级共用一份 各用户一份
Info / Task / Switch(名称、账号、UID、备注…) 仍是用户自己的 自己的
  • 模型:脚本级 BetterGIConfig 新增与用户配置同段、同名、同默认值的 OneDragon 段;新增字段必须两处同步,test_script_and_user_one_dragon_sections_stay_in_sync 会在漏改时变红
  • 接口:只改通用 get_user / update_user 两个口子(读时用脚本级段覆盖、写时把 OneDragon 整段路由过去),再带上战斗 4 项(Plan)与秘境 / 幽境危战副本的读写点;前端无需改动(返回结构不变)
  • 运行时AutoProxy 按来源解析 owner_user_id(脚本级 = 保留 id Default,与 MAA 的 data/{script_id}/Default/ 惯例同构)与 owner_config;per-user 文件副本、物化配置组前缀、残留清理同口径
  • 安全边界_validate_user_id 只单独放行 Default 这一个字面量,仍拒绝 .. 与路径分隔符(附回归测试)

与「快速配置」的关系

两者正交,本次不改动快速配置:

  • 快速配置(Info.IfQuickConfig 决定「要不要用 MAS 配置」(关 = 跑 BGI 原生一条龙)
  • 配置来源(Info.Mode 决定「用谁的编排」(脚本 = 共用一份,用户 = 各一份)

因此实际生效条件是:快速配置开启 + 来源为「脚本」。

验证

  • 后端 tests/task + tests/api693 passed(含本 PR 新增 16 个用例:owner 解析、共享语义、路径穿越防护、段对齐)
  • 前端 vitest:63 files / 578 passedvue-tsc 退出码 0
  • scripts/changelog.py check 通过;py_compile 与 eslint 无新增问题
  • 本地仅剩 5 项 Windows 环境性失败(缺 pytest-asyncio、GBK 默认编码),CI 的 Linux/UTF-8 不受影响

未包含

  • 真机联调(建议:同一脚本下两个用户分别设「脚本」/「用户」,改队列确认只有脚本那个跟着变)
  • 若维护者希望「脚本」来源也覆盖 Info / Task 段的某些字段,可在此基础上扩展,本 PR 只收敛到一条龙编排

Sourcery 摘要

为 BetterGI OneDragon 编排启用脚本级共享,同时保留用户特定设置以及现有的独立控制或直接控制行为。

新功能:

  • 启用 BetterGI 的“脚本配置”来源,使所有选择该来源的用户共享一个 OneDragon 编排,包括队列、分组、队伍、战斗策略和任务设置。

错误修复:

  • 使之前无法正常工作的脚本配置来源影响运行时读取、写入以及生成的 BetterGI 配置副本。

增强功能:

  • 保持用户身份和账户元数据的用户特定性,同时通过脚本级所有者处理共享编排。
  • 保留独立用户和直接控制行为,同时应用一致的所有权和清理语义。
  • 添加本地化 UI 指引,说明对脚本来源编排所做的更改会影响所有使用该来源的用户。

测试:

  • 增加对基于来源的所有者路由、共享配置与用户特定配置路径、模型分区对齐以及保留所有者路径遍历保护的覆盖测试。
Original summary in English

Sourcery 摘要

启用 BetterGI OneDragon 编排的脚本级共享,同时保留用户特定设置和现有配置模式。

新功能:

  • 启用 BetterGI 的脚本配置源,使所有选择该配置源的用户共享同一个 OneDragon 编排,包括队列、组、队伍、战斗策略和任务设置。

错误修复:

  • 使之前无法正常工作的脚本配置源影响运行时配置的读取、写入以及生成的 BetterGI 配置副本。

增强功能:

  • 在保持用户身份和账户元数据分离的同时,通过脚本级所有者路由共享编排。
  • 保留与用户无关的配置和直接控制用户的现有行为。
  • 在 BetterGI 配置界面中添加说明,解释脚本级编排的更改会影响所有使用该配置源的用户。

测试:

  • 增加对基于配置源的所有者路由、共享配置和用户特定配置路径、模型区段对齐,以及保留所有者路径遍历保护的测试覆盖。
Original summary in English

Summary by Sourcery

Enable script-level sharing for BetterGI OneDragon orchestration while preserving user-specific settings and existing configuration modes.

New Features:

  • Enable BetterGI's script configuration source to share one OneDragon orchestration across all users who select it, including queues, groups, teams, combat strategies, and task settings.

Bug Fixes:

  • Make the previously non-functional script configuration source affect runtime configuration reads, writes, and generated BetterGI configuration copies.

Enhancements:

  • Keep user identity and account metadata separate while routing shared orchestration through a script-level owner.
  • Preserve existing behavior for user-independent configuration and direct-control users.
  • Add guidance in the BetterGI configuration UI explaining that script-level orchestration changes affect all users using that source.

Tests:

  • Add coverage for source-based owner routing, shared and user-specific configuration paths, model section alignment, and reserved-owner path traversal protection.

为「脚本配置」来源(`Info.Mode='脚本'`)打基础:per-user 副本以后可以落在脚本级目录
`data/{script_id}/Default/...`,与 MAA 的 `data/{script_id}/Default/ConfigFile` 同构。

- `one_dragon.py`:新增 `SCRIPT_LEVEL_OWNER = "Default"` 与 `owner_user_id(user_id, mode)`,
  统一「按来源决定副本维度」的口径(脚本 = 脚本级共享;用户 / 直控 = 该用户自己的副本)
- `_validate_user_id`:单独放行 `SCRIPT_LEVEL_OWNER` 这一个字面量;仍拒绝 `..` 与路径分隔符,
  目录穿越的安全边界不变(附回归测试)
- 单元测试:owner 解析、两个用户命中同一份脚本级副本而用户级各归各、非法 id 仍被拒绝

本提交只建立维度与安全边界,尚未接线到运行时与接口(见后续提交)。
「脚本」来源的用户改为共读共写脚本级那一份 per-user 副本(`data/{script_id}/Default/...`),
「用户」来源保持不变;直控不读 MAS 副本。

- `api/scripts.py`:新增 `_bettergi_owner_id(script_config, user_id)`,读该用户的
  `Info.Mode` 后用 `one_dragon.owner_user_id` 解析;沿用 `_bettergi_user_id` 做
  「用户是否存在」校验,两者职责分离
- 三条真正读写 per-user 副本的链路接上 owner:一条龙设置读取(GET settings)、
  保存(POST settings 的原生副本部分)、自定义配置组列表(custom-groups)
- 其余 `_bettergi_user_id` 调用保持传真实 userId,不参与副本维度

尚未接线:运行时(AutoProxy / ScriptConfig 的物化与快照)与前端文案见后续提交。
来源选「脚本」的用户,其一条龙编排不再各存一份:队列、内置分组、自定义分组、队伍与
战斗策略、任务设置副本统一读写脚本级存储,改一处所有选该来源的用户一起生效。
来源为「用户」的用户行为逐字不变;直控仍走 BGI 原生配置。

- `app/models/config.py`:脚本级 `BetterGIConfig` 增加与用户配置同段、同名、同默认值的
  OneDragon 段(新增字段必须两处同步,`test_script_and_user_one_dragon_sections_stay_in_sync`
  会在漏改时变红)
- `app/api/scripts.py`:
  - 新增 `_bettergi_uses_script_source` / `_bettergi_owner_config` /
    `_bettergi_apply_script_level_source`,按来源解析编排读写对象
  - 读取:通用 `get_user` 对脚本来源用户用脚本级段覆盖 OneDragon 段
    (Info / Task / Switch 仍是各用户自己的)
  - 写入:通用 `update_user` 把 OneDragon 整段路由到脚本级;队列变更时的 Plan 孤儿清理
    按同一来源读取,避免读到别的用户的旧 Plan
  - 战斗 4 项(Plan)与秘境 / 幽境危战副本的读写一并改走 owner
- `app/task/BetterGI/AutoProxy.py`:新增 `config_mode` / `owner_user_id` / `owner_config`;
  13 处编排字段读取、4 处 per-user 副本调用与物化组前缀全部按来源解析
- `app/task/BetterGI/ScriptConfig.py`:残留物化组清理按 owner 前缀
- 测试:段对齐 + owner 路由(脚本 → 脚本级;用户 / 直控 → 用户配置)
- 新增 changelog 碎片(面向用户的一句话)

前端无需改动:接口返回的数据结构与改动前一致。
- `BetterGIUserEdit.vue`:任务配置卡片内新增一条 info 提示(仅 `Mode === '脚本'` 时显示),
  说明一条龙编排在本来源下是脚本级共用的一份、改动会影响所有选该来源的用户,
  而用户级设置(名称/账号/UID 等)仍各自独立
- i18n:zh-CN / en-US / ja-JP 三语补齐 `bettergiScriptModeShared` 与
  `bettergiScriptModeSharedHint`

验证:frontend vitest 63 files / 578 tests passed;vue-tsc 退出码 0;eslint 无新增问题。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @TCddddd, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 21 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 15, 2026

Copy link
Copy Markdown

审查者指南

此 PR 通过引入脚本级 OneDragon 配置段,并将所有相关 API、运行时实例化、Plan 和秘境设置操作通过共享的 Default 所有者进行路由,使 BetterGI 的「脚本配置」源正式可用,同时保留用户元数据、用户独立模式、直接控制以及现有前端数据契约不变。

共享 OneDragon 配置读写的时序图

sequenceDiagram
    participant User as User
    participant API as BetterGIAPI
    participant Config as RuntimeBetterGIConfig
    participant Shared as ScriptLevelOneDragon
    participant UserConfig as UserConfig

    User->>API: get_user
    API->>Config: read Info.Mode
    alt Mode is 脚本
        Config-->>API: shared OneDragon section
        API-->>User: user metadata + shared OneDragon
    else Mode is 用户
        Config-->>API: user OneDragon section
        API-->>User: user configuration
    end

    User->>API: update_user
    alt Mode is 脚本
        API->>Config: update OneDragon
        Config->>Shared: write script-level OneDragon
        API->>UserConfig: update Info / Task / Switch
    else Mode is 用户
        API->>UserConfig: update user configuration
    end
Loading

文件级变更

变更 详情 文件
通过依赖配置源的所有者路由 BetterGI OneDragon 的读写,使脚本源共享一个脚本级配置,同时保留用户级元数据以及独立/直接控制行为。
  • 新增用于检测配置源、选择脚本级或用户级所有者配置,以及在用户响应中叠加共享 OneDragon 数据的辅助方法。
  • 将队列、分组、队伍、战斗 Plan 设置、领域/深渊设置以及实例化的用户文件路由到选定的所有者。
  • 保留由实际用户负责的 Info/Task/Switch 和用户校验;对于脚本源,仅将 OneDragon 配置段的写入路由到脚本级配置。
app/api/scripts.py
app/task/BetterGI/AutoProxy.py
app/task/BetterGI/ScriptConfig.py
app/task/BetterGI/tools/one_dragon.py
新增脚本级 OneDragon 配置模型,使其与用户级配置段保持一致,从而提供共享的持久化目标。
  • 定义匹配的分组、队列、队伍、策略、任务、执行层和 Plan 字段,并同步默认值。
  • 新增回归测试,要求脚本级和用户级 OneDragon 配置段始终保持一致。
app/models/config.py
tests/api/test_bettergi_script_config_source.py
建立并测试用于共享 BetterGI 构件的保留脚本级所有者路径。
  • 对脚本源用户使用保留的 Default 所有者;对用户源和直接控制源则保留各自的用户所有者。
  • 除 UUID 用户 ID 外,仅允许使用 Default,同时继续拒绝路径遍历和路径分隔符。
  • 通过测试覆盖共享与独立构件路径以及所有者解析。
app/task/BetterGI/tools/one_dragon.py
tests/task/test_bettergi_script_level_owner.py
在 BetterGI 用户配置界面和发布说明中说明共享脚本行为。
  • 为中文、英文和日文的脚本源用户新增本地化说明提示。
  • 说明选择脚本源的所有用户都会受到 OneDragon 配置变更的影响,而用户身份字段仍保持独立。
frontend/src/views/EditView/User/BetterGIUserEdit.vue
frontend/src/i18n/locales/zh-CN.ts
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/ja-JP.ts
changelog.d/bettergi-script-config-source.feat.md

提示和命令

与 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

This PR makes BetterGI’s 「脚本配置」 source functional by introducing a script-level OneDragon section and routing all relevant API, runtime materialization, Plan, and dungeon-setting operations through a shared Default owner, while leaving user metadata, user-independent mode, direct control, and the existing frontend data contract intact.

Sequence diagram for shared OneDragon configuration reads and writes

sequenceDiagram
    participant User as User
    participant API as BetterGIAPI
    participant Config as RuntimeBetterGIConfig
    participant Shared as ScriptLevelOneDragon
    participant UserConfig as UserConfig

    User->>API: get_user
    API->>Config: read Info.Mode
    alt Mode is 脚本
        Config-->>API: shared OneDragon section
        API-->>User: user metadata + shared OneDragon
    else Mode is 用户
        Config-->>API: user OneDragon section
        API-->>User: user configuration
    end

    User->>API: update_user
    alt Mode is 脚本
        API->>Config: update OneDragon
        Config->>Shared: write script-level OneDragon
        API->>UserConfig: update Info / Task / Switch
    else Mode is 用户
        API->>UserConfig: update user configuration
    end
Loading

File-Level Changes

Change Details Files
Route BetterGI OneDragon reads and writes through a source-dependent owner, making the script source share one script-level configuration while preserving user-level metadata and independent/direct-control behavior.
  • Added helpers to detect configuration source, select script-level versus user-level owner configuration, and overlay shared OneDragon data on user responses.
  • Routed queues, groups, teams, combat Plan settings, domain/stygian settings, and materialized per-user files through the selected owner.
  • Kept Info/Task/Switch and user validation on the actual user, while routing script-source writes only for the OneDragon section.
app/api/scripts.py
app/task/BetterGI/AutoProxy.py
app/task/BetterGI/ScriptConfig.py
app/task/BetterGI/tools/one_dragon.py
Added a script-level OneDragon configuration model that mirrors the user-level section to provide a shared persistence target.
  • Defined matching groups, queue, team, strategy, task, execution-layer, and Plan fields with synchronized defaults.
  • Added a regression test requiring the script- and user-level OneDragon sections to remain identical.
app/models/config.py
tests/api/test_bettergi_script_config_source.py
Established and tested the reserved script-level owner path for shared BetterGI artifacts.
  • Used the reserved Default owner for script-source users and preserved per-user owners for user and direct-control sources.
  • Allowed only Default in addition to UUID user IDs, retaining traversal and path-separator rejection.
  • Covered shared versus independent artifact paths and owner resolution with tests.
app/task/BetterGI/tools/one_dragon.py
tests/task/test_bettergi_script_level_owner.py
Communicated the shared-script behavior in the BetterGI user configuration UI and release notes.
  • Added localized explanatory alerts for script-source users in Chinese, English, and Japanese.
  • Documented that OneDragon changes affect all users selecting the script source while user identity fields remain separate.
frontend/src/views/EditView/User/BetterGIUserEdit.vue
frontend/src/i18n/locales/zh-CN.ts
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/ja-JP.ts
changelog.d/bettergi-script-config-source.feat.md

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

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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