feat(AutoEcoFarm):引入一个新的自动生态农场收获任务,并将其接入现有的界面和任务配置中。#934
feat(AutoEcoFarm):引入一个新的自动生态农场收获任务,并将其接入现有的界面和任务配置中。#934MistEO merged 34 commits intoMaaEnd:mainfrom
Conversation
fix2:因为win32前台的DXGI_DesktopDup_Window方式有bug,将screencap参数改成PrintWindow
There was a problem hiding this comment.
Hey - 我发现了 3 个问题,并给出了一些总体反馈:
- 在
autoecofarm.go中,embed的导入和RecognitionDetailJson的解析结果目前都没有被使用;建议删除这个导入,并/或把解析出来的识别数据接入逻辑中,以避免产生死代码。 - 在
MoveToTarget3D中的旋转角度计算中,日志使用的是RealangleDeg,但swipex仍然是从angleDeg推导出来的;将滑动距离与同一个变换后的角度对齐(或者说明它们为什么不同)会让行为更清晰,也更不容易出错。 - 硬编码的屏幕尺寸和
FootY默认值(screenW、screenH、footX、FootY: 500)可能与运行环境不匹配;将它们暴露为可配置项或从上下文中推导,可以提升在不同设备上的健壮性。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `autoecofarm.go`, the `embed` import and the `RecognitionDetailJson` parsing result are currently unused; consider removing the import and/or wiring the parsed recognition data into the logic to avoid dead code.
- The rotation angle calculation in `MoveToTarget3D` uses `RealangleDeg` for logging but still derives `swipex` from `angleDeg`; aligning the swipe distance with the same transformed angle (or documenting why they differ) would make the behavior clearer and less error-prone.
- The hard-coded screen dimensions and `FootY` default (`screenW`, `screenH`, `footX`, `FootY: 500`) may not match all runtime environments; exposing these as configuration or deriving them from context would improve robustness across devices.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="110-115" />
<code_context>
+ angleRad := math.Atan2(deltax, -deltay)
+ angleDeg := angleRad * 180.0 / math.Pi
+ //将屏幕角度通过映射转换成实际角度
+ RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg
+
+ msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg)
+ maafocus.NodeActionStarting(ctx, msg1)
+
+ swipex := int(angleDeg / 90 * rotate90)
+ msg2 := fmt.Sprintf("需要移动%d像素", swipex)
+ maafocus.NodeActionStarting(ctx, msg2)
</code_context>
<issue_to_address>
**issue (bug_risk):** Rotation distance is computed from angleDeg instead of RealangleDeg, which likely breaks the pitch correction logic.
`RealangleDeg` compensates for camera pitch via `Y2Pitch`, but the swipe distance still uses `angleDeg`. If rotation should follow the pitch-corrected angle, derive `swipex` from `RealangleDeg`; otherwise remove `RealangleDeg`. As is, the pitch mapping does not affect swipe distance and can cause rotation misalignment.
</issue_to_address>
### Comment 2
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="169-172" />
<code_context>
+ threshold := params.Threshold
+
+ //判断box是否为空
+ if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 {
+ err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)",
+ arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height())
+ log.Error().Err(err).Msg("目标坐标读取失败")
+ return false // 必须返回false,终止执行
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Box validation treats X/Y=0 as invalid, which can reject valid targets at the screen edges.
This will reject boxes at the left/top edge where X or Y is 0, even though those are valid coordinates. If the intent is only to forbid empty boxes, check Width()/Height() for `<= 0` instead, and optionally handle an all-zero box explicitly if that’s your sentinel case.
</issue_to_address>
### Comment 3
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="62-71" />
<code_context>
+ var params = MoveToTarget3DParam{
+ FootY: 500,
+ }
+ var results = RecognitionDetailJson{}
+
+ //解析 JSON 参数到结构体中
+ err := json.Unmarshal([]byte(arg.CustomActionParam), ¶ms)
+ if err != nil {
+ log.Error().Err(err).Msg("参数解析失败")
+ maafocus.NodeActionStarting(ctx, "参数解析失败")
+ return false
+ }
+ msg_foot := fmt.Sprintf("当前角色脚的y坐标是:%d", params.FootY)
+ maafocus.NodeActionStarting(ctx, msg_foot)
+
+ err = json.Unmarshal([]byte(arg.RecognitionDetail.DetailJson), &results)
+ if err != nil {
+ log.Error().Err(err).Msg("识别区域解析失败")
</code_context>
<issue_to_address>
**suggestion:** RecognitionDetailJson is parsed but never used, adding unnecessary work and complexity.
`RecognitionDetail.DetailJson` is unmarshalled into `results` but never read. If this information isn’t required here, remove the `RecognitionDetailJson` struct usage, the unmarshal, and related logging to avoid unnecessary parsing and complexity.
Suggested implementation:
```golang
//初始化结构体默认值
var params = MoveToTarget3DParam{
FootY: 500,
}
```
```golang
msg_json := fmt.Sprintf("Value JSON: %s\n", arg.RecognitionDetail.DetailJson)
maafocus.NodeActionStarting(ctx, msg_json)
```
</issue_to_address>帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've found 3 issues, and left some high level feedback:
- In
autoecofarm.go, theembedimport and theRecognitionDetailJsonparsing result are currently unused; consider removing the import and/or wiring the parsed recognition data into the logic to avoid dead code. - The rotation angle calculation in
MoveToTarget3DusesRealangleDegfor logging but still derivesswipexfromangleDeg; aligning the swipe distance with the same transformed angle (or documenting why they differ) would make the behavior clearer and less error-prone. - The hard-coded screen dimensions and
FootYdefault (screenW,screenH,footX,FootY: 500) may not match all runtime environments; exposing these as configuration or deriving them from context would improve robustness across devices.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `autoecofarm.go`, the `embed` import and the `RecognitionDetailJson` parsing result are currently unused; consider removing the import and/or wiring the parsed recognition data into the logic to avoid dead code.
- The rotation angle calculation in `MoveToTarget3D` uses `RealangleDeg` for logging but still derives `swipex` from `angleDeg`; aligning the swipe distance with the same transformed angle (or documenting why they differ) would make the behavior clearer and less error-prone.
- The hard-coded screen dimensions and `FootY` default (`screenW`, `screenH`, `footX`, `FootY: 500`) may not match all runtime environments; exposing these as configuration or deriving them from context would improve robustness across devices.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="110-115" />
<code_context>
+ angleRad := math.Atan2(deltax, -deltay)
+ angleDeg := angleRad * 180.0 / math.Pi
+ //将屏幕角度通过映射转换成实际角度
+ RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg
+
+ msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg)
+ maafocus.NodeActionStarting(ctx, msg1)
+
+ swipex := int(angleDeg / 90 * rotate90)
+ msg2 := fmt.Sprintf("需要移动%d像素", swipex)
+ maafocus.NodeActionStarting(ctx, msg2)
</code_context>
<issue_to_address>
**issue (bug_risk):** Rotation distance is computed from angleDeg instead of RealangleDeg, which likely breaks the pitch correction logic.
`RealangleDeg` compensates for camera pitch via `Y2Pitch`, but the swipe distance still uses `angleDeg`. If rotation should follow the pitch-corrected angle, derive `swipex` from `RealangleDeg`; otherwise remove `RealangleDeg`. As is, the pitch mapping does not affect swipe distance and can cause rotation misalignment.
</issue_to_address>
### Comment 2
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="169-172" />
<code_context>
+ threshold := params.Threshold
+
+ //判断box是否为空
+ if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 {
+ err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)",
+ arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height())
+ log.Error().Err(err).Msg("目标坐标读取失败")
+ return false // 必须返回false,终止执行
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Box validation treats X/Y=0 as invalid, which can reject valid targets at the screen edges.
This will reject boxes at the left/top edge where X or Y is 0, even though those are valid coordinates. If the intent is only to forbid empty boxes, check Width()/Height() for `<= 0` instead, and optionally handle an all-zero box explicitly if that’s your sentinel case.
</issue_to_address>
### Comment 3
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="62-71" />
<code_context>
+ var params = MoveToTarget3DParam{
+ FootY: 500,
+ }
+ var results = RecognitionDetailJson{}
+
+ //解析 JSON 参数到结构体中
+ err := json.Unmarshal([]byte(arg.CustomActionParam), ¶ms)
+ if err != nil {
+ log.Error().Err(err).Msg("参数解析失败")
+ maafocus.NodeActionStarting(ctx, "参数解析失败")
+ return false
+ }
+ msg_foot := fmt.Sprintf("当前角色脚的y坐标是:%d", params.FootY)
+ maafocus.NodeActionStarting(ctx, msg_foot)
+
+ err = json.Unmarshal([]byte(arg.RecognitionDetail.DetailJson), &results)
+ if err != nil {
+ log.Error().Err(err).Msg("识别区域解析失败")
</code_context>
<issue_to_address>
**suggestion:** RecognitionDetailJson is parsed but never used, adding unnecessary work and complexity.
`RecognitionDetail.DetailJson` is unmarshalled into `results` but never read. If this information isn’t required here, remove the `RecognitionDetailJson` struct usage, the unmarshal, and related logging to avoid unnecessary parsing and complexity.
Suggested implementation:
```golang
//初始化结构体默认值
var params = MoveToTarget3DParam{
FootY: 500,
}
```
```golang
msg_json := fmt.Sprintf("Value JSON: %s\n", arg.RecognitionDetail.DetailJson)
maafocus.NodeActionStarting(ctx, msg_json)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg | ||
|
|
||
| msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg) | ||
| maafocus.NodeActionStarting(ctx, msg1) | ||
|
|
||
| swipex := int(angleDeg / 90 * rotate90) |
There was a problem hiding this comment.
issue (bug_risk): 旋转距离是根据 angleDeg 而不是 RealangleDeg 计算的,这很可能会破坏俯仰角校正逻辑。
RealangleDeg 通过 Y2Pitch 来补偿相机俯仰,但滑动距离仍然使用 angleDeg。如果旋转应该遵从俯仰校正后的角度,应该从 RealangleDeg 推导 swipex;否则就移除 RealangleDeg。按目前写法,俯仰映射不会影响滑动距离,可能导致旋转偏移。
Original comment in English
issue (bug_risk): Rotation distance is computed from angleDeg instead of RealangleDeg, which likely breaks the pitch correction logic.
RealangleDeg compensates for camera pitch via Y2Pitch, but the swipe distance still uses angleDeg. If rotation should follow the pitch-corrected angle, derive swipex from RealangleDeg; otherwise remove RealangleDeg. As is, the pitch mapping does not affect swipe distance and can cause rotation misalignment.
| if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 { | ||
| err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)", | ||
| arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height()) | ||
| log.Error().Err(err).Msg("目标坐标读取失败") |
There was a problem hiding this comment.
issue (bug_risk): Box 校验把 X/Y=0 当作无效,这会导致屏幕边缘上合法的目标被拒绝。
这样会拒绝左侧/顶部边缘上 X 或 Y 为 0 的 box,尽管这些坐标是合法的。如果你的意图只是禁止空 box,建议只对 Width()/Height() 做 <= 0 校验,并在需要时额外处理“全 0 box”这种特例(如果它是你约定的哨兵值)。
Original comment in English
issue (bug_risk): Box validation treats X/Y=0 as invalid, which can reject valid targets at the screen edges.
This will reject boxes at the left/top edge where X or Y is 0, even though those are valid coordinates. If the intent is only to forbid empty boxes, check Width()/Height() for <= 0 instead, and optionally handle an all-zero box explicitly if that’s your sentinel case.
| var results = RecognitionDetailJson{} | ||
|
|
||
| //解析 JSON 参数到结构体中 | ||
| err := json.Unmarshal([]byte(arg.CustomActionParam), ¶ms) | ||
| if err != nil { | ||
| log.Error().Err(err).Msg("参数解析失败") | ||
| maafocus.NodeActionStarting(ctx, "参数解析失败") | ||
| return false | ||
| } | ||
| msg_foot := fmt.Sprintf("当前角色脚的y坐标是:%d", params.FootY) |
There was a problem hiding this comment.
suggestion: RecognitionDetailJson 被解析出来却从未使用,只会增加不必要的计算和复杂度。
RecognitionDetail.DetailJson 被反序列化到 results 中,但之后完全没有被读取。如果这些信息在当前逻辑中并不需要,建议移除 RecognitionDetailJson 结构体的使用、反序列化代码以及相关日志,以避免不必要的解析和复杂度。
Suggested implementation:
//初始化结构体默认值
var params = MoveToTarget3DParam{
FootY: 500,
} msg_json := fmt.Sprintf("Value JSON: %s\n", arg.RecognitionDetail.DetailJson)
maafocus.NodeActionStarting(ctx, msg_json)Original comment in English
suggestion: RecognitionDetailJson is parsed but never used, adding unnecessary work and complexity.
RecognitionDetail.DetailJson is unmarshalled into results but never read. If this information isn’t required here, remove the RecognitionDetailJson struct usage, the unmarshal, and related logging to avoid unnecessary parsing and complexity.
Suggested implementation:
//初始化结构体默认值
var params = MoveToTarget3DParam{
FootY: 500,
} msg_json := fmt.Sprintf("Value JSON: %s\n", arg.RecognitionDetail.DetailJson)
maafocus.NodeActionStarting(ctx, msg_json)…feat/AutoEcoFarm
There was a problem hiding this comment.
Hey - 我发现了 3 个问题,并给出了一些整体性的反馈:
- 3D 移动逻辑里对
screenW、screenH和footX进行了硬编码,这会在其他分辨率或纵横比下失效;建议从运行时上下文或配置中推导这些值,而不是使用常量。 - 在
MoveToTarget3D.Run中,RecognitionDetailJson被填充了但从未真正使用(只使用了arg.Box);要么移除未使用的解析/日志代码,要么改为使用解析得到的 box,以避免死代码并减少日志噪音。 autoecofarm/register.go中Register函数的注释仍然提到“aspect ratio checker”;请更新注释,让其准确描述 AutoEcoFarm 自定义动作的注册逻辑,以避免在维护该模块时造成混淆。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- 3D movement logic hardcodes `screenW`, `screenH`, and `footX`, which will break on other resolutions or aspect ratios; consider deriving these from the runtime context or configuration instead of constants.
- In `MoveToTarget3D.Run`, `RecognitionDetailJson` is populated but never actually used (only `arg.Box` is used); either remove the unused parsing/logging or switch to using the parsed box to avoid dead code and reduce log noise.
- The `Register` function comment in `autoecofarm/register.go` still mentions "aspect ratio checker"; update it to accurately describe registration of the AutoEcoFarm custom actions to avoid confusion when maintaining this module.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="110-115" />
<code_context>
+ angleRad := math.Atan2(deltax, -deltay)
+ angleDeg := angleRad * 180.0 / math.Pi
+ //将屏幕角度通过映射转换成实际角度
+ RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg
+
+ msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg)
+ maafocus.NodeActionStarting(ctx, msg1)
+
+ swipex := int(angleDeg / 90 * rotate90)
+ msg2 := fmt.Sprintf("需要移动%d像素", swipex)
+ maafocus.NodeActionStarting(ctx, msg2)
</code_context>
<issue_to_address>
**issue (bug_risk):** 计算出来的 RealangleDeg 没有用于滑动距离,这可能会削弱基于俯仰缩放的意义。
`RealangleDeg` 是通过 `Y2Pitch` 计算得到的,但只用于日志输出;`swipex` 仍然使用 `angleDeg`(`swipex := int(angleDeg / 90 * rotate90)`)。如果目的是根据俯仰对旋转/移动进行校准,`swipex` 很可能应该基于 `RealangleDeg`,或者代码需要澄清为什么俯仰缩放没有应用到实际滑动上。就目前而言,`Y2Pitch` 对行为没有任何影响。
</issue_to_address>
### Comment 2
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="169-173" />
<code_context>
+ duration := time.Duration(params.Duration) * time.Millisecond
+
+ //判断box是否为空
+ if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 {
+ err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)",
+ arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height())
+ log.Error().Err(err).Msg("目标坐标读取失败")
+ return false // 必须返回false,终止执行
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** 将 X==0 或 Y==0 视为无效会拒绝位于屏幕顶部/左侧边缘的合法目标。
使用 `X() == 0 || Y() == 0` 会把任何接触左边或上边缘的 box 都视为无效,即便其宽高是正数。如果目标是检测“空 box”,应改为根据尺寸(以及符号)来判断,例如 `if arg.Box.Width() <= 0 || arg.Box.Height() <= 0 { ... }`。
</issue_to_address>
### Comment 3
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="165-166" />
<code_context>
+ stepRatio := params.StepRatio
</code_context>
<issue_to_address>
**suggestion (bug_risk):** StepRatio 没有被限制范围,在极端取值时可能导致过冲或完全不移动。
由于 `stepRatio` 是从 JSON 中读取的,像 `0`、负数或者大于 1 的值都可能导致完全不移动或步长过大。建议在用于计算滑动前,将其钳制到一个安全范围内(例如 `[0.1, 1.0]`)。
```suggestion
stepRatio := params.StepRatio
// Clamp stepRatio to a safe range to avoid no movement or overshoot
if stepRatio < 0.1 {
stepRatio = 0.1
} else if stepRatio > 1.0 {
stepRatio = 1.0
}
duration := time.Duration(params.Duration) * time.Millisecond
```
</issue_to_address>Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Original comment in English
Hey - I've found 3 issues, and left some high level feedback:
- The 3D movement logic hardcodes
screenW,screenH, andfootX, which will break on other resolutions or aspect ratios; consider deriving these from the runtime context or configuration instead of constants. - In
MoveToTarget3D.Run,RecognitionDetailJsonis populated but never actually used (onlyarg.Boxis used); either remove the unused parsing/logging or switch to using the parsed box to avoid dead code and reduce log noise. - The
Registerfunction comment inautoecofarm/register.gostill mentions "aspect ratio checker"; update it to accurately describe registration of the AutoEcoFarm custom actions to avoid confusion when maintaining this module.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The 3D movement logic hardcodes `screenW`, `screenH`, and `footX`, which will break on other resolutions or aspect ratios; consider deriving these from the runtime context or configuration instead of constants.
- In `MoveToTarget3D.Run`, `RecognitionDetailJson` is populated but never actually used (only `arg.Box` is used); either remove the unused parsing/logging or switch to using the parsed box to avoid dead code and reduce log noise.
- The `Register` function comment in `autoecofarm/register.go` still mentions "aspect ratio checker"; update it to accurately describe registration of the AutoEcoFarm custom actions to avoid confusion when maintaining this module.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="110-115" />
<code_context>
+ angleRad := math.Atan2(deltax, -deltay)
+ angleDeg := angleRad * 180.0 / math.Pi
+ //将屏幕角度通过映射转换成实际角度
+ RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg
+
+ msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg)
+ maafocus.NodeActionStarting(ctx, msg1)
+
+ swipex := int(angleDeg / 90 * rotate90)
+ msg2 := fmt.Sprintf("需要移动%d像素", swipex)
+ maafocus.NodeActionStarting(ctx, msg2)
</code_context>
<issue_to_address>
**issue (bug_risk):** The computed RealangleDeg is not used for swipe distance, which may defeat the purpose of the pitch-based scaling.
`RealangleDeg` is computed via `Y2Pitch` but only used for logging; `swipex` still uses `angleDeg` (`swipex := int(angleDeg / 90 * rotate90)`). If the goal is to pitch-calibrate the rotation/movement, `swipex` should likely be based on `RealangleDeg`, or the code should clarify why pitch scaling is not applied to the actual swipe. As is, `Y2Pitch` has no behavioral effect.
</issue_to_address>
### Comment 2
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="169-173" />
<code_context>
+ duration := time.Duration(params.Duration) * time.Millisecond
+
+ //判断box是否为空
+ if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 {
+ err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)",
+ arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height())
+ log.Error().Err(err).Msg("目标坐标读取失败")
+ return false // 必须返回false,终止执行
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Treating X==0 or Y==0 as invalid will reject valid targets at the top/left edge of the screen.
Using `X() == 0 || Y() == 0` treats any box touching the left or top edge as invalid, even when width/height are positive. If the goal is to detect empty boxes, guard on size (and sign) instead, e.g. `if arg.Box.Width() <= 0 || arg.Box.Height() <= 0 { ... }`.
</issue_to_address>
### Comment 3
<location path="agent/go-service/autoecofarm/autoecofarm.go" line_range="165-166" />
<code_context>
+ stepRatio := params.StepRatio
</code_context>
<issue_to_address>
**suggestion (bug_risk):** StepRatio is not bounded, which can cause overshoot or no movement with extreme values.
Because `stepRatio` is read from JSON, values like `0`, negatives, or >1 can cause no movement or overly large jumps. Consider clamping it to a safe range (e.g. `[0.1, 1.0]`) before using it in the swipe calculation.
```suggestion
stepRatio := params.StepRatio
// Clamp stepRatio to a safe range to avoid no movement or overshoot
if stepRatio < 0.1 {
stepRatio = 0.1
} else if stepRatio > 1.0 {
stepRatio = 1.0
}
duration := time.Duration(params.Duration) * time.Millisecond
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| RealangleDeg := Y2Pitch(float64(params.FootY)) / 45 * angleDeg | ||
|
|
||
| msg1 := fmt.Sprintf("需要旋转%.0f°", RealangleDeg) | ||
| maafocus.NodeActionStarting(ctx, msg1) | ||
|
|
||
| swipex := int(angleDeg / 90 * rotate90) |
There was a problem hiding this comment.
issue (bug_risk): 计算出来的 RealangleDeg 没有用于滑动距离,这可能会削弱基于俯仰缩放的意义。
RealangleDeg 是通过 Y2Pitch 计算得到的,但只用于日志输出;swipex 仍然使用 angleDeg(swipex := int(angleDeg / 90 * rotate90))。如果目的是根据俯仰对旋转/移动进行校准,swipex 很可能应该基于 RealangleDeg,或者代码需要澄清为什么俯仰缩放没有应用到实际滑动上。就目前而言,Y2Pitch 对行为没有任何影响。
Original comment in English
issue (bug_risk): The computed RealangleDeg is not used for swipe distance, which may defeat the purpose of the pitch-based scaling.
RealangleDeg is computed via Y2Pitch but only used for logging; swipex still uses angleDeg (swipex := int(angleDeg / 90 * rotate90)). If the goal is to pitch-calibrate the rotation/movement, swipex should likely be based on RealangleDeg, or the code should clarify why pitch scaling is not applied to the actual swipe. As is, Y2Pitch has no behavioral effect.
| if arg.Box.X() == 0 || arg.Box.Y() == 0 || arg.Box.Width() == 0 || arg.Box.Height() == 0 { | ||
| err := fmt.Errorf("目标坐标/尺寸为空(X:%d,Y:%d,W:%d,H:%d)", | ||
| arg.Box.X(), arg.Box.Y(), arg.Box.Width(), arg.Box.Height()) | ||
| log.Error().Err(err).Msg("目标坐标读取失败") | ||
| return false // 必须返回false,终止执行 |
There was a problem hiding this comment.
issue (bug_risk): 将 X==0 或 Y==0 视为无效会拒绝位于屏幕顶部/左侧边缘的合法目标。
使用 X() == 0 || Y() == 0 会把任何接触左边或上边缘的 box 都视为无效,即便其宽高是正数。如果目标是检测“空 box”,应改为根据尺寸(以及符号)来判断,例如 if arg.Box.Width() <= 0 || arg.Box.Height() <= 0 { ... }。
Original comment in English
issue (bug_risk): Treating X==0 or Y==0 as invalid will reject valid targets at the top/left edge of the screen.
Using X() == 0 || Y() == 0 treats any box touching the left or top edge as invalid, even when width/height are positive. If the goal is to detect empty boxes, guard on size (and sign) instead, e.g. if arg.Box.Width() <= 0 || arg.Box.Height() <= 0 { ... }.
|
看看怎么没编过? |
There was a problem hiding this comment.
你好——我发现了 1 个问题,并给出了一些整体性的反馈:
- 变量
oTragetX/Y/W/H的命名中似乎有一个一致的拼写错误;建议将它们(以及相关日志中的变量)重命名为oTarget*,以提高可读性并避免混淆。 - 在
autoEcoFarmCalculateSwipeTarget.Run中,可能需要对XStepRatio和YStepRatio做校验(例如限制在 [0, 1] 这样合理的范围内),以防止由于 JSON 输入异常而产生意外的滑动坐标。 - 当前
Run中的Info级别日志会输出每次调用的详细几何信息(屏幕中心、ROI 等);如果该函数被频繁调用,建议将日志级别下调到Debug或通过条件控制,避免在正常运行时产生过多噪声日志。
面向 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- The variables `oTragetX/Y/W/H` appear to have a consistent typo in their names; consider renaming them (and related logs) to `oTarget*` for clarity and to avoid confusion.
- In `autoEcoFarmCalculateSwipeTarget.Run`, it may be worth validating `XStepRatio` and `YStepRatio` (e.g., clamping to a sane range like [0, 1]) to prevent unexpected swipe coordinates from malformed JSON input.
- The current `Info`-level logging in `Run` prints detailed per-call geometry (screen center, ROI, etc.); if this runs frequently, consider downgrading to `Debug` or guarding it to avoid noisy logs in normal operation.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/scaletarget.go" line_range="45-63" />
<code_context>
+ }
+ }
+
+ oTragetX := float64(arg.Roi.X()) // 传入矩形左上角X
+ oTragetY := float64(arg.Roi.Y()) // 传入矩形左上角Y
+ oTragetW := float64(arg.Roi.Width()) // 传入矩形宽度(X轴方向)
+ oTragetH := float64(arg.Roi.Height()) // 传入矩形高度(Y轴方向)
+
+ log.Info().Msgf(
+ "Roi矩形参数:左上角X=%.2f, 左上角Y=%.2f, 宽度=%.2f, 高度=%.2f",
+ oTragetX, oTragetY, oTragetW, oTragetH,
+ )
+
+ // 计算传入矩形的中点坐标
+ oTragetCenterX := oTragetX + oTragetW/2 // 中点X = 左上角X + 宽度/2
+ oTragetCenterY := oTragetY + oTragetH/2 // 中点Y = 左上角Y + 高度/2
+
+ // 计算屏幕中心坐标
</code_context>
<issue_to_address>
**建议(拼写):** 若干变量名将 `Target` 拼写成了 `Traget`,这会影响可读性并可能造成混淆。
建议将这些变量(`oTragetX/Y/W/H`、`oTragetCenterX/Y`)重命名为使用正确的 `Target` 拼写(例如 `oTargetX`、`oTargetCenterX`),以与预期含义保持一致并统一命名风格。
```suggestion
oTargetX := float64(arg.Roi.X()) // 传入矩形左上角X
oTargetY := float64(arg.Roi.Y()) // 传入矩形左上角Y
oTargetW := float64(arg.Roi.Width()) // 传入矩形宽度(X轴方向)
oTargetH := float64(arg.Roi.Height()) // 传入矩形高度(Y轴方向)
log.Info().Msgf(
"Roi矩形参数:左上角X=%.2f, 左上角Y=%.2f, 宽度=%.2f, 高度=%.2f",
oTargetX, oTargetY, oTargetW, oTargetH,
)
// 计算传入矩形的中点坐标
oTargetCenterX := oTargetX + oTargetW/2 // 中点X = 左上角X + 宽度/2
oTargetCenterY := oTargetY + oTargetH/2 // 中点Y = 左上角Y + 高度/2
// 计算屏幕中心坐标
//计算距离
dx := oTargetCenterX - screenCenterX
dy := oTargetCenterY - screenCenterY
```
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The variables
oTragetX/Y/W/Happear to have a consistent typo in their names; consider renaming them (and related logs) tooTarget*for clarity and to avoid confusion. - In
autoEcoFarmCalculateSwipeTarget.Run, it may be worth validatingXStepRatioandYStepRatio(e.g., clamping to a sane range like [0, 1]) to prevent unexpected swipe coordinates from malformed JSON input. - The current
Info-level logging inRunprints detailed per-call geometry (screen center, ROI, etc.); if this runs frequently, consider downgrading toDebugor guarding it to avoid noisy logs in normal operation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The variables `oTragetX/Y/W/H` appear to have a consistent typo in their names; consider renaming them (and related logs) to `oTarget*` for clarity and to avoid confusion.
- In `autoEcoFarmCalculateSwipeTarget.Run`, it may be worth validating `XStepRatio` and `YStepRatio` (e.g., clamping to a sane range like [0, 1]) to prevent unexpected swipe coordinates from malformed JSON input.
- The current `Info`-level logging in `Run` prints detailed per-call geometry (screen center, ROI, etc.); if this runs frequently, consider downgrading to `Debug` or guarding it to avoid noisy logs in normal operation.
## Individual Comments
### Comment 1
<location path="agent/go-service/autoecofarm/scaletarget.go" line_range="45-63" />
<code_context>
+ }
+ }
+
+ oTragetX := float64(arg.Roi.X()) // 传入矩形左上角X
+ oTragetY := float64(arg.Roi.Y()) // 传入矩形左上角Y
+ oTragetW := float64(arg.Roi.Width()) // 传入矩形宽度(X轴方向)
+ oTragetH := float64(arg.Roi.Height()) // 传入矩形高度(Y轴方向)
+
+ log.Info().Msgf(
+ "Roi矩形参数:左上角X=%.2f, 左上角Y=%.2f, 宽度=%.2f, 高度=%.2f",
+ oTragetX, oTragetY, oTragetW, oTragetH,
+ )
+
+ // 计算传入矩形的中点坐标
+ oTragetCenterX := oTragetX + oTragetW/2 // 中点X = 左上角X + 宽度/2
+ oTragetCenterY := oTragetY + oTragetH/2 // 中点Y = 左上角Y + 高度/2
+
+ // 计算屏幕中心坐标
</code_context>
<issue_to_address>
**suggestion (typo):** Several variable names are misspelled as `Traget`, which hurts readability and may cause confusion.
These variables (`oTragetX/Y/W/H`, `oTragetCenterX/Y`) should be renamed to use `Target` (e.g., `oTargetX`, `oTargetCenterX`) to align with the intended word and keep naming consistent.
```suggestion
oTargetX := float64(arg.Roi.X()) // 传入矩形左上角X
oTargetY := float64(arg.Roi.Y()) // 传入矩形左上角Y
oTargetW := float64(arg.Roi.Width()) // 传入矩形宽度(X轴方向)
oTargetH := float64(arg.Roi.Height()) // 传入矩形高度(Y轴方向)
log.Info().Msgf(
"Roi矩形参数:左上角X=%.2f, 左上角Y=%.2f, 宽度=%.2f, 高度=%.2f",
oTargetX, oTargetY, oTargetW, oTargetH,
)
// 计算传入矩形的中点坐标
oTargetCenterX := oTargetX + oTargetW/2 // 中点X = 左上角X + 宽度/2
oTargetCenterY := oTargetY + oTargetH/2 // 中点Y = 左上角Y + 高度/2
// 计算屏幕中心坐标
//计算距离
dx := oTargetCenterX - screenCenterX
dy := oTargetCenterY - screenCenterY
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


功能说明:
该任务会调用maptracker跑到农场,然后打开地图寻找农作物标记,找到后追踪标记并向着标记前进,收掉路上碰到的所有农田,且每收一个会等一段时间让队友帮忙收周围的,以此来达成自动收菜的功能
目前只有一个收菜方案:即先到达农场的右下角,然后寻找左上角最远的农作物,然后按着对角线移动并收菜,需要使用者将农田摆成方形(长方形最佳),以保证没有遗漏
工作进度:
- [ ] 添加拍照模式(拍照模式下无法识别标记,暂时不做了)Summary by Sourcery
引入一个自动化生态农场采集任务,并将其集成到现有的智能体服务和任务流水线系统中。
New Features:
AutoEcoFarm任务,以及用于导航、农田识别和采集工作流的相关流水线配置。AutoEcoFarm任务,并为所有支持的语言提供本地化文案。Enhancements:
AutoEcoFarm自定义动作,以便可由流水线调用。Original summary in English
Summary by Sourcery
Introduce an automated eco farm harvesting task and integrate it into the existing agent service and task pipeline system.
New Features:
Enhancements:
由 Sourcery 提供的总结
引入一个 AutoEcoFarm 自动收割任务,并将其集成到现有的智能体服务和任务流水线系统中。
新特性:
增强:
Original summary in English
Summary by Sourcery
Introduce an AutoEcoFarm automated harvesting task and integrate it into the existing agent service and task pipeline system.
New Features:
Enhancements:
Summary by Sourcery
引入一个自动生态农场收获任务,并将其集成到现有的代理服务和任务流水线系统中。
新功能:
改进:
Original summary in English
Summary by Sourcery
Introduce an automated eco farm harvesting task and integrate it into the existing agent service and task pipeline system.
New Features:
Enhancements: