| name | Debug |
| description | Debug issues using E2E tests, log analysis, and dev server management |
| user-invocable | true |
Debugging Anvil
This skill provides guidance and helpers for debugging issues in the Anvil codebase.
Quick Reference
Start/Stop Dev Server
pnpm dev
pnpm dev:headless
pnpm dev:no-hmr
pkill -f "tauri dev" && pkill -f "vite" && pkill -f "cargo-watch"
Run Tests
pnpm test
pnpm test:ui
pnpm test:ui:watch
pnpm test:agents
pnpm test:harness
Query Logs
Local dev logs:
tail -f logs/dev.log
grep -i "error" logs/dev.log | tail -50
cat ~/.anvil/logs/structured.jsonl | jq 'select(.level == "ERROR")'
tail -100 logs/dev.log | grep -A5 -B5 "pattern"
grep "agent_hub" logs/dev.log | tail -20
grep "hub::client" logs/dev.log | tail -20
Production/staging logs: Use /query-clickhouse to query ClickHouse observability logs over HTTP API (errors, sessions, performance, etc.).
Test Infrastructure Overview
Test Locations
| Test Type | Location | Config | Command |
|---|
| UI Components | src/**/*.test.{ts,tsx} | vitest.config.ts | pnpm test |
| UI Isolation | src/**/*.ui.test.{ts,tsx} | vitest.config.ui.ts | pnpm test:ui |
| Agent Core | agents/src/**/*.test.ts | agents/vitest.config.ts | pnpm test:agents |
| Integration | agents/src/**/*.integration.test.ts | agents/vitest.config.ts | pnpm test:agents |
| Harness | agents/src/testing/__tests__/ | agents/vitest.config.ts | pnpm test:harness |
Key Test Files
- Agent Message Handler:
agents/src/runners/message-handler.test.ts
- Thread History:
agents/src/runners/thread-history.test.ts, thread-history-live.test.ts
- Output Processing:
agents/src/output.test.ts
- Shared Runner Logic:
agents/src/runners/shared.integration.test.ts
Agent Test Harness
The agent harness (agents/src/testing/agent-harness.ts) provides sophisticated E2E testing by:
- Spawning real agent subprocesses with controlled environments
- Creating temporary test fixtures:
TestAnvilDirectory - Temp anvil config
TestRepository - Git repo fixtures
MockHubServer - Agent communication mock
- Capturing structured output for assertions
Example harness test pattern:
import { AgentHarness } from '../testing/agent-harness';
const harness = new AgentHarness();
await harness.setup();
const result = await harness.runAgent({ prompt: 'test prompt' });
expect(result.events).toContainEqual(expect.objectContaining({ type: 'complete' }));
await harness.cleanup();
UI Test Mocking
UI tests use comprehensive Tauri API mocks defined in src/test/setup-ui.ts:
@tauri-apps/api/core - invoke, transformCallback
@tauri-apps/api/event - listen, emit
- Plugins: dialog, global-shortcut, shell, opener
- Mock filesystem, git state, thread metadata
Logging Architecture
Log Layers (Rust Backend)
The Rust backend (src-tauri/src/logging/mod.rs) has 4 output layers:
- Console Layer - Colored, compact format with uptime timer
- JSON File -
logs/structured.jsonl for LLM analysis
- In-Memory Buffer - Max 1000 entries, deduplicates similar logs
- ClickHouse Layer - Optional remote logging (via
LOG_SERVER_URL)
Log Sources
| Source | Location | Output |
|---|
| Rust/Tauri | src-tauri/src/**/*.rs | Console + files |
| Frontend | src/lib/logger-client.ts | Via Tauri invoke |
| Agent Core | agents/src/lib/logger.ts | Via hub socket |
| Core Lib | core/lib/logger.ts | Console |
Rate-Limited Logging
Use throttle macros to prevent log spam:
throttle_debug!("frequent operation");
throttle_info!("periodic update");
throttle_warn!("repeated warning");
Common Debugging Scenarios
Agent Not Responding
- Check hub connection:
grep "hub" logs/dev.log | tail -20
- Look for socket errors:
grep -i "socket\|connection\|disconnect" logs/dev.log
- Run agent tests:
pnpm test:agents
UI Not Updating
- Check frontend logs in browser DevTools console
- Look for event emission:
grep "emit\|listen" logs/dev.log
- Run UI tests:
pnpm test:ui
Build Failures
- Check for TypeScript errors:
pnpm typecheck
- Check Rust compilation:
cd src-tauri && cargo check
- Clean and rebuild:
pnpm clean && pnpm build
Test Failures
- Run specific test file:
pnpm vitest run path/to/test.ts
- Run in watch mode for iteration:
pnpm vitest watch path/to/test.ts
- Check test setup mocks:
src/test/setup.ts, src/test/setup-ui.ts
Dev Server Architecture
The dev server runs 4 concurrent processes:
┌─────────────────────────────────────────────────────┐
│ pnpm dev │
├─────────────────────────────────────────────────────┤
│ agents │ cd agents && pnpm build --watch │
│ sdk │ cd core/sdk && pnpm build:watch │
│ migrations │ cd migrations && pnpm build:watch │
│ tauri │ tauri dev $TAURI_ARGS │
└─────────────────────────────────────────────────────┘
│
▼
logs/dev.log (combined output)
Environment presets are in scripts/env-presets/:
dev.sh - Development config (port 1421, dev suffix)
prod.sh - Production-like config