Metadata-Version: 2.2
Name: console-patrol
Version: 0.1.0
Summary: AI-First Console Error & Warning Detector for Web Applications
Author-email: zhzgao <zhzgao@users.noreply.github.com>
License: MIT
Keywords: console,detector,antd,react,vue,testing,debugging
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Debuggers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright>=1.40.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: typer>=0.9.0
Requires-Dist: rich>=13.0.0
Requires-Dist: jinja2>=3.1.0
Requires-Dist: platformdirs>=4.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: mypy>=1.7.0; extra == "dev"

# ConsolePatrol

> AI-First Console Error & Warning Detector for Web Applications

[![PyPI](https://img.shields.io/pypi/v/console-patrol.svg)](https://pypi.org/project/console-patrol/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**ConsolePatrol** is an intelligent console monitoring tool designed for AI agents and developers to automatically detect console errors and warnings across entire web applications. It supports multiple UI frameworks (Ant Design, Element UI, React, Vue, etc.) and provides structured reports with actionable insights.

## Features

- 🌐 **Auto-Discovery** — Scans project routes/pages automatically without manual configuration
- 🎯 **Framework-Aware** — Recognizes UI frameworks and applies targeted detection rules
- 📊 **Severity Levels** — P0 (Fatal) / P1 (Warning) / P2 (Hint) classification
- 📋 **Dual Output** — JSON (for AI agents) + Markdown (for humans)
- 🔄 **Diff Mode** — Compare results with previous runs to track changes
- ⚙️ **Extensible Rules** — Easy to add custom detection patterns
- 🖼️ **Screenshot Capture** — Auto-screenshot on critical errors

## Installation

```bash
pip install console-patrol
```

Or from source:

```bash
git clone https://github.com/zhzgao/console-patrol.git
cd console-patrol
pip install -e .
```

## Quick Start

```bash
# Scan a running web app
console-patrol scan http://localhost:3000

# With auto-discovery of routes (React Router example)
console-patrol scan http://localhost:3000 --router-type react

# Full options
console-patrol scan http://localhost:3000 \
  --router-type react \
  --base-path /admin \
  --output report.json \
  --format markdown \
  --screenshot \
  --severity P1
```

## Architecture

```
console-patrol/
├── src/console_patrol/
│   ├── cli.py          # CLI entry point
│   ├── crawler.py      # Page navigation & route discovery
│   ├── detector.py     # Console message interception
│   ├── framework.py    # Framework auto-detection
│   ├── reporter.py     # JSON / Markdown output
│   └── rules/          # Detection rule engine
│       ├── base.py
│       ├── antd.py     # Ant Design rules
│       ├── react.py    # React rules
│       └── element.py  # Element UI rules
└── tests/
```

## Detection Rules

### Severity Levels

| Level | Meaning | Action |
|-------|---------|--------|
| P0 | Fatal (JS exception, crash) | Immediate fix required |
| P1 | Warning (framework issues) | Fix before release |
| P2 | Hint (code smell, anti-pattern) | Consider fixing |

### Built-in Rules

#### Ant Design
- `antd-useForm-unhooked` — `form.getFieldValue()` called outside form context
- `antd-modal-context` — Static modal methods in React 18+
- `antd-tree-missing-keys` — Tree component missing required keys

#### React
- `react-strict-mode-double-mount` — Potential StrictMode side effects
- `react-hook-rules` — Hook usage violations

#### Element UI
- `element-form-validate` — Form validation issues

## For AI Agents

ConsolePatrol is designed to be agent-friendly:

```python
from console_patrol import ConsolePatrol

result = ConsolePatrol.scan(
    url="http://localhost:3000",
    router_type="react",
    wait_time=2.0,
)

# Structured output
for issue in result.issues:
    if issue.severity == "P0":
        print(f"[{issue.severity}] {issue.rule_id}")
        print(f"  File: {issue.location}")
        print(f"  Fix: {issue.suggestion}")
```

## License

MIT © zhzgao
