Skip to content

feat(oknte): oknte接入运行节点采集并允许推送至任务报告 - #437

Open
AthenaHibou wants to merge 20 commits into
AUTO-MAS-Project:devfrom
AthenaHibou:feat/ok-nte-logbox
Open

feat(oknte): oknte接入运行节点采集并允许推送至任务报告#437
AthenaHibou wants to merge 20 commits into
AUTO-MAS-Project:devfrom
AthenaHibou:feat/ok-nte-logbox

Conversation

@AthenaHibou

@AthenaHibou AthenaHibou commented Aug 28, 2026

Copy link
Copy Markdown
  • OK-NTE专项 运行日志关键节点采集推送至任务报告:
  • 接入通用 log_box,日常任务各子任务逐节点展示成功/跳过/失败,并附刷完剩余体力。
  • 支持用户级「是否采集节点详情」开关,关闭即不创建采集(省开销)、报告不含节点详情。
  • 附属 Skill 完善
image

Sourcery 总结

支持收集 OK-NTE 运行时节点详情,并将其包含在任务报告中,同时提供按用户配置的可选收集开关。

新功能:

  • 将 OK-NTE 运行时节点收集结果添加到任务报告中,包括每个子任务的成功、跳过、失败和剩余体力详情。
  • 添加按用户配置的设置,用于启用或禁用节点详情收集,并在 OK-NTE 用户配置界面中提供该设置。

增强功能:

  • 将 OK-NTE 节点收集集成到共享日志收集和报告聚合流程中。
  • 改进专用适配器指南,确保收集的日志既完成聚合,也已追加到通知中。

文档:

  • 记录从日志收集到注入报告的完整流程及其所需的集成点。
Original summary in English

Sourcery 总结

启用可选的 OK-NTE 运行时节点收集功能,并将生成的详细信息纳入任务报告。

新功能:

  • 在任务报告中添加 OK-NTE 运行时节点详细信息和剩余耐力。
  • 添加按用户设置的选项,用于启用或禁用节点详细信息收集。

改进:

  • 将 OK-NTE 日志收集集成到共享的报告聚合和通知流程中。
  • 改进专用适配器指南,以完成从日志收集到报告生成的完整流程。

文档:

  • 记录基于日志的报告详细信息所需的聚合和通知集成点。
Original summary in English

Summary by Sourcery

Enable optional OK-NTE runtime node collection and include the resulting details in task reports.

New Features:

  • Add OK-NTE runtime node details and remaining stamina to task reports.
  • Add a per-user setting to enable or disable node-detail collection.

Enhancements:

  • Integrate OK-NTE log collection with the shared report aggregation and notification flows.
  • Improve specialized-adapter guidance for completing the log collection-to-report pipeline.

Documentation:

  • Document the required aggregation and notification integration points for log-based report details.

日常任务各子任务逐节点展示成功/跳过/失败并附刷完剩余体力;支持用户级「是否采集节点详情」开关,manager 聚合 build_push_log_text + notify append_push_log 两端注入。
明确 manager.final_task 聚合 build_push_log_text 与 tools/notify.py 追加 append_push_log 缺一不可,避免仅采集不注入导致报告无节点(OK-NTE 曾漏接)。
@sourcery-ai

sourcery-ai Bot commented Aug 28, 2026

Copy link
Copy Markdown

审查者指南

本 PR 将 OK-NTE 的运行日志接入通用 log_box,在用户级开关控制下采集并归并日常任务节点状态及剩余体力,随后通过任务聚合和通知正文双端注入任务报告,同时新增前端配置入口并补充相关接入文档。

OK-NTE 节点采集和任务报告交付时序图

sequenceDiagram
    participant User
    participant AutoProxyTask
    participant log_box
    participant UserPushLog
    participant Manager
    participant Notify

    User->>AutoProxyTask: prepare()
    alt PushLogEnabled
        AutoProxyTask->>log_box: get_collect(paths, sink, start_from_end)
        AutoProxyTask->>log_box: open()
        AutoProxyTask->>log_box: collect(OKNTE_PUSH_RULES)
        log_box-->>UserPushLog: _append_push_log(log_type, text)
        AutoProxyTask->>log_box: close(oknte_resolve)
        log_box-->>UserPushLog: resolved node statuses and stamina
    else PushLogEnabled disabled
        AutoProxyTask->>AutoProxyTask: skip log_box creation
    end
    Manager->>Manager: final_task()
    Manager->>Manager: build_push_log_text(user_list, has_uncompleted)
    Manager->>Notify: push_plyer(message with push_log)
    Notify->>Notify: append_push_log(message_text, message.get(push_log))
Loading

OK-NTE 节点状态解析流程图

flowchart LR
    Log["OK-NTE runtime log"] --> Rules["OKNTE_PUSH_RULES"]
    Rules --> Events["Success / skip / failure / stamina markers"]
    Events --> Resolve["oknte_resolve"]
    Resolve --> Status["Final node status\nfailure > skipped > success"]
    Resolve --> Stamina["Remaining stamina\ncurrent - target"]
    Status --> PushLog["User push_log"]
    Stamina --> PushLog
    PushLog --> Report["Task report node details"]
Loading

文件级变更

变更 详情 文件
为 OK-NTE 接入运行日志节点采集、状态归并和任务报告注入闭环。
  • 在用户配置中增加节点详情采集开关,关闭时在任务准备阶段不创建 log_box。
  • 使用 log_box 监控 OK-NTE 日志,匹配成功、失败、跳过及体力信息,并在任务结束时通过后处理器按节点状态优先级归并,追加剩余体力。
  • 在任务管理器聚合用户 push_log,并在通知结果正文中追加节点详情。
app/models/config.py
app/models/schema.py
app/task/OkNte/AutoProxy.py
app/task/OkNte/manager.py
app/task/OkNte/push_log.py
app/task/OkNte/tools/notify.py
为 OK-NTE 用户编辑界面暴露节点详情采集配置。
  • 新增启用/关闭选择项并默认启用。
  • 同步扩展前端用户配置类型。
frontend/src/api/models/OkNteUserConfig_Notify.ts
frontend/src/views/EditView/User/OkNteUserEdit.vue
完善专项开发文档,明确 log_box 的采集开关和报告注入要求。
  • 补充聚合端与通知端必须同时接通的闭环说明及自检项。
.agents/skills/mas-script-specialized-adapter/SKILL.md
.agents/skills/mas-script-specialized-adapter/references/logbox-api.md
更新版本元数据。
  • 调整版本文件以标记本次功能变更。
res/version.json

提示和命令

与 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

本 PR 将 OK-NTE 的运行日志接入通用 log_box,在用户级开关控制下采集并归并日常任务节点状态及剩余体力,随后通过任务聚合和通知正文双端注入任务报告,同时新增前端配置入口并补充相关接入文档。

Sequence diagram for OK-NTE node collection and task report delivery

sequenceDiagram
    participant User
    participant AutoProxyTask
    participant log_box
    participant UserPushLog
    participant Manager
    participant Notify

    User->>AutoProxyTask: prepare()
    alt PushLogEnabled
        AutoProxyTask->>log_box: get_collect(paths, sink, start_from_end)
        AutoProxyTask->>log_box: open()
        AutoProxyTask->>log_box: collect(OKNTE_PUSH_RULES)
        log_box-->>UserPushLog: _append_push_log(log_type, text)
        AutoProxyTask->>log_box: close(oknte_resolve)
        log_box-->>UserPushLog: resolved node statuses and stamina
    else PushLogEnabled disabled
        AutoProxyTask->>AutoProxyTask: skip log_box creation
    end
    Manager->>Manager: final_task()
    Manager->>Manager: build_push_log_text(user_list, has_uncompleted)
    Manager->>Notify: push_plyer(message with push_log)
    Notify->>Notify: append_push_log(message_text, message.get(push_log))
Loading

Flow diagram for OK-NTE node status resolution

flowchart LR
    Log["OK-NTE runtime log"] --> Rules["OKNTE_PUSH_RULES"]
    Rules --> Events["Success / skip / failure / stamina markers"]
    Events --> Resolve["oknte_resolve"]
    Resolve --> Status["Final node status\nfailure > skipped > success"]
    Resolve --> Stamina["Remaining stamina\ncurrent - target"]
    Status --> PushLog["User push_log"]
    Stamina --> PushLog
    PushLog --> Report["Task report node details"]
Loading

File-Level Changes

Change Details Files
为 OK-NTE 接入运行日志节点采集、状态归并和任务报告注入闭环。
  • 在用户配置中增加节点详情采集开关,关闭时在任务准备阶段不创建 log_box。
  • 使用 log_box 监控 OK-NTE 日志,匹配成功、失败、跳过及体力信息,并在任务结束时通过后处理器按节点状态优先级归并,追加剩余体力。
  • 在任务管理器聚合用户 push_log,并在通知结果正文中追加节点详情。
app/models/config.py
app/models/schema.py
app/task/OkNte/AutoProxy.py
app/task/OkNte/manager.py
app/task/OkNte/push_log.py
app/task/OkNte/tools/notify.py
为 OK-NTE 用户编辑界面暴露节点详情采集配置。
  • 新增启用/关闭选择项并默认启用。
  • 同步扩展前端用户配置类型。
frontend/src/api/models/OkNteUserConfig_Notify.ts
frontend/src/views/EditView/User/OkNteUserEdit.vue
完善专项开发文档,明确 log_box 的采集开关和报告注入要求。
  • 补充聚合端与通知端必须同时接通的闭环说明及自检项。
.agents/skills/mas-script-specialized-adapter/SKILL.md
.agents/skills/mas-script-specialized-adapter/references/logbox-api.md
更新版本元数据。
  • 调整版本文件以标记本次功能变更。
res/version.json

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

Choose a reason for hiding this comment

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

你好——我发现了 2 个问题

面向 AI Agent 的提示
请处理此次代码审查中的评论:

## 单独评论

### 评论 1
<location path="app/task/OkNte/AutoProxy.py" line_range="781-782" />
<code_context>
+        try:
+            if self.log_collect is not None:
+                self.log_collect.close(oknte_resolve)
+        except Exception:
+            logger.opt(exception=True).warning("OK-NTE log_box 收尾推送失败(oknte_resolve)")
+
         # 写入历史记录(对齐 General/SRC/MaaEnd 行为)
</code_context>
<issue_to_address>
**问题 (bug_risk):** `log_collect.close(oknte_resolve)` 抛出的异常仅被记录为警告后就被吞掉了,因此任务会继续执行并发送报告,但其中不包含已收集的节点详情,尽管任务本身看起来已经正常完成。

**触发条件:** 在收尾阶段读取日志文件、处理规则或执行 `oknte_resolve` 失败时。

**建议修复:** 将收尾失败记录到任务结果中,或者以其他方式让通知/报告生成逻辑知道节点详情收集失败。
</issue_to_address>

### 评论 2
<location path="app/task/OkNte/push_log.py" line_range="103-105" />
<code_context>
+            states[node] = (rank, status)
+
+    for _, text in results:
+        m = re.match(r"^(✅ 成功|⏭ 跳过|❌ 失败): (.*)$", text)
+        if m:
+            _mark(m.group(1), m.group(2))
+        elif text.startswith("SKIP:"):
+            for node in _oknte_parse_skip_list(text[len("SKIP:"):]):
+                _mark("⏭ 跳过", node)
+        elif text.startswith("CUR:"):
+            try:
+                cur_stamina = int(text[len("CUR:"):])
+            except ValueError:
+                pass
+        elif text.startswith("TGT:"):
+            try:
+                target_stamina = int(text[len("TGT:"):])
+            except ValueError:
+                pass
+        else:
+            # 兜底:裸文本视为开始标记,默认成功
+            _mark("✅ 成功", text)
+
+    result = [
</code_context>
<issue_to_address>
**问题 (bug_risk):** 每个不以已识别状态或 `SKIP:`/`CUR:`/`TGT:` 标记开头的已收集文本,都会被视为 `✅ 成功`,因此意外的提取结果会被报告为成功节点,而不是被丢弃或标记为格式错误的数据。

**触发条件:** 日志规则或未来新增的规则输出未带标记的文本值时。

**建议修复:** 仅接受明确识别的状态标记;对于未知值,应忽略或记录日志,而不是默认将其视为成功。

```suggestion
        else:
            pass
```
</issue_to_address>

Sourcery 评估

需要人工审查。 请先处理 2 个发现的问题。此外,此次更改会收集运行时日志,并将解析出的节点状态和剩余体力添加到任务报告和通知中。如果匹配或状态解析逻辑有误,那么在回滚之前,错误的详情可能已经发送给用户;回滚可以阻止后续报告,但无法撤回已经发送的消息。

阻塞性问题:app/task/OkNte/AutoProxy.py:782app/task/OkNte/push_log.py:105


Sourcery 对开源项目免费——如果您喜欢我们的审查结果,请考虑分享它们 ✨
请帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用这些反馈来改进审查结果。
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="app/task/OkNte/AutoProxy.py" line_range="781-782" />
<code_context>
+        try:
+            if self.log_collect is not None:
+                self.log_collect.close(oknte_resolve)
+        except Exception:
+            logger.opt(exception=True).warning("OK-NTE log_box 收尾推送失败(oknte_resolve)")
+
         # 写入历史记录(对齐 General/SRC/MaaEnd 行为)
</code_context>
<issue_to_address>
**issue (bug_risk):** Exceptions from `log_collect.close(oknte_resolve)` are swallowed after only writing a warning, so the task continues and sends a report without the collected node details even though the task itself appears to complete normally.

**Triggers:** When log-file reading, rule processing, or `oknte_resolve` fails during finalization.

**Suggested fix:** Record the finalization failure in the task result or otherwise make notification/report generation aware that node-detail collection failed.
</issue_to_address>

### Comment 2
<location path="app/task/OkNte/push_log.py" line_range="103-105" />
<code_context>
+            states[node] = (rank, status)
+
+    for _, text in results:
+        m = re.match(r"^(✅ 成功|⏭ 跳过|❌ 失败): (.*)$", text)
+        if m:
+            _mark(m.group(1), m.group(2))
+        elif text.startswith("SKIP:"):
+            for node in _oknte_parse_skip_list(text[len("SKIP:"):]):
+                _mark("⏭ 跳过", node)
+        elif text.startswith("CUR:"):
+            try:
+                cur_stamina = int(text[len("CUR:"):])
+            except ValueError:
+                pass
+        elif text.startswith("TGT:"):
+            try:
+                target_stamina = int(text[len("TGT:"):])
+            except ValueError:
+                pass
+        else:
+            # 兜底:裸文本视为开始标记,默认成功
+            _mark("✅ 成功", text)
+
+    result = [
</code_context>
<issue_to_address>
**issue (bug_risk):** Every collected text that does not start with a recognized status or `SKIP:`/`CUR:`/`TGT:` marker is treated as `✅ 成功`, so an unexpected extraction result is reported as a successful node instead of being discarded or surfaced as malformed data.

**Triggers:** When a log rule or future rule emits an unmarked text value.

**Suggested fix:** Only accept explicitly recognized status markers and ignore or log unknown values rather than defaulting them to success.

```suggestion
        else:
            pass
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and the change collects runtime logs and adds parsed node statuses and remaining stamina to task reports and notifications. If the matching or status-resolution logic is wrong, inaccurate details may already be sent to users before a revert; reverting stops future reports but cannot retract messages already delivered.

Blocking findings: app/task/OkNte/AutoProxy.py:782, app/task/OkNte/push_log.py:105


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 on lines +781 to +782
except Exception:
logger.opt(exception=True).warning("OK-NTE log_box 收尾推送失败(oknte_resolve)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

问题 (bug_risk): log_collect.close(oknte_resolve) 抛出的异常仅被记录为警告后就被吞掉了,因此任务会继续执行并发送报告,但其中不包含已收集的节点详情,尽管任务本身看起来已经正常完成。

触发条件: 在收尾阶段读取日志文件、处理规则或执行 oknte_resolve 失败时。

建议修复: 将收尾失败记录到任务结果中,或者以其他方式让通知/报告生成逻辑知道节点详情收集失败。

Original comment in English

issue (bug_risk): Exceptions from log_collect.close(oknte_resolve) are swallowed after only writing a warning, so the task continues and sends a report without the collected node details even though the task itself appears to complete normally.

Triggers: When log-file reading, rule processing, or oknte_resolve fails during finalization.

Suggested fix: Record the finalization failure in the task result or otherwise make notification/report generation aware that node-detail collection failed.

Comment thread app/task/OkNte/push_log.py Outdated
@HarcoChen
HarcoChen requested a review from Jungle178 August 28, 2026 07:15
AthenaHibou and others added 18 commits August 28, 2026 15:21
在保存首页布局配置时,新增同步hideScrollHint字段的逻辑,确保该配置项能被正确持久化
微调首页滚动提示组件的水平偏移位置,修正弹窗居中偏移问题
自 dev_v2 移植 PR AUTO-MAS-Project#296 的后端 WS 核心(本提交为增量接入,旧发送机制暂存):

- 新增 app/core/ws/:MainConnection 唯一主连接(代次替换、断开清理仅一次)、
  Dispatcher 按 id+type 分发、Publisher 统一出站、protocol 常量与信封解析
- 新增 app/core/lifecycle.py ShutdownCoordinator 与 app/runtime_tasks.py 持有后台任务
- schema 新增 WSEnvelope 与 WS*Data 强类型消息模型(任务模式沿用 dev 词表,
  含 GameSign 专用 WSGameSignResultData;不含插件与弹窗通道)
- /api/core/ws 路由瘦身为 MainConnection.serve,启动队列改由 on_connect 触发;
  新增 /api/core/ws_meta;/close 改为单飞 teardown 完成后发 backend.shutdown.ready
- @ws_command 反射执行器换为显式参数注册表(core.close、queue.add、queue.get)
- main.py 注册 ShutdownCoordinator teardown,uvicorn 启用协议层
  ws_ping_interval/ws_ping_timeout=20s,取消应用层心跳依赖

范围说明:不移植 dev_v2 插件系统相关通道;弹窗 Dialogs 通道按维护者决定不移植。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
将全部 98 处 Config.send_websocket_message 调用迁移到 Publisher 统一出口:

- 任务链路:TaskInfo 状态合并推送(schedule_on_change 由 RuntimeTasks 持有)、
  task.created/task.completed(含机器可读 outcome/error)、task.notice 分级提示;
  add_task 冻结脚本身份,停止契约补齐(停止全部任务加锁且等待收尾,
  单任务对已结束任务幂等成功)
- 电源链路:后端逐秒推送 power.countdown.updated,取消事件幂等发布;
  执行系统电源操作前经 frontend.close.requested 等待前端会话真正断开
- 更新链路:update.progress/completed/failed 强类型事件 + 下载权威快照接口
- 专项适配:MAA/MaaEnd/SRC/M9A/通用/HSR/OkNte/Okww 共 68 处 task.notice 迁移
- GameSign 结果广播迁移至 gamesign.result.updated(修复 dev_v2 上同调用已
  静默失效的问题);模拟器与明日方舟工具错误提示迁移至 emulator.notice/toolkit.notice
- 新增 HTTP 初始快照端点:/api/dispatch/runtime-snapshot、
  /api/dispatch/power/countdown-snapshot、/api/update/download/status
- 出站 Koishi 客户端换用协议层 ping/pong 实现,命令执行器由 main.py 显式注入
- 删除:app/core/broadcast.py(全仓零订阅者)、app/api/ws_debug.py 及其路由、
  Config.websocket/send_json/send_websocket_message、旧 WebSocketMessage 与
  WSClient* 调试模型、过时的 tests/test_websocket_message.py
- 适配既有测试至新契约(Task 签名、MainConnection 连接门控、下载目标版本传参)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- tests/core:主连接管理(单连接替换、代次清理、关闭拒绝新连接)、
  分发器(按 id+type 有序多播、异常隔离、任务持有与取消)、
  关闭协调器幂等 teardown
- tests/api:/close 单飞收口与 backend.shutdown.ready 契约、
  断线后任务停止契约
- tests/services:电源倒计时逐秒推送与取消幂等
- 新增 res/docs/WebSocket管理器快速上手.md(按 dev 范围调整:
  无插件与弹窗通道,含 GameSign 路由)

135 passed;2 项既存基线失败与本次改动无关(telemetry 测试断言旧
_start_sentry 签名、SRC 测试依赖的系统临时目录残留)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
对移植后的后端运行 yarn openapi 再生成(未手改任何生成文件):

- 删除 WS 调试客户端面:WebSocketService.ts 与 14 个 WSClient*/WSMessage* 模型
- 新增 WebSocketMetaOut、TaskRuntimeSnapshot(Item)、PowerCountdownSnapshot、
  UpdateDownloadSnapshot、WSTask*Data 等强类型模型与对应 Service 方法
- 同步收敛此前后端 schema 变更后未再生的存量差异(森空岛内置签到迁移、
  人工排查模式移除、OkNte IfUseMasConfig、MAA 游戏更新配置等字段)
- 删除 WSdev.vue 调试页及其路由与菜单入口(生成的调试客户端唯一调用方)
- OkNteUserEdit 默认值补齐再生成后暴露的 IfUseMasConfig 字段(后端默认 True)

yarn typecheck 0 错误;yarn test 106/106 通过。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dev 分支中前端拉起的后端始终携带 AUTO_MAS_DEV=1(跳过自行提权的宿主标记),
生产环境同样为 1;沿用 dev_v2 的 AUTO_MAS_DEV 判定会把所有正式用户的后端
误判为开发模式,导致 /close 不做完整 teardown、前端跳过 taskkill 兜底。
改以 main.py 启动时归一化的 AUTO_MAS_ENV(.env 开发标记)判定,
打包版前端拉起后端时会显式清除该变量。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
自 dev_v2 移植前端 WS 核心与 Electron 协调退出(旧 useWebSocket 单体暂存,
消费方迁移在后续提交完成):

- 新增 services/websocket/:连接层(状态机 idle/connecting/open/reconnecting/closed、
  单一重连计时器、3s×1.5ⁿ 封顶 30s 退避、id+type 分发、请求响应关联)与
  订阅注册表(幂等 unsubscribe、有序多播、处理器异常隔离),附单元测试
- 新增 useAppLifecycle 生命周期协调器:常驻订阅(shutdown.ready/close.requested/
  power.countdown)、closeApp 正常关闭(30s ready 超时才 taskkill、开发模式保留后端)、
  异常断开自动重启(上限 3 次+失败弹窗兜底)、休眠恢复检查、电源倒计时快照对账
- 新增组合根 bootstrap/realtimeResidents(task-runtime 与 system-notices 常驻;
  调度与更新下载常驻随消费方迁移接入)、useTaskRuntimeState、systemNotices、
  realtimeSnapshotApi
- Electron 主进程改为协调退出:app-close-requested → renderer closeApp → 25s 兜底
  强杀(scoped 按 PID 强杀+复查,删除 taskkill /f /im python.exe 全量误杀与
  CIM 扫描);窗口关闭/托盘退出/托盘重启/before-quit 全部汇入同一路径,
  失败时保留前端并弹窗;新增 powerMonitor 休眠恢复通知
- backendService 引入操作串行队列、forceStopBackend、ws_meta 开发模式探测,
  保留 dev 的便携 Python 路径与派生环境变量逻辑;processManager 限定路径
  标记扫描并复核存活
- 保留 dev 独有托盘 TrayAction 体系与全局停止快捷键(stopAll 仍走 HTTP)

按范围裁剪:不含插件系统常驻与弹窗通道;订阅测试相应去除插件用例并
类型收紧。yarn typecheck 0 错误;build:main 通过;vitest 120/120。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- useWebSocket 由 1492 行单体瘦身为门面,转发 services/websocket 的
  subscribe/unsubscribe/send/request 与连接状态;删除应用层心跳、消息缓存
  重放、连接原因白名单、ExternalWSHandlers、后端进程监控轮询等旧机制
- 调度中心:useSchedulerLogic 迁移到 id+type 订阅 + 任务运行时常驻状态
  (task.created 自动建台、断线后 HTTP 快照对账、/stop 成功后留出真实
  task.completed 窗口);吸收并删除 schedulerHandlers.ts(RequestClose 移交
  生命周期协调器、PowerSign 走常驻订阅、弃用 localStorage 待办重放);
  保留 dev 独有的 startTaskById 托盘启动与 MaaEnd 失败导出弹窗(改挂
  task.notice error 分支)
- 编辑页迁移:MAA/MaaEnd/SRC/通用/OkNte/Okww 用户与脚本配置会话改为
  task.notice + task.completed(+日志 task.log.updated)订阅组;Scripts.vue
  三处配置会话与 ScriptTable activeConnections 契约同步更新
- GameSign 页改订 gamesign.result.updated;卫星状态改由任务运行时常驻
  订阅驱动(errorVisible→lastFailed,周期 HTTP 快照兜底替代 storage 抓取)
- 电源倒计时组件消费生命周期协调器状态;TitleBar 关闭统一走 closeApp
  协调流程;appEntry 进入流程注册常驻订阅后再连接
- 删除 WebSocketMessageListener(dev 上问答弹窗通道无生产方)与
  MessageTestPage 调试页;组合根补齐 scheduler 与 update-download 常驻
- 适配 dev_v2 遗留的过时下载订阅测试断言(常驻订阅不随取消释放)

yarn typecheck 0 错误;vitest 120/120;vite build 与 electron 主进程构建通过;
全仓无 Signal/sendRaw/scheduler-pending-tabs 等旧字段残留。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
开发模式路由守卫对内页直接放行,刷新后落在 /scripts 等内页时没有任何
入口触发主 WebSocket 连接与 markAsInitialized,isAppReady 恒为 false,
整窗空白且无法自愈(旧版由 useWebSocket 单体的全局自动连接掩盖)。
守卫在该场景下补一次 connectWithRetry 并以开发模式容错标记初始化,
连接失败时交由生命周期协调器继续重连。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
「3s 后触发 Popup」按钮为旧 WS 问答弹窗通道的独立弹窗窗口
(/popup 路由,96f97dda 引入)设计;该路由与 Popup.vue 已在
1793100 重构中删除,按钮自此点击即导航到不存在的路由导致
内容区空白。其测试的弹窗通道也已在本次移植中按维护者决定移除。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…#441)

关联 AUTO-MAS-Project#295(本 PR 将 dev_v2 已合入的 AUTO-MAS-Project#296 重构移植到 `dev`,是否随本 PR 关闭该 issue 请维护者定夺)。

## 摘要

1. **后端**新增 `app/core/ws/`(MainConnection 唯一主连接、Dispatcher 按 id+type
分发、Publisher 统一出口、强类型 WSEnvelope/WS*Data);`@ws_command`
反射执行器换为显式参数注册表;出站 Koishi 客户端改用协议层 ping/pong,命令执行器由 main.py 显式注入;新增
`/api/core/ws_meta` 与任务运行时、电源倒计时、更新下载三个 HTTP 初始快照端点。
2. **前端**重写连接层(状态机、单一重连计时器、有限退避、id+type 分发、请求响应关联)与订阅注册表;新增
`useAppLifecycle` 生命周期协调器(常驻订阅、正常关闭 30s taskkill 兜底、异常自动重启后端上限 3
次、后端驱动电源倒计时、休眠恢复检查);Electron 主进程改为协调退出(`app-close-requested` → renderer
closeApp → 25s 兜底 scoped 强杀),**删除 `taskkill /f /im python.exe` 全量误杀**。
3. **删除**应用层心跳、Broadcast(全仓零订阅者)、消息缓存/重放/历史、反射式
ws_command、`app/api/ws_debug.py` 全部调试路由与 WSdev
页面、连接原因白名单、`schedulerHandlers` localStorage 重放。
4. **dev 独有面补齐迁移**(AUTO-MAS-Project#296 未覆盖):HSR/OkNte/Okww 专项共 21 处调用、GameSign 结果广播(新增
`id=GameSign` / `gamesign.result.updated` 路由,并顺带修复该调用在 dev_v2
上已静默失效的问题)、托盘 TrayAction/全局停止快捷键与协调退出汇合、首页卫星状态改由任务运行时常驻订阅驱动。
5. 已包含 dev_v2 上 AUTO-MAS-Project#296 的全部后续修复(30s 关闭超时、模拟器/明日方舟错误通知展示、断线后任务停止契约、/stop
完成事件窗口)。

## 范围调整(相对 dev_v2 版本)

- **不移植**:插件系统/插件市场全部通道(dev 无该子系统)、MaaFW 前端适配、uv/pyproject 工具链。
- **弹窗 Dialogs 通道未移植**:dev 已移除人工排查模式(其唯一生产方),且 dev 上旧 `Message/Question`
通道全仓无发送方;对应 `WebSocketMessageListener` 一并删除。
- **开发模式判定改用 `AUTO_MAS_ENV`**:dev 分支前端拉起的后端始终携带
`AUTO_MAS_DEV=1`(跳过自行提权的宿主标记),不能沿用 dev_v2 的判定,否则生产环境后端会被误判为开发模式导致关闭流程失效。
- 行为说明:Koishi 远程 `core.close` 现执行完整 teardown 并经主 WS 发
`backend.shutdown.ready`(原为关闭 socket + KillSelf);如需远程关闭前端仍可走电源 KillSelf
路径(`frontend.close.requested`)。
- `yarn openapi` 再生成同时收敛了此前后端 schema 变更后未再生的存量差异(森空岛内置签到、人工排查移除、OkNte
`IfUseMasConfig`、MAA 游戏更新配置等字段),生成目录未手改。

## 验证

- 后端 pytest 135 passed(2 项失败为既存基线:telemetry 测试断言旧 `_start_sentry` 签名、SRC
测试依赖的系统临时目录残留,均与本 PR 无关);合并门槛 `pytest --collect-only` 退出码 0。
- 前端 vitest 120/120;`yarn typecheck` 0 错误;vite build 与 electron
主进程构建通过;改动文件 ESLint 全绿。
- 真实主 WS 冒烟:单连接替换旧连接、非法信封丢弃不掉线、`/close` 后依次收到 `power.sign.updated` 与
`backend.shutdown.ready`、开发模式后端保留复用、三个快照端点返回正确。
- 全仓搜索
`send_websocket_message`/`Config.websocket`/`Broadcast`/`sendRaw`/`ExternalWSHandlers`/`scheduler-pending-tabs`
等旧机制 0 残留。
- 待人工复核(需图形界面实机):Electron 正常/异常退出全路径(✕、托盘退出/重启、25s
兜底、失败保留前端)、休眠恢复、任务全流程与音频、断线自动重启弹窗。

## 协作提示

- 与在途 PR AUTO-MAS-Project#423(main.py Win32 依赖)与 AUTO-MAS-Project#417(通知中间层)存在相邻改动,合并顺序靠后的一方需 rebase。
- WS 调试 REST 路由删除会同步影响 MCP 工具面(自动生成),属预期的对外契约变化。
- 协议速查文档新增于 `res/docs/WebSocket管理器快速上手.md`。

🤖 Generated with [Claude Code](https://claude.com/claude-code)
对齐 dev 的 build_user_result_text:ok-ww/general/ok-nte 三专项 manager
按用户交错组装「用户结果行+节点」并入 result,push_log 置空。
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.

4 participants