Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agent/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Subagents provide specialized capabilities. Read them when tasks require domain
| `tools/build-mcp/` | MCP development - creating Model Context Protocol servers and tools | build-mcp, api-wrapper, server-patterns, transports, deployment |
| `tools/ai-assistants/` | AI tool integration - configuring assistants, CAPTCHA solving, multi-modal agents | agno, capsolver, windsurf, configuration, status |
| `tools/ai-orchestration/` | AI orchestration frameworks - visual builders, multi-agent teams, workflow automation, DSL orchestration | overview, langflow, crewai, autogen, openprose, packaging |
| `tools/browser/` | Browser automation - web scraping, testing, screenshots, form filling | stagehand, playwright, playwriter, crawl4ai, dev-browser, pagespeed, chrome-devtools |
| `tools/browser/` | Browser automation - web scraping, testing, screenshots, form filling | agent-browser, stagehand, playwright, playwriter, crawl4ai, dev-browser, pagespeed, chrome-devtools |
| `tools/ui/` | UI components - component libraries, design systems, interface constraints | shadcn, ui-skills |
| `tools/code-review/` | Code quality - linting, security scanning, style enforcement, PR reviews | code-standards, code-simplifier, codacy, coderabbit, qlty, snyk, secretlint, auditing |
| `tools/context/` | Context optimization - semantic search, codebase indexing, token efficiency | osgrep, augment-context-engine, context-builder, context7, toon, dspy, llm-tldr |
Expand Down
311 changes: 311 additions & 0 deletions .agent/scripts/agent-browser-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
#!/bin/bash
# shellcheck disable=SC2034,SC2155,SC2317,SC2329,SC2016,SC2181,SC1091,SC2154,SC2015,SC2086,SC2129,SC2030,SC2031,SC2119,SC2120,SC2001,SC2162,SC2088,SC2089,SC2090,SC2029,SC2006,SC2153

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Disabling a large number of ShellCheck warnings globally can hide real bugs and makes the script harder to maintain. This is especially concerning for warnings like SC2086 (unquoted variables) which point to potential robustness issues. It's better to disable specific warnings on a case-by-case basis with a comment explaining why, or preferably, to fix the underlying code to be compliant.


# Agent Browser Helper - Headless Browser Automation CLI for AI Agents
# Part of AI DevOps Framework
# Provides setup and management of agent-browser CLI

# Source shared constants and functions
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/shared-constants.sh"
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add existence check before sourcing external file.

If shared-constants.sh is missing, the script will fail with an unclear error. Add a guard for better error recovery and user feedback.

🛠️ Proposed fix
 # Source shared constants and functions
 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+if [[ ! -f "${SCRIPT_DIR}/shared-constants.sh" ]]; then
+    echo "[ERROR] Missing required file: ${SCRIPT_DIR}/shared-constants.sh" >&2
+    exit 1
+fi
 source "${SCRIPT_DIR}/shared-constants.sh"
📝 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.

Suggested change
# Source shared constants and functions
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/shared-constants.sh"
# Source shared constants and functions
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ ! -f "${SCRIPT_DIR}/shared-constants.sh" ]]; then
echo "[ERROR] Missing required file: ${SCRIPT_DIR}/shared-constants.sh" >&2
exit 1
fi
source "${SCRIPT_DIR}/shared-constants.sh"
🤖 Prompt for AI Agents
In @.agent/scripts/agent-browser-helper.sh around lines 8 - 10, The script
currently unconditionally sources shared-constants.sh using SCRIPT_DIR and
source, which will produce an unclear error if the file is missing; update the
block to verify the file exists (test -f or [[ -f ]]) at
"${SCRIPT_DIR}/shared-constants.sh" before calling source, and if it does not
exist emit a clear error via echo or logger and exit non‑zero; keep references
to SCRIPT_DIR and the filename so the check and error message point to the exact
missing file.


# Colors for output
readonly BLUE='\033[0;34m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly RED='\033[0;31m'
readonly NC='\033[0m'

# Print functions
print_info() {
local msg="$1"
echo -e "${BLUE}[INFO]${NC} $msg"
return 0
}

print_success() {
local msg="$1"
echo -e "${GREEN}[SUCCESS]${NC} $msg"
return 0
}

print_warning() {
local msg="$1"
echo -e "${YELLOW}[WARNING]${NC} $msg"
return 0
}

print_error() {
local msg="$1"
echo -e "${RED}[ERROR]${NC} $msg" >&2
return 0
}

# Check if agent-browser is installed
check_installed() {
if command -v agent-browser &> /dev/null; then
local version
version=$(agent-browser --version 2>/dev/null || echo "unknown")
print_success "agent-browser is installed: $version"
return 0
else
print_warning "agent-browser is not installed"
return 1
fi
}

# Check if Chromium is installed
check_chromium() {
if agent-browser install --check 2>/dev/null; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upstream docs show agent-browser install / agent-browser install --with-deps, but I don’t see an install --check flag; if unsupported, check_chromium() will always report missing Chromium even when installed.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

print_success "Chromium browser is installed"
return 0
else
print_warning "Chromium browser not found"
return 1
fi
}
Comment on lines +57 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

check_chromium assumes agent-browser is installed.

This function calls agent-browser install --check without first verifying the CLI is present. If agent-browser isn't installed, the user gets a confusing "command not found" error rather than a helpful message.

🛠️ Proposed fix
 # Check if Chromium is installed
 check_chromium() {
+    if ! command -v agent-browser &> /dev/null; then
+        print_warning "Cannot check Chromium - agent-browser not installed"
+        return 1
+    fi
     if agent-browser install --check 2>/dev/null; then
         print_success "Chromium browser is installed"
         return 0
🤖 Prompt for AI Agents
In @.agent/scripts/agent-browser-helper.sh around lines 57 - 66, The
check_chromium function currently calls the agent-browser CLI unconditionally;
first verify the agent-browser command exists (e.g., via command -v or type) and
if missing call print_warning like "agent-browser CLI not found" and return
non-zero, otherwise proceed to run agent-browser install --check as before and
handle its exit status; update check_chromium to perform this pre-check so
missing CLI yields a clear warning instead of a "command not found" error.


# Install agent-browser globally
install_agent_browser() {
print_info "Installing agent-browser CLI..."

# Check for npm
if ! command -v npm &> /dev/null; then
print_error "npm is required. Please install Node.js first."
return 1
fi

# Install globally
if npm install -g agent-browser; then
print_success "agent-browser installed successfully"
else
print_error "Failed to install agent-browser"
return 1
fi

return 0
}

# Install Chromium browser
install_chromium() {
print_info "Installing Chromium browser..."

if ! check_installed; then
print_error "agent-browser must be installed first. Run: $0 install"
return 1
fi

# Detect platform for deps
local with_deps=""
if [[ "$(uname)" == "Linux" ]]; then
print_info "Linux detected - installing with system dependencies"
with_deps="--with-deps"
fi

if agent-browser install $with_deps; then
Comment on lines +99 to +105

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The $with_deps variable is unquoted, which can lead to unexpected behavior due to word splitting and globbing if the variable contained spaces. While it works in this specific case, it's not a robust practice. Using an array for optional arguments is a safer way to build commands.

Suggested change
local with_deps=""
if [[ "$(uname)" == "Linux" ]]; then
print_info "Linux detected - installing with system dependencies"
with_deps="--with-deps"
fi
if agent-browser install $with_deps; then
local install_args=()
if [[ "$(uname)" == "Linux" ]]; then
print_info "Linux detected - installing with system dependencies"
install_args+=("--with-deps")
fi
if agent-browser install "${install_args[@]}"; then

print_success "Chromium installed successfully"
else
print_error "Failed to install Chromium"
return 1
fi

return 0
}

# Full setup
setup() {
print_info "Setting up agent-browser..."

if ! check_installed; then
install_agent_browser || return 1
fi

if ! check_chromium 2>/dev/null; then
install_chromium || return 1
fi

print_success "agent-browser setup complete!"
echo ""
print_info "Quick start:"
echo " agent-browser open example.com"
echo " agent-browser snapshot"
echo " agent-browser click @e1"
echo " agent-browser close"

return 0
}

# Show status
status() {
echo "=== Agent Browser Status ==="
echo ""

# Check installation
if check_installed; then
echo ""
fi

# Check Chromium
check_chromium 2>/dev/null || true
echo ""

# Check active sessions
print_info "Active sessions:"
agent-browser session list 2>/dev/null || echo " (none or daemon not running)"

return 0
}

# List active sessions
sessions() {
print_info "Active browser sessions:"
agent-browser session list 2>/dev/null || echo "No active sessions"
return 0
}

# Close all sessions
close_all() {
print_info "Closing all browser sessions..."

# Get list of sessions and close each
local sessions
sessions=$(agent-browser session list 2>/dev/null | grep -E '^\s*\w+' | awk '{print $1}')

if [[ -z "$sessions" ]]; then
print_info "No active sessions to close"
return 0
fi

for session in $sessions; do
print_info "Closing session: $session"
AGENT_BROWSER_SESSION="$session" agent-browser close 2>/dev/null || true
done
Comment on lines +171 to +182

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current method of parsing session names and iterating over them is not robust and will fail if session names contain spaces or other special characters. Using mapfile to read the session names into an array and then iterating over the array is a safer and more robust approach. This also allows for combining the grep and awk commands for better efficiency.

Suggested change
local sessions
sessions=$(agent-browser session list 2>/dev/null | grep -E '^\s*\w+' | awk '{print $1}')
if [[ -z "$sessions" ]]; then
print_info "No active sessions to close"
return 0
fi
for session in $sessions; do
print_info "Closing session: $session"
AGENT_BROWSER_SESSION="$session" agent-browser close 2>/dev/null || true
done
local sessions_array=()
mapfile -t sessions_array < <(agent-browser session list 2>/dev/null | awk '/^\s*\w+/ {print $1}')
if [[ ${#sessions_array[@]} -eq 0 ]]; then
print_info "No active sessions to close"
return 0
fi
for session in "${sessions_array[@]}"; do
print_info "Closing session: $session"
AGENT_BROWSER_SESSION="$session" agent-browser close 2>/dev/null || true
done


print_success "All sessions closed"
return 0
}

# Run a quick demo
demo() {
print_info "Running agent-browser demo..."

if ! check_installed; then
print_error "agent-browser not installed. Run: $0 setup"
return 1
fi

echo ""
print_info "1. Opening example.com..."
agent-browser open https://example.com

echo ""
print_info "2. Getting snapshot (accessibility tree)..."
agent-browser snapshot -i

echo ""
print_info "3. Getting page title..."
agent-browser get title

echo ""
print_info "4. Taking screenshot..."
local screenshot_path="/tmp/agent-browser-demo.png"
agent-browser screenshot "$screenshot_path"
print_success "Screenshot saved to: $screenshot_path"

echo ""
print_info "5. Closing browser..."
agent-browser close

print_success "Demo complete!"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demo() always prints Demo complete! and returns success, even if one of the agent-browser ... steps fails (since there’s no strict-mode or per-step error handling). That can make troubleshooting harder when agent-browser isn’t fully set up.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

return 0
}

# Show help
show_help() {
cat << 'EOF'
Agent Browser Helper - Headless Browser Automation CLI for AI Agents

Usage: agent-browser-helper.sh <command>

Commands:
setup Full setup (install CLI + Chromium)
install Install agent-browser CLI only
chromium Install Chromium browser only
status Show installation and session status
sessions List active browser sessions
close-all Close all active sessions
demo Run a quick demonstration
help Show this help message

Examples:
# First-time setup
agent-browser-helper.sh setup

# Check status
agent-browser-helper.sh status

# Run demo
agent-browser-helper.sh demo

# Close all sessions
agent-browser-helper.sh close-all

Direct CLI Usage:
agent-browser open example.com # Navigate to URL
agent-browser snapshot # Get accessibility tree with refs
agent-browser click @e2 # Click by ref from snapshot
agent-browser fill @e3 "text" # Fill input by ref
agent-browser screenshot page.png # Take screenshot
agent-browser close # Close browser

Multi-Session:
agent-browser --session s1 open site-a.com
agent-browser --session s2 open site-b.com
agent-browser session list

For full documentation, see:
~/.aidevops/agents/tools/browser/agent-browser.md
https://github.com/vercel-labs/agent-browser
EOF
return 0
}

# Main entry point
main() {
local command="${1:-help}"

case "$command" in
setup)
setup
;;
install)
install_agent_browser
;;
chromium)
install_chromium
;;
status)
status
;;
sessions)
sessions
;;
close-all)
close_all
;;
demo)
demo
;;
help|--help|-h)
show_help
;;
*)
print_error "Unknown command: $command"
echo ""
show_help
return 1
;;
esac
}

main "$@"
Loading
Loading