Skip to main content

An autonomous local-first AI agent that generates, executes, and self-heals Python unit tests in real-time.

Project description

Ghost: Autonomous Test Generation Agent

PyPI version Python Versions License Code Style

Ghost is a local-first autonomous agent designed to automate the unit testing lifecycle for Python applications. Functioning as a background daemon, it monitors filesystem events, generates context-aware pytest(or any other framework) suites, and autonomously resolves execution errors through a continuous feedback loop.

It is engineered for privacy and latency, supporting Ollama and LM Studio for fully local execution, alongside Groq, OpenAI, and Anthropic for cloud-based inference.

Core Capabilities

Context-Aware Code Analysis

Unlike generic AI coding assistants, Ghost parses the project's Abstract Syntax Tree (AST) to construct a dependency map. This ensures generated tests utilize correct imports, class hierarchies, and function signatures, significantly reducing runtime errors.

Autonomous Error Resolution (Self-Healing)

Ghost implements a closed-loop control system for test execution. When a generated test fails:

  1. Capture: stdout, stderr, and stack traces are intercepted.
  2. Analysis: The error context is analyzed against the source code.
  3. Patching: The agent generates and applies a fix (e.g., correcting imports, adjusting mocks).
  4. Verification: The test is re-executed to validate the patch.

Logic Verification Protocol ("The Judge")

To prevent regression validation—where tests are modified to match incorrect implementation logic—Ghost employs a secondary verification step. If an AssertionError occurs, a specialized "Judge" agent determines if the discrepancy stems from the test expectation or the source implementation. If the source code is deemed buggy, the agent halts and alerts the developer rather than altering the test.

Provider-Agnostic Architecture

Ghost decouples the agentic logic from the underlying LLM, allowing seamless switching between providers:

  • Groq: Recommended for high-frequency watch modes (low latency).
  • Ollama: Recommended for air-gapped or privacy-constrained environments.
  • OpenAI / Anthropic: Available for complex reasoning tasks.

Installation

Ghost is published to PyPI as ghosttest.

Global Installation (Recommended)

We recommend installing Ghost as a standalone tool using uv to ensure environment isolation.

uv tool install ghosttest

Standard Installation

pip install ghosttest

Quick Start

1. Initialization

Navigate to your project root and initialize the Ghost configuration. This generates a ghost.toml file and performs an initial AST scan of the codebase.

ghost init

2. Environment Configuration

If using cloud providers, export the necessary API keys. Local providers (Ollama/LM Studio) require no configuration.

# Example for Groq
export GROQ_API_KEY=gsk_...

# Example for OpenAI
export OPENAI_API_KEY=sk-...

3. Execution

Start the daemon. Ghost will monitor for file modifications and trigger the generation/healing loop automatically.

ghost watch

Configuration

Ghost is configured via ghost.toml.

[project]
name = "my-application"
language = "python"

[ai]
# Options: groq, ollama, openai, anthropic, lmstudio
provider = "groq"
model = "llama-3.3-70b-versatile"
rate_limit_rpm = 30

[scanner]
# Directories to exclude from context analysis
ignore_dirs = [".venv", "node_modules", "dist", "__pycache__"]
ignore_files = ["setup.py", "conftest.py"]

[tests]
framework = "pytest"
output_dir = "tests"
auto_heal = true
max_heal_attempts = 3
use_judge = true

Command Reference

Command Description
ghost init Initializes configuration and context map.
ghost watch Starts the filesystem monitor daemon.
ghost generate <file> Manually triggers test generation for a specific file.
ghost config Interactive configuration wizard.
ghost providers Lists supported providers and checks API connectivity.
ghost doctor Verifies installation health and dependencies.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ghosttest-0.2.2.3.tar.gz (44.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghosttest-0.2.2.3-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file ghosttest-0.2.2.3.tar.gz.

File metadata

  • Download URL: ghosttest-0.2.2.3.tar.gz
  • Upload date:
  • Size: 44.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for ghosttest-0.2.2.3.tar.gz
Algorithm Hash digest
SHA256 e24a1fbfe58e759479694b594fff52a2e673d4b2634cf713dc88dddcb41f19de
MD5 55e5a6dcb485c7fb0730b335b5311aa2
BLAKE2b-256 cb5d87b5f3a2402bf1095e05919b7cc91c963798bb79c10d1633bcae73d2ae95

See more details on using hashes here.

File details

Details for the file ghosttest-0.2.2.3-py3-none-any.whl.

File metadata

  • Download URL: ghosttest-0.2.2.3-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for ghosttest-0.2.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0e432ac8bacaa709568b4a9e749d5cfe175a436bcf77fccb309a4a6a5416453d
MD5 eff1f58dbfa816ee3fa93d81c3bd4bf8
BLAKE2b-256 ab17258e8b25cd7c6199a5ca15984bc74bd78e0a6e9b762e4547e5fd7d94a845

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page