Skip to content

feat(push_log/log_box): 新增通用配置的日志采集推送功能,新增供专项适配器调用的日志采集推送组件,落地OKWW的日志推送功能 - #399

Merged
1w1w11w1 merged 31 commits into
AUTO-MAS-Project:devfrom
AthenaHibou:feat/log_box
Aug 27, 2026

Conversation

@AthenaHibou

@AthenaHibou AthenaHibou commented Aug 21, 2026

Copy link
Copy Markdown

feat:
一、push_log:新增推送配置,允许用户通过字符串切割/正则/函数进行日志处理,从而自定义推送运行进程执行情况
详见pr #386
二、log_box:将日志采集推送能力从具体专项抽离为通用的 log_box 组件,使专项与可编辑脚本只需"喂参数(日志位置 + 规则 + 处理器)",采集、前置处理、规则匹配、后置处理、推送统一由组件完成,最终汇入 cur_user_item.push_log 单一 sink。
提供Skill文档,位于.agents\skills\mas-script-specialized-adapter\references\logbox-api.md
详见pr #392

Summary by Sourcery

统一可配置与专用的日志采集,使任务报告可以通过共享的推送日志(push-log)管线包含处理后的执行详情。

New Features:

  • 为通用脚本新增可配置的分割(split)、正则(regex)和多行日志提取能力,包括按规则启用以及区分正常/失败报告语义。
  • 提供可复用的 log_box 组件,用于专用适配器和脚本宿主集成,支持规则构建器、处理管线、日志接收端(sinks)以及日志标记(log marker)。
  • 通过共享的推送日志管线集成 OK-WW 任务节点日志采集、状态解析和报告投递。
  • 新增前端推送日志规则管理、文档、实时日志加载以及由后端驱动的模式调试能力。

Bug Fixes:

  • 防止陈旧进程和延迟启动的进程导致通用脚本任务状态检测错误。
  • 避免在另一项保存或刷新操作进行时丢失已排队的脚本配置编辑。
  • 处理日志轮转、截断、不完整行,以及在重试过程中匹配器状态重置的问题。

Enhancements:

  • 将通用与专用任务报告的推送日志聚合和通知格式统一集中管理。
  • 新增可复用的表达式解析、提取函数、自定义处理算子,以及基于 PO 的日志翻译工具。
  • 在后端和前端设置中暴露推送日志配置字段和生成的 API 模型。

Documentation:

  • 为专用适配器编写 log_box 使用文档,并新增前端参考指南,涵盖分割、正则、表达式和多行日志处理。

Chores:

  • 新增任务级推送日志存储,并在 HTML 与文本通知中包含采集到的进程信息。
Original summary in English

Summary by Sourcery

Unify configurable and specialized log collection so task reports can include processed execution details through a shared push-log pipeline.

New Features:

  • Add configurable split, regex, and multiline log extraction for general scripts, including per-rule enablement and normal/failed report semantics.
  • Provide the reusable log_box component for specialized adapters and script-host integrations, with rule builders, processing pipelines, sinks, and log marker support.
  • Integrate OK-WW task-node log collection, status resolution, and report delivery through the shared push-log pipeline.
  • Add frontend push-log rule management, documentation, live log loading, and backend-powered pattern debugging.

Bug Fixes:

  • Prevent stale processes and delayed process startup from causing incorrect general-script task status detection.
  • Avoid losing queued script configuration edits while another save or refresh is in progress.
  • Handle log rotation, truncation, incomplete lines, and matcher state resets across retries.

Enhancements:

  • Centralize push-log aggregation and notification formatting for general and specialized task reports.
  • Add reusable expression parsing, extraction functions, custom processing operators, and PO-based log translation utilities.
  • Expose push-log configuration fields and generated API models across backend and frontend settings.

Documentation:

  • Document log_box usage for specialized adapters and add frontend reference guides for split, regex, expression, and multiline log processing.

Chores:

  • Add task-level push-log storage and include collected process information in HTML and text notifications.

AthenaHibou and others added 26 commits August 21, 2026 13:58
1. 新增日志元数据前缀剥离功能,过滤OneDragon风格日志前缀
2. 修改推送日志聚合格式,改为按行展示而非管道符分隔
3. 调整通知模板的日志分隔标识与空行排版
1. 重构推送日志配置,拆分开关与匹配规则
2. 新增表达式解析模块,支持正则提取与函数处理
3. 新增日志模式调试API与前端文档
4. 新增字符串切割、正则、多行聚合等日志处理的说明文档
5. 取消了原本的简易日志处理代码
1.  更新所有文档、注释与前端提示中的分隔符说明,将|替换为;
2.  修正subby函数默认参数与文档描述不一致问题
3.  为字面量添加\n、\t转义支持
4.  统一行预处理逻辑,在apply_patterns入口添加strip()处理行尾空白
1.  重构推送日志数据模型:从list[str]改为list[tuple[str, str]],存储(日志类型, 格式化文本)
2.  增强进程搜索能力:新增进程创建时间过滤,避免跟踪旧残留进程
3.  扩展cutby、subby表达式函数:支持指定匹配序号,处理多分隔符场景
4.  新增日志类型标记:支持普通/失败分类,配合推送策略过滤
5. 补充了一些缺失的依赖
- schema: 新增 PushLogPattern 强类型模型(Literalt split/regex/multiline),PatternDebugIn.pattern 由 Dict 改为强类型
- api: debug_pattern 改用 model_dump(exclude_none) 适配强类型
- frontend: 移除裸 fetch,改用生成的 ActionService.debugPattern 强类型方法,并补齐对应 OpenAPI 生成产物
- version: v5.4.0-beta.7 登记推送日志采集功能
- 用 reactive 包裹调试实例,使弹窗模板中的嵌套 ref 自动解包,
  消除 $setup.debug.input.trim is not a function,修复调试界面打不开
- 将 props.pattern 同步到弹窗实例的 currentPattern,
  修复点击「调试」无响应(runDebug 因 currentPattern 为空直接返回)
- 切换规则时仅清空结果与错误、保留已加载的日志输入,
  避免误删用户粘贴/加载的日志内容
- 移除误提交的 .codex/skills gitlink,避免干净克隆缺乏 .gitmodules 无法初始化
- 调试请求复用 @api 生成的 PatternDebugIn/PushLogPattern 契约,消除本地重复类型定义
- debug_pattern 编译忽略 enabled 开关,停用的有效规则也可调试
- flush_patterns 一次收集并返回所有 matcher 残留结果,修复多条 multiline 规则结束时只推首条
- PushLogConfig 调试"加载日志"的 logPath 改传 getter,修复异步加载脚本后误判未配置路径
- GeneralScriptEdit handleChange 串行合并排队保存,不再静默丢弃变更
- 修正普通/失败规则提示文案,对齐实际过滤逻辑(普通始终纳入,失败仅在存在未完成用户时)
逐条修复评审反馈:

- 日志轮转/截断后同步重置采集游标,避免恢复后前段推送日志被跳过丢失
- 每次任务重试前重置多行匹配器窗口状态,防止跨重试把不同尝试的日志拼成一个窗口
- 前端序列化必填字段与后端编译条件对齐,缺少必填字段时给出提示,不再静默失效
- 模拟器/游戏切换、根路径选择等保存入口共用串行保存并排空待处理变更,避免刷新覆盖编辑且队列残留
- 非法提取正则由原先的“无匹配”改为抛出具体语法错误,保存/调试接口返回可读报错
表达式引擎被动化,可注入自定义文本变换算子,对 web 前端面板不暴露。

- functions.py 新增 Process 基类(name + run(text, args))、REGISTRY 注入注册表、
  @register_process 装饰器、make_process 按表达式调用参数实例化
- evaluator.py 编译期函数名校验放宽为「内置 FUNCTIONS ∪ 注入 REGISTRY」,
  apply_function 对 Process 子类用 make_process 实例化调用
- rule.py 的 _call 校验同步放开到 REGISTRY

引擎其它能力($() 作用域、函数链、多行聚合字面量)复用现有语义,仅增加注入算子。
log_box 只对日志本身负责:接收「日志源 + 规则 + 处理器」,内部完成采集 →
前置处理(open)→ 规则匹配/提取 → 后置处理(close)→ 结果推送,与专项解耦。

- app/log_box/ 新增:LogBox 工厂(get_collect)、LogCollect 采集器
  (open/collect/collect_scope/rule/postprocess/print/push/close)、Rule 可编程
  构建器(regex/cut/get/sub/cutby/subby/replace/trim/upper/lower/func)、LogType、
  LogSource 多文件自采集(offset 增量读、轮转处理)、@@Logbox@@ 结果标记渲染与解析
- mas_script.py 仓库根顶层别名:from mas_script import log_box, Rule, LogType
- 结果落点两态:MAS 进程宿主注入 sink 直接写 push_log;脚本子进程宿主走
  @@Logbox@@ 标记回传,由 general/AutoProxy.py 的 check_log 逐行嗅探接收
- .agents/skills 补充 logbox-api.md 使用文档并在 SKILL.md 登记落点

配套验收:MAS 宿主注入 sink 直接进 push_log;脚本宿主经 @@Logbox@@ 出现在任务报告;
前置/后置处理器、print、push 均生效。
gettext PO 解析 + 通用翻译器,供专项/脚本做日志预翻译,不绑定具体脚本
(okww 等只是使用方)。

- po.py:PO 状态机解析(跨行 msgid/msgstr、转义序列、复数取 msgstr[0]、
  忽略 msgctxt/文件头/空 msgstr)
- translator.py:PoTranslator.load(多文件, base 相对路径动态解析)、
  load_supplement(补充优先)、translate(逐行)、clear(会话结束释放)

用法:okww 以 ok.po + 项目自带补充 .po 作前置翻译,补充优先。
open() 文档声明「可选、幂等」,但 LogSource.read_new() 在未 open 时返回空,
导致不显式调用 open() 直接 close() 采不到任何内容。重构 _open_sources():
open() 与 _capture()(close 收尾)共用,close 时自动启动日志源记录起始位置,
open 真正可选。

logbox-api.md 修正:
- Rule 示例 get(1) 是按字符数保留、不是正则分组提取;改为 regex(r"(\d+)")
  捕获组提取,并补充「$() 必须用捕获组、无捕获组返回空串」的说明
- 自定义处理说明:不能用 .process(fn) 直接传 Python 闭包(跨进程只传规则参数、
  契约不含函数体),统一用 @register_process 具名注入 + Rule.func() 调用
- 示例补充 col.open() 与 start_from_end 采集语义说明
- collect.py:匹配正则非法时 fail-fast(与表达式编译语义一致),空正则仍按
  「不生效」跳过;collect_scope 的起始/结束正则同样校验
- sources.py:LogSource 轮转检测改用文件身份 (st_ino, st_ctime_ns),兼容
  Windows 下 st_ino 不可靠(st_ctime 为创建时间,文件被替换时变化)
- general/AutoProxy.py:移除从未被读取的 _marker_flushed 死状态;flush 标记
  仅表示回传通道结束、不记录状态(结果统一在 final_task 写回 push_log)
MAS 侧尚未把用户脚本进程 stdout 接入 check_log(脚本 stdout 现为 DEVNULL
丢弃、check_log 只读 LogPath 日志文件),也未设置 MAS_SCRIPT_LOG_PATH 与
import mas_script 所需的 PYTHONPATH。文档标注:

- 脚本宿主(@@Logbox@@ 回传)为能力预留,当前唯一可用宿主为 MAS 进程注入 sink
- 脚本宿主示例标记为将来接通后的用法示意,当前不可交付
OK-WW 专项作为 log_box 的一个实例:只提供参数(日志路径/规则/处理器)并注入
sink,日志获取、前置处理、规则匹配、后置解析与推送全部由 log_box 完成。

- push_log.py:OKWW_REL_I18N_PO(相对 RootPath)/ OKWW_SUPPLEMENT_PO(res/i18n
  补充 .po)、OKWW_PUSH_RULES 状态标记规则(开始/失败/跳过/成功四类,失败匹配
  源码 log_error 专属日志、排除战斗噪音)、okww_resolve 后处理(按节点解析
  最终状态,失败 > 跳过 > 成功)
- AutoProxy.py:构造 log_collect,注入 sink 到 cur_user_item.push_log,open 挂
  PoTranslator(ok.po + 补充 .po),final_task 调 close(okww_resolve) 收尾
- manager.py:聚合各用户 push_log 进任务报告("失败"类型仅在未完成用户时纳入)
- notify.py:通知详情追加 push_log(与 HTML 模板 push_log 区块一致)
- res/i18n/okww.po:AutoMAS 项目自带补充翻译(覆盖 ok.po 子串污染、翻译关键
  节点日志)

真实日志验证节点完整有序、状态正确;节点级失败始终展示(LogType.NORMAL +
文本状态),推送时机由 SendTaskResultTime 全局控制(与 MAS 原生语义一致)。
- logbox-api.md:新增「日志类型与推送时机语义」章节(LogType 逐条 +
  SendTaskResultTime 全局,与 MAS 原生一致);专项喂参示例更新为后处理状态解析
- log-box-rework.md:第 3 步描述对齐最终实现(补充 .po、okww_resolve 状态解析、
  匹配/提取均在翻译后行、推送时机语义)
- version.json:v5.4.0-beta.9 登记 log_box 采集推送能力
将各模块重复的推送日志处理逻辑抽离到app/tools/push_log.py,统一实现push_log的聚合与文本追加,替换原有分散的硬编码实现,更新文档说明通用工具使用方式
- LogCollect.open() 有参调用返回自身,与 close/collect 链式风格统一
- _PostProcessor 直接消费/返回 (log_type, text) 元组,文本改写后日志类型不再丢失
- okww_resolve 按节点名(去状态前缀)重建日志类型映射,修复带状态前缀规则类型错配
- 同步 logbox-api 后处理示例签名,并补充与通用脚本 web 配置推送日志的分工说明
新增目录导航、命名约定说明以及7条常见开发陷阱细节,同时修复resolve函数注释与逻辑细节,优化日志类型匹配逻辑
更新日志匹配规则,新增带前缀的匹配串避免误判普通每日任务异常,同时保留原英文匹配串适配多语言场景

@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 @AthenaHibou, your pull request is larger than the review limit of 150000 diff characters

@sourcery-ai

sourcery-ai Bot commented Aug 21, 2026

Copy link
Copy Markdown

审阅者指南

实现了一个可复用的 log_box 日志采集/推送组件、一个可配置的日志模式抽取引擎(含表达式语言),并将推送日志采集集成到通用脚本和 OK-WW 适配器中,同时提供后端 API、前端配置/调试 UI 以及文档。

通用脚本日志处理与 push_log 聚合的时序图

sequenceDiagram
  participant LM as LogMonitor
  participant AP as AutoProxyTask
  participant LP as LogPatternExtractor
  participant UI as UserItem
  participant PT as push_log_tools
  participant GM as GeneralManager
  participant NO as Notify

  LM->>AP: check_log(log_content, latest_time)
  AP->>AP: parse_marker(line)
  alt script_marker
    AP->>AP: push_log_buffer.append((type, text))
  else no_marker
    AP->>LP: apply_patterns(line, matchers)
    alt matched
      LP-->>AP: (log_type, text)
      AP->>AP: push_log_buffer.append((log_type, formatted_text))
    end
  end

  AP->>AP: _push_log_processed = len(log_content)

  AP->>LP: flush_patterns(matchers)
  LP-->>AP: [(log_type, text)]
  AP->>AP: push_log_buffer.append(...)
  AP->>UI: set push_log = push_log_buffer

  GM->>PT: build_push_log_text(user_list, has_uncompleted)
  PT-->>GM: push_log_text
  GM->>NO: push_plyer(..., message["push_log"])
  NO-->>NO: append_push_log(message_text, push_log)
Loading

log_box 日志采集与推送投递的流程图

flowchart TD
  A["MAS_or_script_host"] --> B["log_box.get_collect(paths, sink, start_from_end)"]
  B --> C["LogCollect"]
  C --> D["LogCollect.open(preprocessor)"]
  C --> E["LogCollect.collect / collect_scope / rule"]
  D --> F["LogSource.read_new"]
  F --> G["RegexMatcher / MultiLineAggregator.apply"]
  G --> H["LogCollect.close(postprocessor)"]

  H --> I{sink_injected?}
  I -->|yes| J["sink(log_type, text) → cur_user_item.push_log"]
  I -->|no| K["emit(render_push / render_flush)"]
  K --> L["AutoProxyTask.check_log"]
  L --> M["parse_marker → push_log_buffer"]

  subgraph MAS_push_aggregation
    N["build_push_log_text(user_list, has_uncompleted)"] --> O["append_push_log(message_text, push_log)"]
  end
Loading

文件级变更

Change Details Files
引入 log_box 作为可复用的日志采集/推送组件,支持多源、前/后处理、规则以及脚本宿主标记。
  • 新增 LogCollect 会话对象,用于跟踪一个或多个日志文件,应用预处理器、单行和多行规则以及后处理器,然后通过 sink 或 stdout 标记投递结果。
  • 实现 LogBox 工厂和顶层 mas_script 别名,用于为 MAS 进程宿主(带 sink)或脚本子进程宿主(基于标记)创建 LogCollect 实例。
  • 定义 LogType 常量、logbox 结果标记(带 JSON 负载的 @@Logbox@@ push/flush),以及用于增量 tail、带轮转/截断处理和可选基于时间过滤的 LogSource。
  • 新增可编程的 Rule 构建器,用于基于表达式的抽取流水线,并在 app/log_box/init.py 中导出 log_box API。
app/log_box/__init__.py
app/log_box/collect.py
app/log_box/factory.py
app/log_box/logtype.py
app/log_box/markers.py
app/log_box/rule.py
app/log_box/sources.py
mas_script.py
添加通用的日志模式抽取引擎及表达式语言,并集成到各类工具中。
  • 实现 LogPatternExtractor,支持 split/regex/multiline 模式类型、已编译匹配器、模式序列化/反序列化、模式应用、残留状态的冲刷(flush),以及模式校验/调试辅助功能。
  • 引入 expression 模块(解析器、求值器、函数),支持 $(regex) 作用域、字面量、拼接以及包含自定义处理算子的函数链。
  • 通过 app.utils 暴露模式和表达式工具,并将其接入 log_box 和通用日志推送逻辑以复用。
app/utils/LogPatternExtractor.py
app/utils/expression/__init__.py
app/utils/expression/parser.py
app/utils/expression/evaluator.py
app/utils/expression/functions.py
app/utils/__init__.py
为 .po/.mo 文件新增 i18n 翻译工具,并在 OK-WW 中用于预翻译日志。
  • 实现 PoTranslator 和 PO/MO 解析辅助工具,用于加载翻译映射(包括补充翻译),并提供按行的 translate/clear API。
  • 在 OK-WW AutoProxy 中使用 PoTranslator 在规则匹配前翻译 ok-script 日志,同时加载脚本本地及项目补充翻译文件。
app/utils/i18n/__init__.py
app/utils/i18n/po.py
app/utils/i18n/translator.py
app/task/Okww/AutoProxy.py
app/task/Okww/push_log.py
res/i18n/okww.po
将基于 log_box 的推送日志采集接入 OK-WW,并实现通用的 push_log 聚合工具供 OK-WW 和通用脚本共享。
  • 在 OK-WW AutoProxy 中,针对 ok-script.log 创建 LogCollect 会话,将 sink 注入 cur_user_item.push_log,应用翻译预处理器,注册 OKWW 专用规则,并在关闭时通过后处理器解析节点级状态。
  • 新增 OK-WW manager 和 notify 集成,通过共享工具将每个用户的 push_log 聚合为任务级文本,并将其追加进 HTML 和文本通知中。
  • 新增通用 push_log 工具模块,对每个用户的 (log_type, text) 条目进行聚合,并可按未完成用户过滤失败类型行,然后将聚合结果追加进通知正文。
  • 扩展 UserItem,使其能保存每次运行的 push_log 条目以便后续聚合。
app/task/Okww/AutoProxy.py
app/task/Okww/manager.py
app/task/Okww/tools/notify.py
app/models/task.py
app/tools/push_log.py
res/html/general_result.html
为通用脚本添加可配置的基于 JSON 的推送日志采集,并通过后端 API 和前端工具集成模式调试。
  • 扩展通用脚本配置 schema 和模型,添加描述 split/regex/multiline 规则的 PushLogEnabled 和 PushLogPatterns 字段;新增 PushLogPattern 以及模式调试请求/响应模型。
  • 更新 General AutoProxy 以加载和编译推送日志模式,在 check_log 期间缓冲抽取出的 (log_type, text) 元组,处理来自脚本宿主的 @@Logbox@@ 标记,在 final_task 时冲刷多行匹配器,并将结果写入 cur_user_item.push_log。
  • 创建 /api/setting/debug_pattern API,用于对给定日志文本验证和运行单个模式,返回按行或按窗口的命中/抽取详细信息。
  • 在通用 manager 的 final_task 和通知辅助中集成聚合后的 push_log,与 OK-WW 一致,复用 app/tools/push_log.build_push_log_text 和 append_push_log。
app/models/config.py
app/models/schema.py
app/models/task.py
app/api/setting.py
app/task/general/AutoProxy.py
app/task/general/manager.py
app/task/general/tools/notify.py
增强前端脚本编辑 UI,支持推送日志配置、模式调试和行内文档。
  • 扩展生成的 API 模型/服务,加入 PushLogPattern、模式调试 DTO 以及 debug_pattern 端点。
  • 新增 Vue 组件与可组合函数(PushLogConfig、LogPatternRule、LogPatternDebugModal、LogPatternDocsModal、usePushLogPatterns、useLogPatternDebug),用于配置模式、重排规则、对单个模式进行实时调试(针对日志内容),以及展示基于 markdown 的 split/regex/expression/multiline 模式文档。
  • 在通用脚本编辑视图中集成推送日志配置区块,包括对 Script.PushLogEnabled/PushLogPatterns 的 v-model 绑定,以及具备状态感知的保存语义以批量更新,并避免在异步保存期间丢失编辑内容。
frontend/src/api/index.ts
frontend/src/api/models/GeneralConfig_Script.ts
frontend/src/api/models/OkNteConfig_Script.ts
frontend/src/api/models/PushLogPattern.ts
frontend/src/api/models/PatternDebugIn.ts
frontend/src/api/models/PatternDebugOut.ts
frontend/src/api/models/PatternDebugResultItem.ts
frontend/src/api/services/ActionService.ts
frontend/src/api/services/Service.ts
frontend/src/types/script.ts
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/views/EditView/Script/components/PushLogConfig.vue
frontend/src/views/EditView/Script/components/LogPatternRule.vue
frontend/src/views/EditView/Script/components/LogPatternDebugModal.vue
frontend/src/views/EditView/Script/LogPatternDocsModal.vue
frontend/src/views/EditView/Script/composables/usePushLogPatterns.ts
frontend/src/views/EditView/Script/composables/useLogPatternDebug.ts
frontend/src/views/EditView/Script/docs/split-doc.md
frontend/src/views/EditView/Script/docs/regex-doc.md
frontend/src/views/EditView/Script/docs/expression-doc.md
frontend/src/views/EditView/Script/docs/multiline-doc.md
调整进程管理和文档,以支持更健壮的脚本托管和基于日志的报告能力。
  • 更新 ProcessManager.search_process,通过强制最小 create_time 阈值来忽略预先存在的进程,降低附着到陈旧实例上的概率。
  • 优化通用 AutoProxy 的进程状态逻辑,以跟踪脚本进程是否曾被发现,并在宣告过早退出前引入启动宽限期,从而改进成功/失败分类。
  • 扩展技能文档,描述如何使用 log_box 组件和共享的 push_log 工具,并按需更新版本和忽略设置。
app/utils/ProcessManager.py
app/task/general/AutoProxy.py
.agents/skills/mas-script-specialized-adapter/SKILL.md
.agents/skills/mas-script-specialized-adapter/references/logbox-api.md
res/version.json
.gitignore
requirements.txt

提示与命令

与 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 a reusable log_box logging collection/push component, a configurable log pattern extraction engine (including expression language), and integrates push-log collection into both general scripts and the OK-WW adapter with backend APIs, frontend configuration/debug UI, and documentation.

Sequence diagram for general script log processing and push_log aggregation

sequenceDiagram
  participant LM as LogMonitor
  participant AP as AutoProxyTask
  participant LP as LogPatternExtractor
  participant UI as UserItem
  participant PT as push_log_tools
  participant GM as GeneralManager
  participant NO as Notify

  LM->>AP: check_log(log_content, latest_time)
  AP->>AP: parse_marker(line)
  alt script_marker
    AP->>AP: push_log_buffer.append((type, text))
  else no_marker
    AP->>LP: apply_patterns(line, matchers)
    alt matched
      LP-->>AP: (log_type, text)
      AP->>AP: push_log_buffer.append((log_type, formatted_text))
    end
  end

  AP->>AP: _push_log_processed = len(log_content)

  AP->>LP: flush_patterns(matchers)
  LP-->>AP: [(log_type, text)]
  AP->>AP: push_log_buffer.append(...)
  AP->>UI: set push_log = push_log_buffer

  GM->>PT: build_push_log_text(user_list, has_uncompleted)
  PT-->>GM: push_log_text
  GM->>NO: push_plyer(..., message["push_log"])
  NO-->>NO: append_push_log(message_text, push_log)
Loading

Flow diagram for log_box log collection and push delivery

flowchart TD
  A["MAS_or_script_host"] --> B["log_box.get_collect(paths, sink, start_from_end)"]
  B --> C["LogCollect"]
  C --> D["LogCollect.open(preprocessor)"]
  C --> E["LogCollect.collect / collect_scope / rule"]
  D --> F["LogSource.read_new"]
  F --> G["RegexMatcher / MultiLineAggregator.apply"]
  G --> H["LogCollect.close(postprocessor)"]

  H --> I{sink_injected?}
  I -->|yes| J["sink(log_type, text) → cur_user_item.push_log"]
  I -->|no| K["emit(render_push / render_flush)"]
  K --> L["AutoProxyTask.check_log"]
  L --> M["parse_marker → push_log_buffer"]

  subgraph MAS_push_aggregation
    N["build_push_log_text(user_list, has_uncompleted)"] --> O["append_push_log(message_text, push_log)"]
  end
Loading

File-Level Changes

Change Details Files
Introduce log_box as a reusable log collection/push component with support for multiple sources, pre/post-processing, rules, and script-host markers.
  • Add LogCollect session object that tails one or more log files, applies pre-processors, line and multi-line rules, and post-processors, then delivers results via a sink or stdout markers.
  • Implement LogBox factory and top-level mas_script alias to create LogCollect instances for MAS process host (with sink) or script sub-process host (marker-based).
  • Define LogType constants, logbox result markers (@@Logbox@@ push/flush with JSON payload), and LogSource for incremental tailing with rotation/truncation handling and optional time-based filtering.
  • Add programmable Rule builder for expression-based extraction pipelines and export log_box APIs in app/log_box/init.py.
app/log_box/__init__.py
app/log_box/collect.py
app/log_box/factory.py
app/log_box/logtype.py
app/log_box/markers.py
app/log_box/rule.py
app/log_box/sources.py
mas_script.py
Add a generic log pattern extraction engine with an expression language and integrate it into utilities.
  • Implement LogPatternExtractor with split/regex/multiline pattern types, compiled matchers, pattern (de)serialization, application, flushing of residual state, and pattern validation/debug helpers.
  • Introduce an expression module (parser, evaluator, functions) that supports $(regex) scopes, literals, concatenation, and a function chain including custom process operators.
  • Expose pattern and expression utilities via app.utils and wire them for reuse by log_box and general log-push logic.
app/utils/LogPatternExtractor.py
app/utils/expression/__init__.py
app/utils/expression/parser.py
app/utils/expression/evaluator.py
app/utils/expression/functions.py
app/utils/__init__.py
Add i18n translation utilities for .po/.mo files and use them to pre-translate logs for OK-WW.
  • Implement PoTranslator and PO/MO parsing helpers to load translation mappings, including supplemental translations, and provide line-level translate/clear APIs.
  • Use PoTranslator in OK-WW AutoProxy to translate ok-script logs before rule matching, loading both script-local and project-supplemental translation files.
app/utils/i18n/__init__.py
app/utils/i18n/po.py
app/utils/i18n/translator.py
app/task/Okww/AutoProxy.py
app/task/Okww/push_log.py
res/i18n/okww.po
Wire log_box-based push-log collection into OK-WW and implement generic push_log aggregation utilities used by both OK-WW and general scripts.
  • In OK-WW AutoProxy, create a LogCollect session over ok-script.log, inject a sink into cur_user_item.push_log, apply translation as a pre-processor, register OKWW-specific rules, and close with a post-processor that resolves per-node status.
  • Add OK-WW manager and notify integration to aggregate per-user push_log into a task-level text via a shared tool, and append it into both HTML and text notifications.
  • Introduce a generic push_log tool module that aggregates per-user (log_type, text) entries with optional filtering of failure-type lines based on uncompleted users, and appends the aggregated text into notification bodies.
  • Extend UserItem to hold per-run push_log entries for later aggregation.
app/task/Okww/AutoProxy.py
app/task/Okww/manager.py
app/task/Okww/tools/notify.py
app/models/task.py
app/tools/push_log.py
res/html/general_result.html
Add configurable push-log collection for general scripts using JSON-defined patterns and integrate pattern debugging via a backend API and frontend tooling.
  • Extend general script config schema and models with PushLogEnabled and PushLogPatterns fields describing split/regex/multiline rules; add PushLogPattern and pattern debug request/response models.
  • Update General AutoProxy to load and compile push-log patterns, buffer extracted (log_type, text) tuples during check_log, handle @@Logbox@@ markers from script hosts, flush multiline matchers at final_task, and write results into cur_user_item.push_log.
  • Create /api/setting/debug_pattern API that validates and runs a single pattern against provided log text, returning detailed per-line or per-window hit/extracted information.
  • Integrate aggregated push_log into general manager final_task and notify helpers similar to OK-WW, reusing app/tools/push_log.build_push_log_text and append_push_log.
app/models/config.py
app/models/schema.py
app/models/task.py
app/api/setting.py
app/task/general/AutoProxy.py
app/task/general/manager.py
app/task/general/tools/notify.py
Enhance frontend script editing UI with push-log configuration, pattern debugging, and inline documentation.
  • Extend generated API models/services with PushLogPattern, pattern debug DTOs, and the debug_pattern endpoint.
  • Add new Vue components and composables (PushLogConfig, LogPatternRule, LogPatternDebugModal, LogPatternDocsModal, usePushLogPatterns, useLogPatternDebug) to configure patterns, reorder rules, live-debug single patterns against log content, and show markdown-based documentation for split/regex/expression/multiline modes.
  • Integrate push-log configuration section into the general script edit view, including v-model wiring to Script.PushLogEnabled/PushLogPatterns and stateful save semantics that batch updates and avoiding losing edits during async saves.
frontend/src/api/index.ts
frontend/src/api/models/GeneralConfig_Script.ts
frontend/src/api/models/OkNteConfig_Script.ts
frontend/src/api/models/PushLogPattern.ts
frontend/src/api/models/PatternDebugIn.ts
frontend/src/api/models/PatternDebugOut.ts
frontend/src/api/models/PatternDebugResultItem.ts
frontend/src/api/services/ActionService.ts
frontend/src/api/services/Service.ts
frontend/src/types/script.ts
frontend/src/views/EditView/Script/GeneralScriptEdit.vue
frontend/src/views/EditView/Script/components/PushLogConfig.vue
frontend/src/views/EditView/Script/components/LogPatternRule.vue
frontend/src/views/EditView/Script/components/LogPatternDebugModal.vue
frontend/src/views/EditView/Script/LogPatternDocsModal.vue
frontend/src/views/EditView/Script/composables/usePushLogPatterns.ts
frontend/src/views/EditView/Script/composables/useLogPatternDebug.ts
frontend/src/views/EditView/Script/docs/split-doc.md
frontend/src/views/EditView/Script/docs/regex-doc.md
frontend/src/views/EditView/Script/docs/expression-doc.md
frontend/src/views/EditView/Script/docs/multiline-doc.md
Adjust process management and documentation to support more robust script hosting and log-based reporting.
  • Update ProcessManager.search_process to ignore pre-existing processes by enforcing a minimum create_time threshold, reducing the chance of attaching to stale instances.
  • Refine general AutoProxy process status logic to track whether the script process was ever seen and introduce a startup grace period before declaring premature exits, improving success/failure classification.
  • Extend skill documentation to describe using the log_box component and shared push_log tools, and update versioning and ignore settings as needed.
app/utils/ProcessManager.py
app/task/general/AutoProxy.py
.agents/skills/mas-script-specialized-adapter/SKILL.md
.agents/skills/mas-script-specialized-adapter/references/logbox-api.md
res/version.json
.gitignore
requirements.txt

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

# Conflicts:
#	app/utils/__init__.py
#	frontend/src/views/EditView/Script/GeneralScriptEdit.vue
@1w1w11w1

Copy link
Copy Markdown
Contributor

代码审查:PR #399(push_log / log_box)

审查范围:refs/pull/399/head (06f6cc7) 对比 origin/dev,58 文件 +7403/-177。重点看后端采集链路与两处宿主接入,前端主要是格式化改动(GeneralScriptEdit.vue 的实际逻辑改动只有串行保存那一段)。

整体设计方向是对的:把采集能力从专项抽成 log_box、单一 sink 汇入 push_log,表达式引擎与 i18n 独立成模块,职责切得清楚。以下是需要处理的问题,按影响排序。


一、需要修复

1. log_box 的日志轮转处理无法生效,轮转前的内容会静默丢失

app/log_box/collect.py:129_capture() 的唯一调用点(在 _finalize() 内),也就是说 log_box 全程不轮询,整个会话只在 close() 时读一次文件。

app/log_box/sources.py:91-95 的轮转处理是「检测到文件身份变化 → offset 归零 → 重读」。在只读一次的前提下,这个分支只有一个效果:读到轮转后的新文件,轮转前写的全部内容一行都拿不到

对比 app/utils/LogMonitor.py:116-127,那边检测到轮转会显式去加载 bak_log_path 把被轮换的旧日志补回来。log_box 没有这个动作,且因为没有增量读,也不可能有——旧内容从来没被读进来过。

PR 里 d681a533 声称「日志轮转/截断后同步重置采集游标,避免恢复后前段推送日志被跳过丢失」。这个修复对走 LogMonitor 的通用脚本路径是成立的;对 log_box 不成立。okww 单次运行时间较长,ok-script.log 一旦在会话中轮转,节点信息就整段缺失。

建议二选一:要么 LogSource 也支持读 .bak 补偿,要么让 LogCollect 真正增量轮询(既然 _offset 累加逻辑已经写好了)。顺带一提,当前实现是 close 时一次性把整个会话的新增内容读进内存,长时间运行的日志体积也值得关注。

2. app/tools/push_log.py:32 硬编码 "失败",绕过了常量

if log_type != "失败" or has_uncompleted

LOG_TYPE_ERROR 就在 app/utils/LogPatternExtractor.py:58app/log_box/logtype.py 也是规规矩矩 import 的。这里硬编码的后果是:将来改动常量值,过滤逻辑会静默失效——不报错、不告警,只是「失败」类日志开始无条件进报告。改成 import 常量即可。

3. app/task/general/AutoProxy.py:709-715 判态改动使 Success! 需要「曾观测到进程」

改动后要走到 Success!,条件是 _process_seen and not self.success_log。原逻辑只要 not self.success_log 即可。

受影响场景:未配置 SuccessLog、且进程在首次日志回调触发前就已退出的脚本(LogMonitor 1 秒轮询 + 前面还有等待日志文件生成的循环,快速结束的脚本完全可能落进这个窗口)。这类任务原本判 Success!,现在会先等满 90 秒宽限期,再判「脚本在完成任务前退出」。

IfTrackProcess=Falseis_running() 退化为 self.process.returncode is None,所以并非只有开启进程追踪才受影响。

另外 90 秒是硬编码魔数,且从 log_start_time 起算(每次重试重置),不是从进程拉起时刻起算,语义上偏松。建议提为可配置项或至少提取成命名常量并在注释里说明取值依据。

4. app/utils/i18n/translator.py:122 每行翻译都重排整个映射表

for key in sorted(self._map, key=len, reverse=True):

translate() 是逐行调用的前置处理器,每一行都做一次全表 sorted() + 全表 in 扫描。ok.po 条目数量不小,日志行数上万,这个开销完全没必要——排序结果在 load() 之后就固定了。在 load/load_supplement 末尾算一次有序 key 列表缓存起来即可。

5. app/task/Okww/AutoProxy.py:571-574suppress(Exception) 范围过大

with suppress(Exception):
    self.log_collect.close(okww_resolve)
    self.log_translator.clear()

这里会吞掉 okww_resolve 的解析异常、sink 写入异常,以及 prepare() 未执行完时 self.log_collect 不存在导致的 AttributeError——全部无声无息。采集失败时用户只会看到报告里没有节点信息,无从排查。建议至少 logger.warning 记一笔。


二、可以删掉的部分

这块按「先问需不需要存在」的标准过一遍,以下代码当前零调用方:

6. LogSource 的时间过滤是不可达代码

app/log_box/sources.py:50-53start_time / time_format / time_range 三个参数,LogCollect.__init__LogBox.get_collect 都没有传(已 grep 确认无任何传参点)。start_time 恒为 Noneread_new()sources.py:113-114 直接 return,_after_start() 永远不会被调用。参数、字段、方法和那段「对齐 LogMonitor 按时间起始过滤语义」的文档一起删掉,需要时再加。

7. Rule 构建器与 LogCollect.print() / push() 无调用方

app/log_box/rule.py 整个文件(101 行)只被 collect.py__init__.py import,col.rule(...) 没有任何实际调用;okww 走的是 collect(*rule) 声明式路径。LogCollect.print()collect.py:223)是 print() 的一层包装,push() 同样没有调用方。

这些是给「将来的专项适配器」预留的 API,但 bae4321 已经说明脚本宿主通道尚未端到端接通。预留 API 加文档的维护成本是实打实的,等第二个专项接入时按真实需求加更省事。

8. app/utils/__init__.py 新增的 14 个懒加载导出中 8 个无消费方

实际被用到的只有 load_patterns / apply_patterns / flush_patterns / debug_pattern(+compile_regexLOG_TYPE_NORMAL 由 log_box 直接从模块 import)。serialize_patternsvalidate_patterncompile_patternSplitMatcherSUPPORTED_PATTERN_TYPESCompiledMatcherPATTERN_TYPE_SPLIT/REGEX/MULTILINE 全无调用方。

其中 serialize_patternsLogPatternExtractor.py:406-490,85 行)值得单独说:前端 usePushLogPatterns.ts 自己实现了一份序列化,后端这份从未被调用。两份逻辑还不完全等价——前端 enabled=false 且 match 为空时保留该条(if (enabled && !match) continue),后端无条件丢弃。目前不触发问题因为后端那份是死代码,但留着两份会漂移的同构逻辑不如删掉一份。

9. app/task/Okww/push_log.py:114-118last_type 映射是空转

OKWW_PUSH_RULES 全部规则都省略了第三项,所以经 LogCollect.collectlog_type 恒为 LogType.NORMAL。这段按节点名重建类型映射的代码,输出恒等于 "普通"。这与「节点级失败始终展示」的设计是一致的,但那就直接返回 LogType.NORMAL,不需要这层映射。


三、小问题

  • app/models/schema.py:790 描述写的是 {"type":"regex|multiline","pattern":"..."},实际 PushLogPattern 没有 pattern 字段,且支持三种类型(含 split)。文档与契约不一致。
  • app/task/Okww/push_log.py:28 OKWW_SUPPLEMENT_PO = Path.cwd() / ... 在 import 时求值。项目里 Path.cwd() 用得很多,但都在函数或类初始化内部,这里是模块级——依赖 import 时刻的工作目录,比其他用法脆。
  • PushLogPattern.logTypeOptional[str],同一模型的 type 用了 Literal[...]。既然取值只有普通/失败,用 Literal 更省一次运行期归一。
  • app/utils/expression/evaluator.py:139 except (ValueError, TypeError) as e: continuee 未使用。
  • requirements.txt 只是把 sentry-sdktomli_w 两行互换了位置,无实际变更,建议还原以减小 diff。
  • app/log_box/collect.py:76 open() 标注返回 "LogCollect",无参调用实际返回注册器函数。文档(logbox-api.md 陷阱 拆分有关基础逻辑,修改部分变量名称 #6)已经提示了这个形态差异,但类型标注本身仍与实现不符,建议标成 Union[LogCollect, Callable[...]] 或拆成两个方法。

审查方式:worktree 检出 PR head 后读全文,非仅读 diff。第一、三条已通过调用点 grep 与对照 LogMonitor 实现确认;第六至八条的「无调用方」结论均来自全仓 grep。

AthenaHibou and others added 4 commits August 27, 2026 10:21
- log_box 日志源支持轮转 .bak 补偿,避免会话中日志轮转导致前段节点信息丢失
- 通用脚本恢复「进程退出即视为任务完成」的判定,避免未配置成功日志且快速结束的脚本被误判为提前退出;90s 宽限期提为命名常量
- push_log 聚合过滤改用 LOG_TYPE_ERROR 常量,避免硬编码失效
- PoTranslator 缓存按长度排序的键列表,避免逐行翻译重复排序整表
- OK-WW 采集收尾异常记录日志,补充翻译路径改为运行时解析
- 删除无调用方接口:LogSource 时间过滤、Rule 编程式构建器与 print/push、serialize_patterns、冗余的 utils 懒加载导出与 okww last_type 重映射
- 修正 schema 推送模式描述、evaluator 未用变量等小问题
1. 新增OkwwUserConfig_Notify的PushLogEnabled配置项与前端编辑控件
2. 在AutoProxy中根据开关控制log_box的创建与销毁,省采集开销
3. 更新版本日志与开发文档说明该开关的使用模式
4. 调整日志聚合相关注释说明现有逻辑适配新开关
…to pr-399

# Conflicts:
#	.agents/skills/mas-script-specialized-adapter/SKILL.md
#	res/version.json
@1w1w11w1
1w1w11w1 merged commit 9b6d0eb into AUTO-MAS-Project:dev Aug 27, 2026
2 checks passed
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.

3 participants