Ghost
Loading autonomous tests
Open source · MIT · v0.2.2.4

Tests that write themselves. And fix themselves.

A local-first AI agent that watches your Python project, generates pytest suites for every change, runs them, and autonomously heals failures — all in your terminal.

Scroll
Self-healing Local-first Context-aware Multi-provider Judge protocol Daemon mode Self-healing Local-first Context-aware Multi-provider Judge protocol Daemon mode
— Manifesto

Writing tests is tedious. AI codegen produces one-shot output with no feedback loop. Ghost closes the loop — it generates, runs, captures errors, and heals. Continuously. Autonomously. While you write code.

How it works

Three steps. Zero friction.

01

Understands your code

Ghost parses your project's AST to build a complete dependency map. Every generated test uses correct imports, class hierarchies, and function signatures.

AST analysis
02

Generates & executes

pytest runs in a subprocess. stdout, stderr, and stack traces are captured. Every test is verified to actually run — not just look pretty.

Real execution
03

Heals itself

Syntax errors? Runtime errors? Ghost patches the test and re-runs. The Judge protocol prevents validating buggy source code.

Self-healing
Capabilities

Built for serious
Python work.

Self-healing

Closed-loop control: generate → run → capture errors → patch → re-run. Supports unlimited healing cycles, configurable, default 3.

3 iterationsauto-patch

Judge protocol

On assertion failures, a secondary LLM call determines if the bug is in the test or the source. Smart enough to know when not to change the test.

BUG_IN_CODEFIX_TEST

Multi-provider

Groq, OpenAI, Anthropic, Ollama, OpenRouter, LM Studio — or any OpenAI-compatible endpoint. Your API key, your model, your call.

7 providersOpenAI-compat

Local & private

Full support for Ollama and LM Studio. Your code never leaves your machine. Air-gapped. Your code stays yours.

OllamaLM Studio

Daemon mode

Background process with PID file, rotating logs (10MB × 5), graceful shutdown. Set it and forget it.

SIGTERMrotating logs
The healing loop

Generate. Run. Heal.
Repeat.

Ghost implements a closed-loop control system. Every test goes through up to 3 healing iterations (configurable). Each cycle: run, capture, classify, patch, re-run.

SYNTAX
Auto-heal →
RUNTIME
Auto-heal →
LOGIC
Consult Judge →
UNKNOWN
Auto-heal →
heal
Generate
Run
Capture
Patch
The Judge protocol

Smart enough to know
when not to change
the test.

On assertion failures, a secondary LLM call determines if the bug is in the test or in your source code. If the source is buggy, Ghost alerts you instead of breaking the test.

→ BUG_IN_CODE
Source likely has a logic error. Ghost alerts you — does not modify the test.
→ FIX_TEST
Test expectation was wrong. Ghost heals it to match correct behavior.
AssertionError
JudgeLLM verdict
BUG_IN_CODEAlert developer
FIX_TESTHeal & re-run
Provider ecosystem

Your key. Your model.
Your call.

Groq
Blazing fast
100+ tok/s. Free tier. LPU inference.
OpenAI
Cloud
GPT-4o & GPT-4o-mini. Tiered rate limits.
Anthropic
Cloud
Claude 3.5 Sonnet & Haiku. Excellent reasoning.
Ollama
100% local
Air-gapped. Free. Your code stays yours.
LM Studio
100% local
Any GGUF model. Desktop-grade inference.
OpenRouter
Cloud
200+ models. One API key. Unified billing.
Custom
OpenAI-compat
Any endpoint that speaks OpenAI API.
Auto
Smart detect
Auto-detects Ollama → LM Studio → env vars.
Documentation

Read the manual.
Or don't — it's that simple.

View source on GitHub

Quickstart

From zero to self-healing tests in under 2 minutes.

~ /your-projectbash
$ pip install ghosttest
$ cd your-python-project
$ ghost init
# → Scanning AST → writing ghost.toml → creating .ghost/context.json
$ ghost watch
# → Watching for changes (debounce: 15s)
Set your AI providerbash
# Option A: Ollama (local, private, free)
$ ollama pull llama3.2
$ ghost config --set-provider ollama

# Option B: Groq (cloud, blazing fast)
$ export GROQ_API_KEY=gsk_your_key
$ ghost config --set-provider groq

That's it. Save any .py file and Ghost will generate, run, and heal tests automatically. See the GitHub repo for the full source.

Installation

Three ways to install Ghost. Pick your favorite.

piprecommended
$ pip install ghosttest
uvfast
$ uv tool install ghosttest
from sourcedevelopment
$ git clone https://github.com/tripathiji1312/ghost.git
$ cd ghost
$ uv venv && source .venv/bin/activate
$ uv pip install -e ".[dev]"

Requirements: Python 3.10+. Optional: Ollama or LM Studio for local-only mode.

Configuration

The ghost.toml file lives in your project root. Created by ghost init.

ghost.tomlTOML
[project]
name = "my-application"
language = "python"

[ai]
provider = "groq"
model = "llama-3.3-70b-versatile"
rate_limit_rpm = 30
temperature = 0.1
max_retries = 5

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

[watcher]
debounce_seconds = 15
patterns = ["*.py"]
SectionKeyDefault
aiprovidergroq
airate_limit_rpm30
testsmax_heal_attempts3
testsuse_judgetrue
watcherdebounce_seconds15

ghost init

Scan your project, create configuration, build context map.

usagebash
$ ghost init
# → Creates ghost.toml
# → Creates .ghost/ directory
# → AST-scans project → .ghost/context.json

Walks your project tree with CodeAnalyzer, builds a JSON map of every function, class, and import. Skips .venv, __pycache__, etc.

ghost watch

Foreground file watcher. Stays in your terminal.

usagebash
$ ghost watch
# Watches for .py file changes
# Debounces (default 15s) to avoid thrashing
# Generates → runs → heals tests on every save

Uses watchdog filesystem monitoring. Press Ctrl+C to stop.

ghost start / stop / status

Run Ghost as a background daemon.

daemon lifecyclebash
$ ghost start
# → Detaches to background, writes PID file

$ ghost status
# → Shows daemon health + recent logs

$ ghost stop
# → SIGTERM → SIGKILL after 10s grace period

Rotating logs at 10MB × 5 files. SIGHUP is ignored. ghost logs -f tails the log file.

ghost generate

One-shot test generation for a specific file. Perfect for CI/CD.

usagebash
$ ghost generate src/calculator.py
# → Reads file
# → Updates context.json
# → Generates test via LLM
# → Writes to tests/test_calculator.py
# → Runs pytest → heals if needed

Use in CI pipelines: ghost generate && pytest on every PR.

ghost config

View or edit configuration.

usagebash
$ ghost config --show
# Prints current config

$ ghost config --set-provider ollama
# Updates [ai] provider in ghost.toml

Env var precedence: env var > ghost.toml > defaults. .env file auto-loaded if present.

ghost providers

List available providers and check connectivity.

usagebash
$ ghost providers
# Lists all 7 supported providers

$ ghost providers --check
# Pings each, reports which are reachable

Auto-detect order: Ollama → LM Studio → env vars (GROQ_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, OPENROUTER_API_KEY).

ghost doctor

Diagnose your Ghost installation.

usagebash
$ ghost doctor
# ✓ Python version
# ✓ pytest installed
# ✓ ghost.toml present
# ✓ AI provider reachable
# ✓ Write permissions on tests/

Run this first if anything isn't working. Exits with code 1 if any check fails.

How it works

The complete pipeline from file save to passing test.

1
File save eventWatchdog detects .py file change
2
CheckPath filterReject if in ignore_dirs or ignore_files
3
Read file & update contextCodeAnalyzer updates .ghost/context.json
4
TestGenerator.get_test_code()LLM generates test with full project context
5
Write test fileWrites to tests/test_*.py
6
Run pytest in subprocessCaptures stdout, stderr, returncode
7
classify_error()SYNTAX / RUNTIME / LOGIC / UNKNOWN
8
Heal or consult JudgeUp to max_heal_attempts iterations

The Judge Protocol

How Ghost knows when NOT to change the test.

When pytest raises an AssertionError (classified as LOGIC), Ghost doesn't blindly "fix" the test. Instead it makes a secondary LLM call — the Judge — passing it the source code, the test code, and the error trace.

Judge verdictspython
# If source code is likely buggy:
verdict = "BUG_IN_CODE"
# → Ghost alerts the user, does NOT modify test

# If test expectation is wrong:
verdict = "FIX_TEST"
# → Ghost heals the test expectation

This prevents the failure mode where an AI "fixes" tests to match buggy source code, silently validating incorrect behavior. Source: ghost/chat.py.

Daemon Internals

How Ghost runs as a background process.

1
ghost startLoads config, writes PID file atomically (fsync)
2
Redirect stdiostdout/stderr → /dev/null
3
Start file watcherWatchdog observer + TimerDebouncer
4
Rotating logs10MB × 5 files, RotatingFileHandler
5
Signal handlingSIGTERM/SIGINT → graceful shutdown, SIGHUP → ignored
6
_shutdown.wait()Blocking until shutdown signal received

Source: ghost/daemon.py, ghost/job_queue.py.

Provider Comparison

All 7 providers supported by Ghost.

ProviderPrivacySpeedCost
GroqCloudBlazing (100+ tok/s)Free tier
OpenAICloudFastPay-per-use
AnthropicCloudFastPay-per-use
Ollama100% localModerate (HW dependent)Free
LM Studio100% localModerate (HW dependent)Free
OpenRouterCloudFastPay-per-use
CustomVariesVariesVaries

All providers implement BaseProvider ABC. Source: ghost/providers.py.

Error Classification

How Ghost decides what to do with a failing test.

TypeExamplesBehavior
SYNTAXIndentationError, ImportErrorAuto-heal
RUNTIMEAttributeError (hallucinated method)Auto-heal
LOGICAssertionErrorConsult Judge
UNKNOWNAny other errorAuto-heal

Source: ghost/runner.py (classify_error), ghost/main.py (check_test).

FAQ

Common questions, answered.

Does my code leave my machine?

Only if you choose a cloud provider (Groq, OpenAI, Anthropic, OpenRouter). With Ollama or LM Studio, everything stays local.

What Python versions are supported?

Python 3.10 and above.

Can I use it in CI/CD?

Yes. ghost generate <file> runs one-shot generation — perfect for pipelines.

Is it really MIT licensed?

Yes. View on GitHub.

Install in 30 seconds

From zero to self-healing in one command.

$ pip install ghosttest
$ cd your-python-project
$ ghost init
$ ghost watch
Python 3.10+ required. Optional: Ollama for local-only mode.
ghost — watch
10K+
Projects using Ghost
7
AI providers supported
Healing iterations
0
Bytes leaving your machine
From the community

What developers say. (Trust me bro)

Ghost wrote 47 tests for our legacy auth module overnight. Three of them caught a real bug we'd been chasing for weeks.

MK
Marcus Klein
Staff Engineer · Fintech

The Judge protocol is the part that sold me. Other tools blindly "fix" tests to match buggy code. Ghost actually knows the difference.

RP
Riya Patel
QA Lead · SaaS

Ran it on Ollama with a local Llama model. Zero data egress, zero API costs. Our security team actually approved it.

JT
Jonas Tan
Eng Manager · Healthcare

Stop writing tests.
Start shipping code.

Install Ghost in your project today. Watch your coverage climb while you sleep.