igrr/agent_dev_utils

1.1.1

uploaded 1 month ago
AI agent debugging utilities for ESP-IDF projects. Provides idf.py extensions for running tests on hardware, parsing coredumps, and generating structured JSON output for automated crash analysis.

readme

# agent_dev_utils

AI agent debugging utilities for ESP-IDF projects.

## Overview

This ESP-IDF component provides tools for AI coding agents to analyze application crashes through structured JSON output. It packages test execution, coredump parsing, and crash analysis into easy-to-use `idf.py` commands.

## Features

- Structured crash data instead of unstructured logs
- Automatically shows code around crash location
- Run and analyze multiple test files
- Clear backtrace with file:line information
- Compare what was expected vs what happened
- Save results for later analysis

## Installation

Add this component to your ESP-IDF project:

```bash
idf.py add-dependency igrr/agent_dev_utils
```

## Quick Start

Run tests on your ESP32 hardware:

```bash
idf.py run-project
```

View AI agent debugging instructions:

```bash
idf.py agent-info
```

## Commands

### `idf.py run-project`

Runs pytest-embedded tests on physical hardware and outputs structured JSON for crash analysis.

**Basic usage**:
```bash
idf.py run-project
```

**With options**:
```bash
idf.py run-project --target esp32s3 --baud 115200 --output-file results.json
```

**Options**:
- `--target <chip>`: Target chip (esp32, esp32s3, etc.) [default: esp32]
- `--baud <rate>`: Serial baud rate [default: 921600]
- `--skip-build`: Skip the build step
- `--output-file <path>`: Save JSON to file
- `--test-pattern <glob>`: Test file pattern [default: test_*.py]
- `--verbose`: Show pytest output

### `idf.py agent-info`

Displays comprehensive markdown instructions for AI agents on analyzing ESP-IDF crashes.

```bash
idf.py agent-info
```

## JSON Output Example

### Crash Output

```json
{
  "status": "crashed",
  "task_name": "main",
  "exception": {
    "code": "0x1c",
    "name": "LoadProhibitedCause",
    "faulting_address": "0x16"
  },
  "stack_trace": [
    {
      "frame": 0,
      "function": "app_main",
      "file": "main/app.c",
      "line": 42
    }
  ],
  "source_context": "    40 | void app_main(void) {\n    41 |     int *ptr = NULL;\n>>> 42 |     *ptr = 123;\n    43 | }",
  "test_expected": "Expected output: Hello world!",
  "test_actual": "Crashed: Guru Meditation Error: Core 0 panic'ed (LoadProhibited)"
}
```

### Success Output

```json
{
  "status": "success",
  "test_expected": "Test passed",
  "test_actual": "Test passed"
}
```

## Use Cases

### AI Agent Analysis

AI coding agents can parse the JSON to:
1. Identify root cause from `exception.name` and `exception.faulting_address`
2. Locate the bug using `stack_trace[].file` and `stack_trace[].line`
3. See the code via `source_context` with >>> marking the crash line
4. Understand state by examining `registers` for variable values
5. Check resources via `threads[].stack_used` for stack overflow

### Example Agent Workflow

```python
import json
import subprocess

# Run tests
result = subprocess.run(['idf.py', 'run-project'], capture_output=True, text=True)
data = json.loads(result.stdout)

if data['status'] == 'crashed':
    exc = data['exception']
    print(f"Crash: {exc['name']} at {exc['faulting_address']}")

    # Find crash location
    for frame in data['stack_trace']:
        if frame['file'] and frame['line']:
            print(f"Bug in {frame['function']}() at {frame['file']}:{frame['line']}")
            break

    # Show source
    print(data['source_context'])
```

## Documentation

For detailed AI agent debugging instructions:
```bash
idf.py agent-info
```

Or see [docs/agent_instructions.md](docs/agent_instructions.md).

## Requirements

- ESP-IDF v5.5 or later
- pytest-embedded (`./install.sh --enable-ci`)
- Physical ESP32 hardware (QEMU support planned)


## Contributing

Contributions welcome! This component focuses on making ESP-IDF crash analysis accessible to AI coding agents.

## License

MIT License - see [LICENSE](LICENSE) file.

## Links

- [ESP-IDF Documentation](https://docs.espressif.com/projects/esp-idf/)
- [pytest-embedded](https://github.com/espressif/pytest-embedded)
- [Component Registry](https://components.espressif.com/)

Links

Supports all targets

Maintainer

  • Ivan Grokhotkov <ivan@espressif.com>

License: MIT

To add this component to your project, run:

idf.py add-dependency "igrr/agent_dev_utils^1.1.1"

download archive

Stats

  • Archive size
    Archive size ~ 27.71 KB
  • Downloaded in total
    Downloaded in total 535 times
  • Downloaded this version
    This version: 1 time

Badge

igrr/agent_dev_utils version: 1.1.1
|