Communitygithub.com

Vite Agent Debugger

Production-tested, tool-agnostic skills for AI coding agents (Claude Code, Codex, Gemini CLI, Cursor, and beyond), providing runtime visibility and a self-healing loop for Vite projects.

What is Vite Agent Debugger?

The Vite Agent Debugger skill provides AI coding agents with runtime visibility into Vite projects, enabling a self-healing feedback loop: read logs, locate the root cause, modify the code, restart the dev server, and verify the fix. It relies on the `vite-plugin-agent-eyes` npm package (source code at webkubor/vite-plugin-agent-eyes) for automatic instrumentation of fetch/XHR calls, route navigation, console output, DOM snapshots, and login state, while also offering optional manual instrumentation for fine-grained control. The skill supports a guard system (`agentGit`, `agentGuard`, `agentSizeWatch`) that runs during development and pre-commit to block secrets, large files, long lines, and other code smells, with deduplication and webhook notifications for team integration. Key use cases include diagnosing broken pages, login failures, request errors, and cookie issues without guessing, then using agent-placed log files (in `log/<port>/`) to audit interactions, errors, API calls, and auth state for efficient troubleshooting.

Works with✓Claude Code✓Codex CLI✓Cursor✓Gemini CLI
npx skills add webkubor/agent-skills

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

── Quality Tracker ──

{ "status": "production", "rating": "★★★★★", "last_used": "2026-07-16", "total_uses": 1, "trace": [ {"date": "2026-07-16", "usage": "Added agent-skills", "result": "✅ In production use"} ] }

What does Vite Agent Debugger do?

Gives agents working in Vite projects runtime visibility, running the self-healing loop of "read logs → locate → fix → restart dev → verify". Companion npm package: vite-plugin-agent-eyes (source code and full docs: webkubor/vite-plugin-agent-eyes). For agent workflow only, prefer reading AGENT_GUIDE.md; for Codex, Claude, Gemini, Hermes to discover and use autonomously, read AGENT_BOOTSTRAP.md; the README is for human installation and evaluation.

When to Use

  • User reports "page broken / can't log in / request failed / cookie issue" — but you shouldn't guess the code — read telemetry first.
  • You've made changes and need to verify: restart dev, trigger an action, read logs to confirm correct behavior.
  • To restore a logged-in UI or browser console, first check log/<port>/auth-state.json for the current account profile, then read log/<port>/interaction.log to replay recent interaction paths.
  • When a user's commit is blocked by a guard, or you need to proactively avoid obvious errors / code smells, first read log/guard-report.json.
  • To instrument a Vite project that hasn't yet been upgraded with these capabilities.

Setup (One-time, 3 Steps)

// 1. vite.config.ts
import { agentDebugger, agentProxy } from 'vite-plugin-agent-eyes'
export default defineConfig({
  plugins: [agentDebugger({ screenshots: true })],  // screenshots optional, enables CDP screenshots
  server: { proxy: { '/api': agentProxy('https://your-api.example.com') } },
})
// 2. Application entry file (main.ts / main.tsx / main.js / index.js — framework-agnostic)

Recommended: one-line auto-instrumentation, which automatically wraps fetch/XHR, route navigation, global errors, full console, DOM snapshots, and sanitized interaction traces:

import { autoInstrument } from 'vite-plugin-agent-eyes/client'
autoInstrument()

Or manual instrumentation (for fine-grained control):

import { installAgentErrorReporter, logApiCall, logConsoleEntry, snapshotDom } from 'vite-plugin-agent-eyes/client'
installAgentErrorReporter()   // captures global errors + full console + DOM snapshot
// In fetch/ky/axios interceptor, call after each request completes
logApiCall({ method, path, url, ok, duration_ms, code, status, request_id, error, request, response })
logConsoleEntry('warn', ['deprecated API called'])

Record sanitized account profile after login success:

import { recordLoginSuccess } from 'vite-plugin-agent-eyes/client'
recordLoginSuccess({ userId, email, name, roles, tenantId })

Only sanitized profile is saved; no token/cookie. Accessible in the browser via window.__AGENT_EYES_AUTH__, file at log/<port>/auth-state.json.

Interaction traces are installed by autoInstrument() by default, written to log/<port>/interaction.log. input / change only record <redacted>, never actual form values.

Without the package installed and need temporary use: prefer git / workspace installation of this package; do not just copy src/index.ts / src/client.ts — they depend on cdp, git, guard-* modules in the same directory.

Commit Governance: agentGit / agentGuard / agentSizeWatch (Quick Config Reference)

The three responsibilities (hooks are set/overwritten at dev startup by the plugin with apply:'serve' — after changing configuration or upgrading the package, you must run pnpm dev once for them to take effect; for Astro projects, add to astro.config's vite.plugins):

PluginTimingEffect
agentGitBefore/after commitReplaces husky: runs precommit commands + can embed guard; sends Feishu notification after commit. Built-in rebase/cherry-pick replay deduplication
agentGuardDuring commitHard blocks staged files: secrets / large files / long lines / TODO / any / console.log. If using agentGit, configure inside agentGit({ guard }), don't mount it separately (would cause pre-commit contention)
agentSizeWatchDuring dev codingWarns for very long files in the console with [agent-eyes:size]; warns only, never blocks. Specifically for preventing AI-generated bloated CSS

Example config (as used in this project's three repos):

agentGit({
  projectLabel: 'Main Website',
  precommit: ['sh scripts/precommit.sh'],     // any non-zero exit blocks the commit
  webhook: [{ url: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxxx', format: 'feishu' }],
  guard: { level: 'block', fileLength: { warn: 400, block: 800 } },  // hard block on code smells
  claimHooksPath: true,   // if global core.hooksPath (e.g., lefthook) shadows this repo's hooks, set local override
  force: true,            // take over existing non-plugin pre-commit hooks
})
// Real-time dev warning (optional, mounted independently): agentSizeWatch({ warn: 400, cssWarn: 300 })

level: warn only reports / block (recommended) blocks on red lines / strict currently same as block. guard.checks: ['secrets','largeFiles','fileLength','todo','noAny','noConsoleLog'], can toggle individually.

Two 0.12.0 behaviors you must know before configuring guard (or you'll think it's a bug):

  • Lockfiles/compressed artifacts are not counted in fileLength: pnpm-lock.yaml/package-lock.json/yarn.lock/*.lock/go.sum/.min.js|css are automatically skipped — generated code, not hand-written. To extend the list, modify GENERATED_FILE_PATTERN (must sync both copies in guard-core + guard-hook).

  • Webhook won't self-injure: agentGit automatically injects its configured webhook URL into guard allowSecrets, so secret check won't flag it as a leak. To manually allow other string literals, use guard.allowSecrets: [...].

  • guard only checks staged files; latest JSON report is at log/guard-report.json.

  • For full option table, see the README ### agentGit / agentGuard / agentSizeWatch API section.

Self-Healing Loop (Core, Execute strictly)

  1. First read log/README.md — project self-documentation, confirms which port logs are in and what each stream shows.
  2. Read log/<port>/errors.log — locate "what broke" (latest first, head is enough).
  3. Drill down based on clues:
    • Unclear reproduction path → log/<port>/interaction.log for click/input/change/submit/route order.
    • API/field issues → log/<port>/api-calls.log for actual request/response bodies (never guess fields based on types).
    • Console warnings/debug info → log/<port>/console.log for all-level output (React dev warnings, library deprecations, etc.).
    • Login/cookie/CORS/302 etc. network layer → log/<port>/proxy-<host>.log for Cookie(req) and Set-Cookie.
    • Restore logged-in UI → log/<port>/auth-state.json for current account profile.
    • Visual issues → log/<port>/snapshots/ for error screenshots (PNG) + DOM snapshots (HTML).
    • Pre-commit guard issues → log/guard-report.json for block/warning details.
  4. Noise prediction: 401 on /auth/session when not logged in, browser extension runtime.lastError — these are expected noise, not bugs, don't chase them.
  5. Edit code → restart dev server (Vite config/plugin changes don't reload via HMR, must restart) → re-trigger → re-read logs to verify. Logs are cleared on each startup; you only see the current session.

Signature Diagnosis: Login Succeeds but Constant 401

log/<port>/api-calls.log:  POST .../auth/login  code=0        ← login success
log/<port>/api-calls.log:  GET  .../auth/session code=40101    ← immediately after, not logged in
log/<port>/proxy-<host>.log: GET .../auth/session → 200 | Cookie(req): none   ← browser didn't send cookie

Root cause: The upstream Set-Cookie header has Domain=<parent domain> + Secure + SameSite=None, locally http://localhost domain mismatch + Secure dropped → cookie rejected. agentProxy already fixes this by default in dev (removes Domain / strips Secure / changes SameSite=None→Lax). To disable: agentProxy(target, { rewriteCookiesForLocalhost: false }).

Log Quick Reference

FileWhat to Look At
log/<port>/errors.logAPI failures + front-end runtime errors (aggregated, deduplicated, with frequency)
log/<port>/console.logFull-level console output (log/warn/error/info/debug)
log/<port>/interaction.logSanitized interaction traces (click/input/change/submit/route)
log/<port>/api-calls.logAll API calls + routes, with request/response bodies
log/<port>/proxy-<host>.logProxy layer Cookie / Set-Cookie attributes / status (per-proxy by host file)
log/<port>/auth-state.jsonMost recent login success sanitized account profile
log/<port>/snapshots/err-*.pngError screenshots (requires CDP, auto-detects port)
log/<port>/snapshots/dom-*.htmlDOM snapshots (always available, no CDP needed)
log/guard-report.jsonMost recent pre-commit guard JSON report

Related Skills