Agentation Documentation

repository·main·Indexed 26 days ago

https://github.com/benjitaylor/agentation

An agent-agnostic visual feedback tool that allows developers to provide structured feedback to AI coding agents. It enables users to select elements or text on a webpage to generate precise CSS selectors and context. The tool includes a React component for browser annotations, an MCP server (agentation-mcp) for AI agent integration, and a hook for Claude Code to inject pending UI annotations into the agent's context.

Tokens
18K
Snippets
28
Records
127
Agent score
88%

What's inside Agentation

  1. Understand Agentation Hook behavior and output

    main

    The hook triggers on every user message. It queries http://localhost:4747/pending.

    • If annotations exist: It formats the element selector and the comment, injecting them into the Claude prompt.
    • If no annotations exist or the server is offline: The hook remains silent and outputs nothing, ensuring no disruption to your workflow.

    Example of injected content:

    === AGENTATION FEEDBACK (2 pending) ===
    
    [1] button.submit-btn
        Comment: This button should be disabled during loading
    
    [2] div.error-message
        Comment: Error text is hard to read, needs more contrast
    
    Address these UI issues.
    === END ===
  2. Start the Agentation MCP Server

    main

    Run the server to start both the HTTP server (default port 4747) for receiving browser annotations and the MCP server (stdio) for exposing tools to agents.

    agentation-mcp server

    Server Options

    • --port <port>: Set the HTTP server port (default: 4747).
    • --mcp-only: Skip the HTTP server and only run the MCP server on stdio.
    • --http-url <url>: Specify the HTTP server URL for the MCP server to fetch from.
  3. Execute the Two-Session Self-Driving Workflow

    main

    The Two-Session Self-Driving Workflow enables full autonomous design reviews by splitting tasks between two agents: a Critic that identifies issues via a browser and a Fixer that applies code changes.

    Prerequisites

    • Agentation toolbar installed on the target page.
    • MCP server running and connected (toolbar must show "MCP Connected").
    • agent-browser skill installed.

    Workflow Steps

    1. Start the Fixer (Terminal 2) first: This ensures the agent is ready to receive annotations as they are generated.
    2. Start the Critic (Terminal 1): This agent will navigate the browser and add annotations.
    3. Observe the loop: The Critic adds annotations, which are sent via MCP to the Fixer. The Fixer processes them one by one and resolves them.
    ### Terminal 1 — The Critic
    ```bash
    claude
    > /agentation-self-driving

    Terminal 2 — The Fixer

    claude
    > Watch for agentation annotations and fix each one. Use agentation_watch_annotations
    > in a loop. For each annotation: read the target code, make the fix, then call
    > agentation_resolve with a summary of what you changed.
  4. Install the Agentation Hook for Claude Code

    main

    The Agentation Hook automatically injects pending UI annotations into Claude's context whenever you send a message. You can install it using one of three methods depending on your needs.

    Add the following configuration to your project's .claude/settings.json file. This method uses a curl command and a Python one-liner to fetch and format annotations directly.

    Option 2: Shell Script

    For more detailed or custom output, create a shell script (e.g., check-agentation.sh) and reference its path in your .claude/settings.json under the UserPromptSubmit hook.

    Option 3: Global Settings

    To enable Agentation for all projects, add the configuration to your global Claude settings file at ~/.claude/settings.json.

    {
      "hooks": {
        "UserPromptSubmit": [
          {
            "type": "command",
            "command": "curl -sf --connect-timeout 1 http://localhost:4747/pending 2>/dev/null | python3 -c \"import sys,json;d=json.load(sys.stdin);c=d['count'];exit(0)if c==0 else[print(f'\n=== AGENTATION: {c} UI annotations ===\n'),*[print(f\"[{i+1}] {a['element']}\n    {a['comment']}\n\")for i,a in enumerate(d['annotations'])],print('=== END ===\n')]\" 2>/dev/null;exit 0"
          }
        ]
      }
    }
  5. Use agentation_watch_annotations and agentation_resolve in a Fixer loop

    main

    To implement a Fixer agent in the self-driving workflow, use the following pattern to process design annotations:

    1. Call agentation_watch_annotations to block and wait for new annotations. Each annotation includes the element path, CSS selectors, and feedback text.
    2. Use the provided selectors or component names to locate and read the relevant code in the codebase.
    3. Apply the necessary code changes.
    4. Call agentation_resolve with a summary of the changes made to clear the annotation.
    5. Repeat the loop by calling agentation_watch_annotations again.
  6. Requirements for Agentation Hook

    main

    To use the Agentation Hook, ensure the following are available in your environment:

    • Agentation server: Must be running at http://localhost:4747/pending. You can start it using npx agentation-mcp server or by integrating it into your application.
    • Python 3: Required for parsing the JSON response from the server.
    • curl: Required to make the HTTP request to the local server.
  7. Create design annotations using coordinate-based clicks

    main

    Standard @ref clicks do not trigger Agentation annotation dialogs because the overlay intercepts pointer events at the coordinate level. To trigger a dialog, you must use a sequence of mouse events at the element's center coordinates.

    Workflow:

    1. Take an interactive snapshot (agent-browser snapshot -i) to find the element and its CSS selector.
    2. Scroll the element into view using eval with scrollIntoView (do not use scrollintoview @ref).
    3. Get the bounding box via eval with getBoundingClientRect (do not use get box @ref).
    4. Calculate the center coordinates: centerX = x + width/2, centerY = y + height/2.
    5. Execute: mouse move <centerX> <centerY>, mouse down left, and mouse up left.
    6. Use snapshot -i to find the @ref for the annotation textbox and submit button at the bottom of the output.
    7. Fill the text and click the add button using @ref syntax.
    # Example workflow for an <h1> element
    agent-browser eval "document.querySelector('h1').scrollIntoView({block:'center'})"
    agent-browser eval "((r) => r.x+','+r.y+','+r.width+','+r.height)(document.querySelector('h1').getBoundingClientRect())"
    # (Parse output, e.g., "383,245,200,40")
    
    agent-browser mouse move 483 265
    agent-browser mouse down left
    agent-browser mouse up left
    
    # Use refs found in the full snapshot for the dialog
    agent-browser fill @<textboxRef> "Your critique here"
    agent-browser click @<addRef>
  8. Launch the agent-browser in headed mode

    main

    Agentation Self-Driving mode requires a visible (headed) browser so the user can monitor the agent's actions. If a launch fails due to a stale session, close the existing session before retrying.

    # Try to open. If it fails (stale session), close first then retry.
    agent-browser --headed open <url> 2>&1 || { agent-browser close 2>/dev/null; agent-browser --headed open <url>; }
  9. Set up the Agentation MCP server for AI agent syncing

    main

    To enable real-time annotation syncing with AI agents (like Claude Code, Cursor, or Windsurf), you must set up the agentation-mcp server. After setup, restart your coding agent to load the server.

    Supports 9+ agents including Claude Code, Cursor, Codex, and Windsurf. Use the add-mcp utility:

    npx add-mcp

    Follow the prompts to add agentation-mcp as an MCP server.

    Claude Code Only

    If you are only using Claude Code, you can use the interactive wizard:

    agentation-mcp init

    Verification

    Run the following command to verify your installation:

    agentation-mcp doctor
    npx add-mcp
    # OR
    agentation-mcp init
    # OR
    agentation-mcp doctor