Instruckt for Laravel

repository·main·Indexed 41 days ago

https://github.com/joshcirre/instruckt-laravel

A Laravel package providing visual feedback tools for AI coding agents. It allows users to annotate web elements in the browser and share them with AI agents via structured markdown or Model Context Protocol (MCP) tools. Features include a Vite plugin, Blade components, and MCP tools like `instruckt.get_all_pending`, `instruckt.get_screenshot`, and `instruckt.resolve` to manage and clear feedback markers.

Tokens
2.6K
Snippets
9
Records
13
Agent score
2%

What's inside Instruckt

  1. How instruckt works (Mental Model)

    main

    instruckt provides a visual feedback loop between users and AI agents:

    1. Initialization: The Vite plugin or Blade component initializes the annotation UI.
    2. Annotation: Users click elements to leave feedback and optionally capture screenshots.
    3. Clipboard: Annotations are automatically copied as structured markdown for easy pasting into AI agents.
    4. Persistence: Annotations are stored via API in storage/app/_instruckt/ (JSON for data, PNG for screenshots).
    5. AI Interaction: AI agents use MCP tools to read pending annotations and can call instruckt.resolve to mark them as fixed, which removes the marker from the browser.
  2. Understand Instruckt source resolution and framework context

    main

    When an annotation is provided, the server automatically resolves component names to source file paths. The framework object within an annotation provides metadata to help you navigate directly to the code:

    • source_file: The relative path to the component file (e.g., app/Livewire/Dashboard.php). Use this to open the file directly instead of searching.
    • source_line: The starting line number of the class.
    • render_line: For Livewire components, the line number of the render() method where the view is returned.
    • class_name: The fully-qualified PHP class name (e.g., App\Livewire\Dashboard).
  3. How the Instruckt visual feedback workflow works

    main

    Instruckt enables users to provide visual feedback by pasting structured markdown into a chat. This markdown contains specific context (element, component, classes, text) that allows an AI agent to locate and fix UI issues.

    The standard workflow for an AI agent is:

    1. Identify the fix: Parse the pasted markdown to find the target element, component, and source file.
    2. Inspect visual context: If the annotation mentions a screenshot, use instruckt.get_screenshot to view the user's view.
    3. Apply and Resolve: After making the code change, call instruckt.resolve using the annotation's ID. This automatically removes the visual marker from the user's browser without requiring a page reload.
    # UI Feedback: /dashboard
    
    ## 1. Change the heading text
    - ID: `01JWXYZ123ABC`
    - Element: `h1.text-xl` in `pages::dashboard`
    - Source: `app/Livewire/Pages/Dashboard.php:1`
    - Classes: `text-xl font-bold`
    - Text: "Welcome"
    - Screenshot: `storage/app/_instruckt/screenshots/01JWXYZ.png`
  4. Resolve Instruckt annotations

    main

    To remove a visual feedback marker from a user's browser, you must call instruckt.resolve with the specific annotation ID.

    Best Practices:

    • Always resolve after fixing: If you do not call this, the marker remains visible in the user's browser.
    • Direct Resolution: You can use the ID found directly in the user's pasted markdown to call instruckt.resolve immediately. You only need to call instruckt.get_all_pending if you need to check for screenshots or list all active markers.
  5. Use the instruckt Blade component

    main

    If you prefer not to use Vite/JS configuration, you can use the Blade component in your layout before the </body> tag.

    Note: The component is gated by config('instruckt.enabled'), which defaults to true only when APP_ENV=local. Visual configuration (colors, keys) for the Blade component is handled via component attributes.

    <x-instruckt-toolbar
        theme="dark"
        position="bottom-left"
        :adapters="['livewire', 'vue']"
        :colors="['default' => '#6366f1', 'screenshot' => '#22c55e', 'dismissed' => '#71717a']"
        :keys="['annotate' => 'a', 'freeze' => 'f']"
    />
  6. Install instruckt-laravel

    main

    Install the package as a development dependency and run the installation command to automate setup. The installation command publishes the configuration, installs the necessary npm package, adds the Vite plugin, injects the virtual module into your JS entry point, and configures MCP for detected AI agents.

    Requirements:

    • PHP 8.2+
    • Laravel 11 or 12
    • laravel/mcp (optional, for MCP tool integration)
    composer require joshcirre/instruckt-laravel --dev
    
    php artisan instruckt:install
  7. Manually connect an AI agent via MCP

    main

    If the automatic installation does not detect your agent, you can manually add the instruckt MCP server to your agent's configuration file (e.g., .mcp.json for Claude Code).

    {
      "mcpServers": {
        "instruckt": {
          "command": "php",
          "args": ["artisan", "mcp:start", "instruckt"]
        }
      }
    }
  8. Configure the instruckt Vite plugin

    main

    The default way to use instruckt is via the Vite plugin. This plugin only runs during vite serve (apply: 'serve'), ensuring it is completely absent from production builds.

    When using the Vite plugin, visual configuration (colors, keys, position, theme) must be defined here rather than in the PHP config file.

    import laravel from 'laravel-vite-plugin'
    import instruckt from 'instruckt/vite'
    
    export default defineConfig({
      plugins: [
        laravel({ input: ['resources/js/app.js'] }),
        instruckt({
          server: false,
          endpoint: '/instruckt',
          adapters: ['livewire', 'blade'],
          mcp: true,
        }),
      ],
    })
  9. Uninstall instruckt-laravel

    main

    To remove instruckt, use the instruckt:uninstall command. This reverses the installation process, including removing Vite/JS artifacts, config files, Blade components, MCP entries, and stored data in storage/app/_instruckt/.

    After running the artisan command, remove the package via Composer.

    php artisan instruckt:uninstall
    
    # Then remove the package
    composer remove joshcirre/instruckt-laravel --dev
  10. Reference: instruckt configuration keys

    main

    Publish the config file using php artisan vendor:publish --tag=instruckt-config. The PHP configuration governs backend behavior (enabled status, routes, middleware, MCP). Visual settings like colors and keys are ignored here if using the Vite plugin; they must be set in vite.config.js instead.

    return [
        // Only enabled in local env by default
        'enabled' => (bool) env('INSTRUCKT_ENABLED', env('APP_ENV') === 'local'),
    
        // API route prefix
        'route_prefix' => env('INSTRUCKT_ROUTE_PREFIX', 'instruckt'),
    
        // Middleware applied to API routes
        'middleware' => explode(',', env('INSTRUCKT_MIDDLEWARE', 'api')),
    
        // Override JS source (e.g. pinned CDN version) — Only used by Blade component
        'cdn_url' => env('INSTRUCKT_CDN_URL', null),
    
        // Marker pin colors (CSS color strings) — Only used by Blade component
        'colors' => [
            // 'default'    => '#6366f1',
            // 'screenshot' => '#22c55e',
            // 'dismissed'  => '#71717a',
        ],
    
        // Keyboard shortcuts — Only used by Blade component
        'keys' => [
            // 'annotate'   => 'a',
            // 'freeze'     => 'f',
            // 'screenshot' => 'c',
            // 'clearPage'  => 'x',
        ],
    ];
  11. Reference: instruckt API routes

    main

    All routes are registered under the configured prefix (default: /instruckt):

    | Method | Route | Description |
    |--------|-------|-------------|
    | GET | `/instruckt/annotations` | List all annotations |
    | POST | `/instruckt/annotations` | Create annotation |
    | PATCH | `/instruckt/annotations/{id}` | Update annotation |
  12. Reference: instruckt MCP tools

    main

    The package registers the following tools for your AI agent to interact with annotations:

    | Tool | Description |
    |------|-------------|
    | `instruckt.get_all_pending` | Get all pending annotations |
    | `instruckt.get_screenshot` | Get the screenshot image for an annotation |
    | `instruckt.resolve` | Mark an annotation as resolved (removes marker from browser) |