Skip to content

Commit 2a90cb4

Browse files
Natsuusourcery-ai[bot]MistEO
authored
docs: clarify on_error logic in pipeline protocol (#1251)
## Summary by Sourcery 澄清并重构关于流水线节点生命周期和 `on_error` 行为的文档,并整理代理(agent)文档中的相关表格。 Enhancements: - 通过用新的「Node Flow」章节替换旧的流程图来整合节点生命周期文档,从而减少重复内容。 Documentation: - 使用更新后的 Mermaid 流程图和专门的「Node Flow」章节,记录详细的节点生命周期流程。 - 澄清 `on_error` 节点在何时执行,明确将该行为与下一个节点的识别超时关联起来,并链接到新的流程图。 - 调整 `AGENTS.md` 中的 Markdown 表格格式,以确保间距一致并提升可读性。 <details> <summary>Original summary in English</summary> ## Summary by Sourcery Clarify and restructure documentation of the pipeline node lifecycle and on_error behavior, and tidy related tables in agent docs. Enhancements: - Consolidate the node lifecycle documentation by replacing the older flowchart with the new Node Flow section to reduce duplication. Documentation: - Document the detailed node lifecycle flow with an updated Mermaid flowchart and dedicated Node Flow section. - Clarify when on_error nodes are executed, explicitly tying the behavior to next node recognition timeout and linking to the new flowchart. - Adjust Markdown table formatting in AGENTS.md for consistent spacing and readability. </details> --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: MistEO <mistereo@hotmail.com>
1 parent b273a7a commit 2a90cb4

3 files changed

Lines changed: 56 additions & 54 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ MaaFramework/
6161
### 术语定义
6262

6363
| 术语 | 说明 |
64-
|------|------|
64+
| ------ | ------ |
6565
| **Node(节点)** | Pipeline JSON 中的一个完整对象,包含识别、动作、后继节点等配置 |
6666
| **Task(任务)** | 若干 Node 按顺序相连的逻辑流程 |
6767
| **Entry(入口)** | Task 中的第一个 Node |
@@ -91,7 +91,7 @@ MaaFramework/
9191
### 识别算法类型
9292

9393
| 类型 | 说明 | 关键参数 |
94-
|------|------|----------|
94+
| ------ | ------ | ---------- |
9595
| `DirectHit` | 直接命中,不进行识别 | - |
9696
| `TemplateMatch` | 模板匹配(找图) | `template`, `threshold`, `roi` |
9797
| `FeatureMatch` | 特征匹配(抗透视) | `template`, `count`, `detector` |
@@ -104,7 +104,7 @@ MaaFramework/
104104
### 动作类型
105105

106106
| 类型 | 说明 | 关键参数 |
107-
|------|------|----------|
107+
| ------ | ------ | ---------- |
108108
| `DoNothing` | 不执行任何操作 | - |
109109
| `Click` | 点击 | `target`, `target_offset` |
110110
| `LongPress` | 长按 | `target`, `duration` |

docs/en_us/3.1-PipelineProtocol.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ The task process terminates when any of the following conditions are met:
4747
- The current node's `next` list misses until timeout
4848
- External `post_stop` is called or `StopTask` action is executed
4949

50+
## Node Flow
51+
52+
A node's lifecycle is as follows:
53+
54+
```mermaid
55+
flowchart TB
56+
A[enter the node] --> B[pre_wait_freezes]
57+
B --> C[pre_delay]
58+
C --> D[action]
59+
D --> M{"repeat > 1?"}
60+
M -->|yes| N[repeat_wait_freezes]
61+
N --> O[repeat_delay]
62+
O --> D
63+
M -->|no| E[post_wait_freezes]
64+
E --> F[post_delay]
65+
F --> P[screenshot]
66+
P --> G[recognize next]
67+
G --> H{successfully identified nodes}
68+
H -->|yes| I[enter a new node]
69+
H -->|no| J{"timer timeout"}
70+
J -->|yes| K[on_error]
71+
J -->|no| L[wait for rate_limit]
72+
L --> P
73+
```
74+
5075
## Application Examples
5176

5277
### Scenario Description
@@ -193,7 +218,7 @@ Typical flow: recognize inside `roi` (with `roi_offset`), get `box`, then calcul
193218
Can be approximated as `while(!hit && !timeout) { foreach(next); sleep_until(rate_limit); }`.
194219

195220
- `on_error` : *string* | *NodeAttr* | *list<string | NodeAttr, >*
196-
Failure successors. These nodes are executed next when the current node's `next` list times out, or when a hit sub-node's action fails. Optional, empty by default.
221+
When **this node's** next list has no matching nodes and the loop recognition times out, or when the action fails to execute, the nodes in this list will be executed next (see [flowchart](#node-flow)). Optional, empty by default.
197222
💡 Since v5.1, nodes with attributes, NodeAttr objects, or heterogeneous arrays combining both are supported. See [Node Attributes](#node-attributes) for details.
198223

199224
- `anchor`: *string* | *list<string, >* | *object* **💡 v5.1**
@@ -261,30 +286,6 @@ Typical flow: recognize inside `roi` (with `roi_offset`), get `box`, then calcul
261286
This field can be used to store custom configuration information that does not affect the node's execution logic but can be retrieved through related interfaces.
262287
**Note**: This field will be merged with the `attach` in the default value using dict merge, not overwritten. That is, the `attach` in the node will be merged with the `attach` in the default value, where values with the same keys will be overwritten by the node's values, but other keys will be preserved.
263288

264-
The lifecycle of a node is as follows:
265-
266-
```mermaid
267-
graph TB
268-
A[enter the node] --> B[pre_wait_freezes]
269-
B --> C[pre_delay]
270-
C --> D[action]
271-
D --> M{repeat > 1?}
272-
M -->|yes| N[repeat_wait_freezes]
273-
N --> O[repeat_delay]
274-
O --> D
275-
M -->|no| E[post_wait_freezes]
276-
E --> F[post_delay]
277-
F --> Q[start timer]
278-
Q --> P[screenshot]
279-
P --> G[recognize next]
280-
G --> H{successfully identified nodes}
281-
H -->|yes| I[enter a new node]
282-
H -->|no| J{timeout}
283-
J -->|yes| K[on_error]
284-
J -->|no| L[wait for rate_limit]
285-
L --> P
286-
```
287-
288289
### Pipeline v2
289290

290291
> [!NOTE]

docs/zh_cn/3.1-任务流水线协议.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@
5151
- 当前节点的 `next` 列表未命中且超时
5252
- 外部调用 `post_stop` 或执行了 `StopTask` 动作
5353

54+
## 节点流程
55+
56+
一个节点的生命周期如下:
57+
58+
```mermaid
59+
flowchart TB
60+
A[进入节点] --> B[pre_wait_freezes]
61+
B --> C[pre_delay]
62+
C --> D[action]
63+
D --> M{"repeat > 1?"}
64+
M -->|是| N[repeat_wait_freezes]
65+
N --> O[repeat_delay]
66+
O --> D
67+
M -->|否| E[post_wait_freezes]
68+
E --> F[post_delay]
69+
F --> P[截图]
70+
P --> G[识别next]
71+
G --> H{"是否有识别成功的节点"}
72+
H -->|是| I[进入新节点]
73+
H -->|否| J{"检查计时"}
74+
J -->|超时| K[on_error]
75+
J -->|未超时| L[等待rate_limit]
76+
L --> P
77+
```
78+
5479
## 应用示例
5580

5681
### 场景描述
@@ -155,7 +180,7 @@ Android 设置界面存在菜单 `显示`/`存储`/`无障碍`,其中 `存储`
155180
| ---- | -------- |
156181
| v5.0 | 新增 `attach` 字段; 新增 `TouchDown` `TouchMove` `TouchUp` `KeyDown` `KeyUp` 动作; Click / LongPress / Swipe / MultiSwipe 新增 `contact` `pressure` 字段; `target` 新增 `[x, y]` 二元坐标支持 |
157182
| v5.1 | 新增 `anchor` `max_hit` 字段; 新增 `Scroll` 动作; 新增节点属性(`jump_back` / `anchor`); `next` / `on_error` 新增 NodeAttr 支持; `order_by` 新增 `Expected` 排序; `is_sub` / `interrupt` 废弃 |
158-
| v5.3 | 新增 `repeat` `repeat_delay` `repeat_wait_freezes` 字段; 新增 `And` `Or` 识别类型; 新增 `Shell` 动作; TemplateMatch `method` 新增 `10001`; 新增默认属性(`default_pipeline.json`|
183+
| v5.3 | 新增 `repeat` `repeat_delay` `repeat_wait_freezes` 字段; 新增 `And` `Or` 识别类型; 新增 `Shell` 动作; TemplateMatch `method` 新增 `10001`; 新增默认属性(`default_pipeline.json` |
159184
| v5.5 | `timeout` 新增 `-1`(无限等待)支持; Scroll 新增 `target` `target_offset` |
160185
| v5.6 | `roi` / `target` 支持负数坐标和尺寸 |
161186
| v5.7 | `anchor` 新增 object 形式(指定目标节点 / 清除锚点); `And` / `Or` 新增节点名称引用支持 |
@@ -197,7 +222,7 @@ Android 设置界面存在菜单 `显示`/`存储`/`无障碍`,其中 `存储`
197222
可近似理解为 `while(!hit && !timeout) { foreach(next); sleep_until(rate_limit); }`
198223

199224
- `on_error` : *string* | *NodeAttr* | *list<string | NodeAttr, >*
200-
失败后继列表。当当前节点的 `next` 列表识别超时,或某个子节点识别命中后动作失败时,会执行该列表中的节点。可选,默认空。
225+
**本节点**内的 `next` 列表中没有任何节点命中并且循环识别超时,或动作执行失败后,接下来会执行该列表中的节点(参见[流程图](#节点流程)。可选,默认空。
201226
💡 v5.1 版本起新增支持带属性节点、 NodeAttr 形式对象,或两者结合的异质数组。详情请参考 [节点属性](#节点属性)
202227

203228
- `anchor`: *string* | *list<string, >* | *object* **💡 v5.1**
@@ -267,30 +292,6 @@ Android 设置界面存在菜单 `显示`/`存储`/`无障碍`,其中 `存储`
267292
该字段可用于存储自定义的配置信息,这些信息不会影响节点的执行逻辑,但可以通过相关接口获取。
268293
**注意**:该字段会与默认值中的 `attach` 进行字典合并(dict merge),而不是覆盖。即节点中的 `attach` 会与默认值中的 `attach` 合并,相同键的值会被节点中的值覆盖,但其他键会保留。
269294

270-
一个节点的生命周期如下
271-
272-
```mermaid
273-
graph TB
274-
A[进入节点] --> B[pre_wait_freezes]
275-
B --> C[pre_delay]
276-
C --> D[action]
277-
D --> M{repeat > 1?}
278-
M -->|是| N[repeat_wait_freezes]
279-
N --> O[repeat_delay]
280-
O --> D
281-
M -->|否| E[post_wait_freezes]
282-
E --> F[post_delay]
283-
F --> Q[开始计时]
284-
Q --> P[截图]
285-
P --> G[识别next]
286-
G --> H{是否有识别成功的节点}
287-
H -->|是| I[进入新节点]
288-
H -->|否| J{timeout}
289-
J -->|超时| K[on_error]
290-
J -->|未超时| L[等待rate_limit]
291-
L --> P
292-
```
293-
294295
### Pipeline v2
295296

296297
> [!NOTE]

0 commit comments

Comments
 (0)