From ea954629986ca011c17aaefbeae0052f5f15a7bc Mon Sep 17 00:00:00 2001 From: teknium1 Date: Tue, 17 Mar 2026 04:32:39 -0700 Subject: [PATCH] fix(tools): browser handler safety + fuzzy_match docstring accuracy 1. browser_tool.py: Replace **args spread on browser_click, browser_type, and browser_scroll handlers with explicit parameter extraction. The **args pattern passed all dict keys as keyword arguments, causing TypeError if the LLM sent unexpected parameters. Now extracts only the expected params (ref, text, direction) with safe defaults. 2. fuzzy_match.py: Update module docstring to match actual strategy order in code. Block anchor was listed as #3 but is actually #7. Multi-occurrence is not a separate strategy but a flag. Updated count from 9 to 8. --- tools/browser_tool.py | 6 +++--- tools/fuzzy_match.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/browser_tool.py b/tools/browser_tool.py index 9760cf302..dbc0d7e6c 100644 --- a/tools/browser_tool.py +++ b/tools/browser_tool.py @@ -1734,7 +1734,7 @@ registry.register( name="browser_click", toolset="browser", schema=_BROWSER_SCHEMA_MAP["browser_click"], - handler=lambda args, **kw: browser_click(**args, task_id=kw.get("task_id")), + handler=lambda args, **kw: browser_click(ref=args.get("ref", ""), task_id=kw.get("task_id")), check_fn=check_browser_requirements, emoji="👆", ) @@ -1742,7 +1742,7 @@ registry.register( name="browser_type", toolset="browser", schema=_BROWSER_SCHEMA_MAP["browser_type"], - handler=lambda args, **kw: browser_type(**args, task_id=kw.get("task_id")), + handler=lambda args, **kw: browser_type(ref=args.get("ref", ""), text=args.get("text", ""), task_id=kw.get("task_id")), check_fn=check_browser_requirements, emoji="⌨️", ) @@ -1750,7 +1750,7 @@ registry.register( name="browser_scroll", toolset="browser", schema=_BROWSER_SCHEMA_MAP["browser_scroll"], - handler=lambda args, **kw: browser_scroll(**args, task_id=kw.get("task_id")), + handler=lambda args, **kw: browser_scroll(direction=args.get("direction", "down"), task_id=kw.get("task_id")), check_fn=check_browser_requirements, emoji="📜", ) diff --git a/tools/fuzzy_match.py b/tools/fuzzy_match.py index ddcdf4274..d4231c1e3 100644 --- a/tools/fuzzy_match.py +++ b/tools/fuzzy_match.py @@ -6,16 +6,17 @@ Implements a multi-strategy matching chain to robustly find and replace text, accommodating variations in whitespace, indentation, and escaping common in LLM-generated code. -The 9-strategy chain (inspired by OpenCode): +The 8-strategy chain (inspired by OpenCode), tried in order: 1. Exact match - Direct string comparison 2. Line-trimmed - Strip leading/trailing whitespace per line -3. Block anchor - Match first+last lines, use similarity for middle -4. Whitespace normalized - Collapse multiple spaces/tabs to single space -5. Indentation flexible - Ignore indentation differences entirely -6. Escape normalized - Convert \\n literals to actual newlines -7. Trimmed boundary - Trim first/last line whitespace only +3. Whitespace normalized - Collapse multiple spaces/tabs to single space +4. Indentation flexible - Ignore indentation differences entirely +5. Escape normalized - Convert \\n literals to actual newlines +6. Trimmed boundary - Trim first/last line whitespace only +7. Block anchor - Match first+last lines, use similarity for middle 8. Context-aware - 50% line similarity threshold -9. Multi-occurrence - For replace_all flag + +Multi-occurrence matching is handled via the replace_all flag. Usage: from tools.fuzzy_match import fuzzy_find_and_replace