Repository navigation
feat: add held-key click support (#291) - #292
Conversation
📝 WalkthroughWalkthroughThis PR implements keyboard modifier support for mouse clicks by adding a repeatable ChangesHeld-Key Click Feature
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
specs/feature-mouse-interactions/feature.gherkin (1)
167-203: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winStep definition phrasing differs from implemented BDD scenarios.
The scenarios in
specs/feature-mouse-interactions/feature.gherkinuse step phrases like "the fixture should record..." (lines 172–174, 181–184, 194, 202), but the implemented BDD scenarios intests/features/interact.feature(context snippet) use "the click event log should show..." and "the click event log should contain...". Align the spec Gherkin with the actual step definitions to avoid confusion during traceability reviews.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@specs/feature-mouse-interactions/feature.gherkin` around lines 167 - 203, Update the Gherkin step phrasing so it matches the implemented step definitions: replace occurrences of "the fixture should record" in the scenarios (e.g., "the fixture should record 'Shift' keydown before the click", "the fixture should record 'Shift' keyup after the click", "the fixture should record 'Space' and 'Alt' keydown events before the click", "the fixture should record 'Alt' and 'Space' keyup events after the click", and "the fixture should record no held key events for the click") with the implemented phrases used in tests/features/interact.feature such as "the click event log should show ..." or "the click event log should contain ..." so the step text exactly matches the existing step definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@specs/feature-mouse-interactions/design.md`:
- Line 115: Several fenced code blocks use bare triple-backticks (```) and
should include language identifiers; update each fenced block (the occurrences
that start with ```) to specify an appropriate language token (e.g., use "bash"
or "shell" for CLI examples, "text" for pseudo-code or human-readable flows) or
explicitly leave it blank but add a short comment above the fence explaining why
no language is specified; search for the bare ``` fences in the document and
replace them with ```bash, ```shell, or ```text as appropriate.
In `@specs/feature-mouse-interactions/requirements.md`:
- Around line 358-363: The functional requirement numbering in requirements.md
is inconsistent: the table lists FR13–FR17 but the surrounding text/reference
mentions FR18; update the document so the summary and any references match the
actual requirements (either add the missing FR18 row or change the text to refer
to FR13–FR17), and ensure any mentions in the same section (e.g., the paragraph
referencing FR18) are adjusted accordingly to use the correct FR identifiers.
In `@tests/bdd.rs`:
- Around line 633-640: Build a proper file:// URL from the fixture path and use
that in the navigate invocation instead of interpolating fixture.display() raw
(which breaks on spaces/Windows paths). For example, convert fixture to a
platform-correct URL via
Url::from_file_path(fixture).map_err(...).unwrap().to_string() (or an equivalent
API) and then pass that URL into run_agentchrome (e.g. format!("agentchrome
navigate '{}' --wait-until networkidle", file_url)) so the navigate argument is
a valid, fully-formed file URL that won’t be split by whitespace or malformed on
Windows; update the code around project_root(), fixture and the run_agentchrome
call accordingly.
- Around line 401-412: The Drop implementation for CliWorld currently ignores
the result of the disconnect command; change the teardown to capture the Result
from std::process::Command::status() (the call inside CliWorld::drop), check for
Err or a non-success exit (.success() == false), and report failures instead of
silently swallowing them — e.g., log or print an error with context including
self.binary_path/self.temp_home and the exit code or error from the command;
ensure you still tolerate failures during Drop but surface them (using eprintln!
or a logger like log::error) so teardown failures are visible in test output.
---
Outside diff comments:
In `@specs/feature-mouse-interactions/feature.gherkin`:
- Around line 167-203: Update the Gherkin step phrasing so it matches the
implemented step definitions: replace occurrences of "the fixture should record"
in the scenarios (e.g., "the fixture should record 'Shift' keydown before the
click", "the fixture should record 'Shift' keyup after the click", "the fixture
should record 'Space' and 'Alt' keydown events before the click", "the fixture
should record 'Alt' and 'Space' keyup events after the click", and "the fixture
should record no held key events for the click") with the implemented phrases
used in tests/features/interact.feature such as "the click event log should show
..." or "the click event log should contain ..." so the step text exactly
matches the existing step definitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a6bbae97-01e7-4917-a60f-1fa9c740896c
📒 Files selected for processing (24)
.gitignoreman/agentchrome-interact-click-at.1man/agentchrome-interact-click.1man/agentchrome-interact-drag-at.1man/agentchrome-interact-drag.1man/agentchrome-interact-hover.1man/agentchrome-interact-key.1man/agentchrome-interact-mousedown-at.1man/agentchrome-interact-mouseup-at.1man/agentchrome-interact-scroll.1man/agentchrome-interact-type.1man/agentchrome-interact.1specs/feature-mouse-interactions/design.mdspecs/feature-mouse-interactions/feature.gherkinspecs/feature-mouse-interactions/requirements.mdspecs/feature-mouse-interactions/tasks.mdspecs/feature-mouse-interactions/verification-report.mdsrc/cli/mod.rssrc/error.rssrc/examples_data.rssrc/interact.rstests/bdd.rstests/features/interact.featuretests/fixtures/click-held-keys.html
|
|
||
| ### Data Flow — `interact click s1 --hold Shift` | ||
|
|
||
| ``` |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Add language identifiers to fenced code blocks.
Markdownlint flags these code blocks as missing language identifiers. For plaintext command-line examples, use shell or bash; for pseudo-code flows, use text or leave blank with a comment explaining why.
Also applies to: 131-131, 199-199, 263-263, 382-382
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 115-115: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@specs/feature-mouse-interactions/design.md` at line 115, Several fenced code
blocks use bare triple-backticks (```) and should include language identifiers;
update each fenced block (the occurrences that start with ```) to specify an
appropriate language token (e.g., use "bash" or "shell" for CLI examples, "text"
for pseudo-code or human-readable flows) or explicitly leave it blank but add a
short comment above the fence explaining why no language is specified; search
for the bare ``` fences in the document and replace them with ```bash, ```shell,
or ```text as appropriate.
Source: Linters/SAST tools
| | FR13 | `--hold <KEY>` on `interact click` — hold any valid AgentChrome key while dispatching an element-targeted click | Must | Reuses the key-name inventory from `interact key` | | ||
| | FR14 | `--hold <KEY>` on `interact click-at` — hold one or more distinct keys while dispatching coordinate clicks, including `--relative-to` coordinates | Must | Multiple `--hold` flags may be supplied | | ||
| | FR15 | Held modifier keys (`Alt`, `Control`, `Meta`, `Shift`) set the matching CDP mouse `modifiers` bitmask during click dispatch | Must | Ensures DOM click handlers observe `altKey`, `ctrlKey`, `metaKey`, and `shiftKey` | | ||
| | FR16 | Invalid or duplicate held-key values fail during argument validation before any browser dispatch | Must | Preserve structured stderr and typed exit-code behavior | | ||
| | FR17 | Existing click/click-at behavior, output fields, wait behavior, and snapshot behavior remain backward-compatible when held keys are omitted | Must | No new output field is required for unmodified clicks | | ||
| | FR18 | Clap help, built-in examples, and BDD coverage document and exercise at least one `--hold <KEY>` click invocation | Should | Supports agent discovery through help, examples, and tests | |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Functional requirement numbering appears incomplete.
The table shows FR13–FR17 (5 requirements), but the summary in line 18 mentions "FR18" in the context of the feature enhancement. Verify that all functional requirements are listed or update the reference to match the actual count (FR13–FR17).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@specs/feature-mouse-interactions/requirements.md` around lines 358 - 363, The
functional requirement numbering in requirements.md is inconsistent: the table
lists FR13–FR17 but the surrounding text/reference mentions FR18; update the
document so the summary and any references match the actual requirements (either
add the missing FR18 row or change the text to refer to FR13–FR17), and ensure
any mentions in the same section (e.g., the paragraph referencing FR18) are
adjusted accordingly to use the correct FR identifiers.
| impl Drop for CliWorld { | ||
| fn drop(&mut self) { | ||
| if let (Some(binary), Some(temp_home)) = (&self.binary_path, &self.temp_home) { | ||
| let _ = std::process::Command::new(binary) | ||
| .args(["connect", "--disconnect"]) | ||
| .env("HOME", temp_home.path()) | ||
| .env("USERPROFILE", temp_home.path()) | ||
| .env("AGENTCHROME_NO_SKILL_CHECK", "1") | ||
| .stdout(Stdio::null()) | ||
| .stderr(Stdio::null()) | ||
| .status(); | ||
| } |
There was a problem hiding this comment.
Do not silently swallow disconnect cleanup failures in Drop.
At Lines 404-412, the teardown command result is fully ignored. If connect --disconnect fails, Chrome/session cleanup can be skipped and leak state into later scenarios with no visible signal, causing hard-to-diagnose flakes.
Proposed fix
impl Drop for CliWorld {
fn drop(&mut self) {
if let (Some(binary), Some(temp_home)) = (&self.binary_path, &self.temp_home) {
- let _ = std::process::Command::new(binary)
+ match std::process::Command::new(binary)
.args(["connect", "--disconnect"])
.env("HOME", temp_home.path())
.env("USERPROFILE", temp_home.path())
.env("AGENTCHROME_NO_SKILL_CHECK", "1")
.stdout(Stdio::null())
.stderr(Stdio::null())
- .status();
+ .status()
+ {
+ Ok(status) if status.success() => {}
+ Ok(status) => eprintln!("warning: CliWorld cleanup disconnect exited with {status}"),
+ Err(err) => eprintln!("warning: CliWorld cleanup disconnect failed: {err}"),
+ }
}
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| impl Drop for CliWorld { | |
| fn drop(&mut self) { | |
| if let (Some(binary), Some(temp_home)) = (&self.binary_path, &self.temp_home) { | |
| let _ = std::process::Command::new(binary) | |
| .args(["connect", "--disconnect"]) | |
| .env("HOME", temp_home.path()) | |
| .env("USERPROFILE", temp_home.path()) | |
| .env("AGENTCHROME_NO_SKILL_CHECK", "1") | |
| .stdout(Stdio::null()) | |
| .stderr(Stdio::null()) | |
| .status(); | |
| } | |
| impl Drop for CliWorld { | |
| fn drop(&mut self) { | |
| if let (Some(binary), Some(temp_home)) = (&self.binary_path, &self.temp_home) { | |
| match std::process::Command::new(binary) | |
| .args(["connect", "--disconnect"]) | |
| .env("HOME", temp_home.path()) | |
| .env("USERPROFILE", temp_home.path()) | |
| .env("AGENTCHROME_NO_SKILL_CHECK", "1") | |
| .stdout(Stdio::null()) | |
| .stderr(Stdio::null()) | |
| .status() | |
| { | |
| Ok(status) if status.success() => {} | |
| Ok(status) => eprintln!("warning: CliWorld cleanup disconnect exited with {status}"), | |
| Err(err) => eprintln!("warning: CliWorld cleanup disconnect failed: {err}"), | |
| } | |
| } | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/bdd.rs` around lines 401 - 412, The Drop implementation for CliWorld
currently ignores the result of the disconnect command; change the teardown to
capture the Result from std::process::Command::status() (the call inside
CliWorld::drop), check for Err or a non-success exit (.success() == false), and
report failures instead of silently swallowing them — e.g., log or print an
error with context including self.binary_path/self.temp_home and the exit code
or error from the command; ensure you still tolerate failures during Drop but
surface them (using eprintln! or a logger like log::error) so teardown failures
are visible in test output.
| let fixture = project_root().join("tests/fixtures/click-held-keys.html"); | ||
| assert!(fixture.is_file(), "missing fixture {}", fixture.display()); | ||
| let capture = run_agentchrome( | ||
| world, | ||
| &format!( | ||
| "agentchrome navigate file://{} --wait-until networkidle", | ||
| fixture.display() | ||
| ), |
There was a problem hiding this comment.
Build a robust fixture URL before dispatching navigate.
At Line 638, composing file://{fixture.display()} inside a whitespace-split command string is brittle: paths with spaces can be split into invalid argv tokens, and Windows path formatting can produce a malformed file URL. This can make held-key fixture scenarios fail outside narrow path assumptions.
Proposed fix
fn click_held_keys_fixture_loaded(world: &mut CliWorld) {
let fixture = project_root().join("tests/fixtures/click-held-keys.html");
assert!(fixture.is_file(), "missing fixture {}", fixture.display());
+ let fixture_url = format!(
+ "file://{}",
+ fixture
+ .canonicalize()
+ .expect("failed to canonicalize fixture path")
+ .to_string_lossy()
+ .replace('\\', "/")
+ .replace(' ', "%20")
+ );
let capture = run_agentchrome(
world,
- &format!(
- "agentchrome navigate file://{} --wait-until networkidle",
- fixture.display()
- ),
+ &format!("agentchrome navigate {fixture_url} --wait-until networkidle"),
None,
);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let fixture = project_root().join("tests/fixtures/click-held-keys.html"); | |
| assert!(fixture.is_file(), "missing fixture {}", fixture.display()); | |
| let capture = run_agentchrome( | |
| world, | |
| &format!( | |
| "agentchrome navigate file://{} --wait-until networkidle", | |
| fixture.display() | |
| ), | |
| let fixture = project_root().join("tests/fixtures/click-held-keys.html"); | |
| assert!(fixture.is_file(), "missing fixture {}", fixture.display()); | |
| let fixture_url = format!( | |
| "file://{}", | |
| fixture | |
| .canonicalize() | |
| .expect("failed to canonicalize fixture path") | |
| .to_string_lossy() | |
| .replace('\\', "/") | |
| .replace(' ', "%20") | |
| ); | |
| let capture = run_agentchrome( | |
| world, | |
| &format!("agentchrome navigate {fixture_url} --wait-until networkidle"), | |
| None, | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/bdd.rs` around lines 633 - 640, Build a proper file:// URL from the
fixture path and use that in the navigate invocation instead of interpolating
fixture.display() raw (which breaks on spaces/Windows paths). For example,
convert fixture to a platform-correct URL via
Url::from_file_path(fixture).map_err(...).unwrap().to_string() (or an equivalent
API) and then pass that URL into run_agentchrome (e.g. format!("agentchrome
navigate '{}' --wait-until networkidle", file_url)) so the navigate argument is
a valid, fully-formed file URL that won’t be split by whitespace or malformed on
Windows; update the code around project_root(), fixture and the run_agentchrome
call accordingly.
Summary
--hold <KEY>support tointeract clickandinteract click-atso click automation can model modifier-sensitive and held-key interactions from the mouse-interactions spec.Alt,Control,Meta, andShift, plus cleanup on click errors.Acceptance Criteria
From
specs/feature-mouse-interactions/requirements.md:Test Plan
From
specs/feature-mouse-interactions/tasks.mdtesting phase:cargo buildcargo test --libcargo test --test bddcargo clippy --all-targetscargo fmt --checktests/fixtures/click-held-keys.htmlfor--hold Shift,--hold Space --hold Alt, invalid/duplicate held keys, unheld click regression, and disconnect cleanupSpecs
specs/feature-mouse-interactions/requirements.mdspecs/feature-mouse-interactions/design.mdspecs/feature-mouse-interactions/tasks.mdspecs/feature-mouse-interactions/verification-report.mdCloses #291
Summary by CodeRabbit
New Features
--holdoption to click commands, allowing one or more keyboard keys to be held during click dispatch.Documentation
interactsubcommands to describe the new--holdoption with examples for single and multiple held keys.