feat: add ambient mouse API endpoint for anti-bot event diversity#149
feat: add ambient mouse API endpoint for anti-bot event diversity#149ulziibay-kernel wants to merge 9 commits intomainfrom
Conversation
- Add mousetrajectory lib with Bernstein Bezier curves, jitter, easeOutQuad - MoveMouse supports smooth=true for curved path, smooth=false for instant - OpenAPI: smooth, steps (5-80), step_delay_ms (3-30) on MoveMouseRequest - Add cursor-trail demo (before/after instant vs Bezier) Co-authored-by: Cursor <cursoragent@cursor.com>
- Fix demo README: kernel-images or kernel-images-private (not just private) - Use await browser.close() for clean demo script shutdown - Add named constants in mousetrajectory (boundsPadding, knotsCount, etc.) - Avoid mutating opts.MaxPoints; use local var instead - Add ctx.Done() check and sleepWithContext in Bezier step loop for cancellation - Clarify OpenAPI: steps/step_delay_ms ignored when smooth=false - Add TestHumanizeMouseTrajectory_ZeroLengthPath edge case Co-authored-by: Cursor <cursoragent@cursor.com>
Demo not needed in this repo. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Align with Camoufox humanize:minTime/maxTime. Steps and delay auto-computed from path length and target duration. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The deferred modifier key release was using the request context, which fails if cancelled mid-movement, leaving keys stuck. Use context.Background() to match the established cleanup pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
- Eliminate duplicated validation by having MoveMouse call doMoveMouse directly instead of reimplementing resolution/bounds checks - Remove unnecessary moveMouseSmooth/moveMouseInstant wrapper functions - Compute trajectory MaxPoints from duration_sec so the requested duration is actually achievable (remove 30ms step delay upper clamp) - Skip zero-delta mousemove_relative steps to avoid no-op xdotool calls - Always pass -- to mousemove_relative for robustness with negative args - Remove redundant nil check in deferred HoldKeys cleanup - Clean up duration_sec OpenAPI description (remove internal references) - Rename defaultMaxTime/defaultMinTime to defaultMaxPoints/defaultMinPoints - Export MinPoints/MaxPoints constants from mousetrajectory package - Add clamping tests for MaxPoints below min and above max Co-authored-by: Cursor <cursoragent@cursor.com>
| if s.ambientCancel != nil { | ||
| s.ambientCancel() | ||
| s.ambientCancel = nil | ||
| } |
There was a problem hiding this comment.
Invalid config request kills existing ambient loop
Medium Severity
SetAmbientMouse unconditionally cancels the existing ambient loop (lines 50–53) before validating the new configuration via resolveAmbientConfig (line 62). If a user calls this endpoint with enabled: true but invalid parameters (e.g., min_interval_ms > max_interval_ms), the running loop is stopped and the 400 error is returned — leaving the system with no ambient loop running. The config validation needs to happen before the old loop is cancelled to avoid this destructive side effect on error.
Additional Locations (1)
Add POST /computer/ambient_mouse to toggle a background loop of diverse input events (mouse drift, scroll, micro-drag, click, key tap). The loop acquires inputMu per action so it cooperates with explicit computer-use API calls instead of contending with them. - Configurable intervals (min/max_interval_ms) and per-action weights - Display geometry cached for 30s to minimize lock hold time - Mouseup uses background context to prevent stuck mouse button on cancel - Clean shutdown via Shutdown() cancels the ambient context Co-authored-by: Cursor <cursoragent@cursor.com>
de2df27 to
ab8a845
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| } | ||
| if cfg.minIntervalMs > cfg.maxIntervalMs { | ||
| return cfg, fmt.Errorf("min_interval_ms must be <= max_interval_ms") | ||
| } |
There was a problem hiding this comment.
Missing minimum interval allows CPU-intensive tight loop
Medium Severity
resolveAmbientConfig only validates that minIntervalMs <= maxIntervalMs, but doesn't enforce a positive floor. A client can pass min_interval_ms: 0, max_interval_ms: 0, causing the ambient loop to run with zero delay between iterations — a tight busy loop that constantly acquires inputMu and shells out to xdotool, starving other API calls. The OpenAPI spec declares minimum: 50 but that isn't enforced server-side.


feat: add ambient mouse API endpoint for anti-bot event diversity
Add POST /computer/ambient_mouse to toggle a background loop of diverse
input events (mouse drift, scroll, micro-drag, click, key tap). The loop
acquires inputMu per action so it cooperates with explicit computer-use
API calls instead of contending with them.
Builds on top of #148
Note
Medium Risk
Adds a new background input loop and changes the default
MoveMousebehavior to multi-step movement, which may affect timing and interaction determinism for existing clients.Overview
Adds a new
POST /computer/ambient_mouseAPI that starts/stops a background goroutine emitting randomized input events (drift, scroll, micro-drag, click, key tap) with configurable intervals and per-action weights, coordinated via the existinginputMulock.Updates
MoveMouseto support human-like smooth motion by default (smooth+ optionalduration_sec), generating a Bezier-like trajectory and executing stepwisexdotool mousemove_relativewith jittered delays; also ensures the ambient loop is cancelled duringApiService.Shutdownand adds cached display-geometry lookups for ambient actions.Written by Cursor Bugbot for commit ab8a845. This will update automatically on new commits. Configure here.