Skip to main content

Open-source self-healing runtime for Python: RAG + OpenAI-compatible LLM + unified diff patches

Project description

self-heal

Open-source self-healing helper for Python: index your repo (AST chunks + OpenAI-compatible embeddings), capture tracebacks (in-process hook / decorator or supervised subprocess), ask an OpenAI-compatible chat model for a unified diff, validate paths, optionally apply via git apply / patch, and audit proposals.

  • Python ≥ 3.11
  • Protocol: OpenAI-compatible HTTP APIs (base_url + chat completions + embeddings)
  • Safety: no exec of model output; patches are unified diffs only; allow/deny paths; secrets masked in captured locals; API keys from env only.

Install

pip install -e ".[dev]"   # from this repo

Set OPENAI_API_KEY (or the env name from [llm].api_key_env in .self-heal.toml).

Quickstart

  1. Init config in your project root:

    self-heal init
    
  2. Index code (needs embeddings endpoint):

    self-heal index
    
  3. Supervised run (captures stderr tracebacks and can propose/heal):

    PYTHONPATH=. self-heal run -- python -m examples.broken_app.main
    

    With auto-apply (still validates paths; use with care):

    PYTHONPATH=. self-heal run --auto --no-dry-run -- python -m examples.broken_app.main
    
  4. Offline heal from a traceback file:

    python -m examples.broken_app.main 2> tb.txt   # or copy a traceback
    self-heal heal --tb tb.txt
    
  5. Library usage (in-process):

    from pathlib import Path
    from self_heal import install, self_heal
    
    install(project_root=Path(__file__).resolve().parents[1])
    
    @self_heal(mode="suggest")
    def risky():
        ...
    

Configuration

See .self-heal.example.toml or run self-heal init (template ships in self_heal/templates/).

Key sections: [llm], [index], [heal], [supervisor].

Security

  • Model output is never executed as Python; only unified diffs are accepted.
  • Patches are checked against allowed_paths / forbidden_paths; defaults block .git/, .env*, secrets globs, pyproject.toml.
  • Locals and tracebacks are sanitized before being sent to the model.
  • Prefer dry-run (default in CLI) until you trust the workflow; use --no-dry-run with --auto only when appropriate.

Limitations (MVP)

  • Patch application: prefers git apply inside a git repo; otherwise tries system patch, then a small Python hunk applier.
  • Supervised mode expects Python-style tracebacks on stderr.
  • Embedding dimension is assumed compatible with Chroma’s stored vectors (default client setup targets OpenAI text-embedding-3-small-sized vectors).

License

MIT — see 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

self_heal_runtime-0.1.1.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

self_heal_runtime-0.1.1-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file self_heal_runtime-0.1.1.tar.gz.

File metadata

  • Download URL: self_heal_runtime-0.1.1.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for self_heal_runtime-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ccdd2ded3eabe75d7bd3502c9ac6c5e2ee97a70a1c05e62fba948acf911124bd
MD5 b919b091944ec9f5fcd4b1dca8eac418
BLAKE2b-256 5453b67484a733098975a287eb195a6ae1236e8994f3b4b707a4a9c46be930a1

See more details on using hashes here.

File details

Details for the file self_heal_runtime-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for self_heal_runtime-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8552c406d8c7137121a6ab003f72594f2c1e6bcd02908a9ef7cdd470adb9dc8
MD5 6a7d33e31da497ba46887baa759ce6eb
BLAKE2b-256 8432d960ef3f5b9db0b4c0a6511db6af4c39f1616184a4a4a2a88455de81e4ab

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