feat: add optional anchor info for reco sink#1187
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些整体性的反馈:
- 新的
run_recognition函数签名让所有调用方都必须传入anchor_name,而且改变了ocr_cache这个默认参数的位置;建议给anchor_name一个默认值(例如std::nullopt),或者增加一个重载,以避免破坏现有调用点和 API 预期。 - 在
PipelineTask::recognize_list中,锚点参数的构造方式是node.anchor ? std::optional<std::string>{ node.name } : std::nullopt;如果目的是曝光锚点而不是节点名称,这里很可能应该使用锚点的值而不是节点名。 - 为了在传递可选锚点时避免不必要的字符串拷贝,建议把
run_recognition的参数改为const std::optional<std::string>& anchor_name(并相应更新调用处)。
给 AI Agent 的 Prompt
Please address the comments from this code review:
## Overall Comments
- 新的 `run_recognition` 函数签名让所有调用方都必须传入 `anchor_name`,而且改变了 `ocr_cache` 这个默认参数的位置;建议给 `anchor_name` 一个默认值(例如 `std::nullopt`),或者增加一个重载,以避免破坏现有调用点和 API 预期。
- 在 `PipelineTask::recognize_list` 中,锚点参数的构造方式是 `node.anchor ? std::optional<std::string>{ node.name } : std::nullopt`;如果目的是曝光锚点而不是节点名称,这里很可能应该使用锚点的值而不是节点名。
- 为了在传递可选锚点时避免不必要的字符串拷贝,建议把 `run_recognition` 的参数改为 `const std::optional<std::string>& anchor_name`(并相应更新调用处)。
## Individual Comments
### Comment 1
<location path="source/MaaFramework/Task/TaskBase.cpp" line_range="84-85" />
<code_context>
{ "name", data.name },
{ "focus", data.focus },
};
+ if (anchor_name) {
+ cb_detail["anchor"] = *anchor_name;
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** 在当前实现中,如果 `anchor` 不存在,运行时负载会完全省略这个字段,而 MaaMsg 的约定是 `string | null`。
按照现在的写法,下游使用方只能看到字符串或缺失的 `anchor` 字段,而不会看到 `null`。如果有任何下游代码依赖该字段总是存在,或者明确为 `null`,这会引入一个隐蔽的破坏性变更。请在 `anchor_name` 未设置时始终将 `"anchor"` 设为 `null`,或者更新 MaaMsg 的约定以反映新的行为。
</issue_to_address>帮我变得更有用!请对每条评论点 👍 或 👎,我会根据这些反馈改进之后的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The new
run_recognitionsignature makesanchor_namemandatory for all callers and shifts theocr_cachedefault argument; consider givinganchor_namea default (e.g.,std::nullopt) or adding an overload to avoid breaking existing call sites and API expectations. - In
PipelineTask::recognize_list, the anchor argument is built asnode.anchor ? std::optional<std::string>{ node.name } : std::nullopt; if the intent is to surface the anchor rather than the node name, this likely should use the anchor value instead. - To avoid an unnecessary string copy when passing the optional anchor, consider changing
run_recognitionto takeconst std::optional<std::string>& anchor_name(and update the call site accordingly).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `run_recognition` signature makes `anchor_name` mandatory for all callers and shifts the `ocr_cache` default argument; consider giving `anchor_name` a default (e.g., `std::nullopt`) or adding an overload to avoid breaking existing call sites and API expectations.
- In `PipelineTask::recognize_list`, the anchor argument is built as `node.anchor ? std::optional<std::string>{ node.name } : std::nullopt`; if the intent is to surface the anchor rather than the node name, this likely should use the anchor value instead.
- To avoid an unnecessary string copy when passing the optional anchor, consider changing `run_recognition` to take `const std::optional<std::string>& anchor_name` (and update the call site accordingly).
## Individual Comments
### Comment 1
<location path="source/MaaFramework/Task/TaskBase.cpp" line_range="84-85" />
<code_context>
{ "name", data.name },
{ "focus", data.focus },
};
+ if (anchor_name) {
+ cb_detail["anchor"] = *anchor_name;
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** The runtime payload omits `anchor` entirely when absent, while the MaaMsg contract says `string | null`.
As written, consumers will now see either a string or a missing `anchor` field, never `null`. If any downstream code depends on the field always existing or being explicitly `null`, this introduces a subtle breaking change. Please either always set `"anchor"` to `null` when `anchor_name` is unset, or update the MaaMsg contract to reflect the new behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
neko-para/maa-support-extension#64
Summary by Sourcery
为节点识别事件添加可选的锚点元数据,并在识别管线和各语言绑定中贯通锚点信息。
New Features:
Enhancements:
Original summary in English
Summary by Sourcery
Add optional anchor metadata to node recognition events and plumb anchor information through the recognition pipeline and language bindings.
New Features:
Enhancements: