fix(agent): P0.6 guard human corrections
This commit is contained in:
@@ -3565,15 +3565,62 @@ Example: x_pct=0.50, y_pct=0.30"""
|
||||
|
||||
monitor = self.sct.monitors[1]
|
||||
screen_w, screen_h = monitor["width"], monitor["height"]
|
||||
screen_left = monitor.get("left", 0)
|
||||
screen_top = monitor.get("top", 0)
|
||||
|
||||
if not (
|
||||
isinstance(screen_w, int)
|
||||
and isinstance(screen_h, int)
|
||||
and screen_w >= 200
|
||||
and screen_h >= 200
|
||||
):
|
||||
logger.warning(
|
||||
"[APPRENTISSAGE] Monitor aberrant (%sx%s) — capture refusée",
|
||||
screen_w,
|
||||
screen_h,
|
||||
)
|
||||
return []
|
||||
|
||||
listener_start_ts = time.time()
|
||||
drain_guard_s = 1.0
|
||||
|
||||
def _on_click(x, y, button, pressed):
|
||||
if done_event.is_set():
|
||||
return False
|
||||
if pressed and button.name in ("left", "right"):
|
||||
# Ignore residual low-level mouse events delivered just after
|
||||
# the listener is attached. These are often synthetic agent or
|
||||
# remote-desktop events, not a deliberate human correction.
|
||||
if time.time() - listener_start_ts < drain_guard_s:
|
||||
logger.debug(
|
||||
"[APPRENTISSAGE] Clic ignoré (drain %.1fs) : (%s, %s)",
|
||||
drain_guard_s,
|
||||
x,
|
||||
y,
|
||||
)
|
||||
return
|
||||
|
||||
rel_x = x - screen_left
|
||||
rel_y = y - screen_top
|
||||
if not (0 <= rel_x < screen_w and 0 <= rel_y < screen_h):
|
||||
logger.warning(
|
||||
"[APPRENTISSAGE] Clic ignoré hors moniteur "
|
||||
"(monitor=%sx%s left=%s top=%s, raw=(%s,%s), rel=(%s,%s))",
|
||||
screen_w,
|
||||
screen_h,
|
||||
screen_left,
|
||||
screen_top,
|
||||
x,
|
||||
y,
|
||||
rel_x,
|
||||
rel_y,
|
||||
)
|
||||
return
|
||||
|
||||
action = {
|
||||
"type": "click",
|
||||
"x_pct": round(x / screen_w, 6),
|
||||
"y_pct": round(y / screen_h, 6),
|
||||
"x_pct": round(rel_x / screen_w, 6),
|
||||
"y_pct": round(rel_y / screen_h, 6),
|
||||
"button": button.name,
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
@@ -3589,7 +3636,14 @@ Example: x_pct=0.50, y_pct=0.30"""
|
||||
pass
|
||||
actions.append(action)
|
||||
last_action_time[0] = time.time()
|
||||
logger.info(f"[APPRENTISSAGE] Clic ({x}, {y}) bouton={button.name}")
|
||||
logger.info(
|
||||
"[APPRENTISSAGE] Clic raw=(%s,%s) rel=(%s,%s) bouton=%s",
|
||||
x,
|
||||
y,
|
||||
rel_x,
|
||||
rel_y,
|
||||
button.name,
|
||||
)
|
||||
|
||||
def _on_key_press(key):
|
||||
if done_event.is_set():
|
||||
|
||||
Reference in New Issue
Block a user