Skip to main content

Reliable. Autonomous. Model-Agnostic. Turn any LLM into a disciplined software engineer.

Project description

โ™พ๏ธ Darkzloop

Reliable. Autonomous. Model-Agnostic.
Stop hand-carrying cargo. Operate the locomotive.

PyPI License: MIT Python 3.10+

Darkzloop is a terminal-based agent runner that turns any LLM into a rigorous software engineer. Built on the Ralph Wiggum Loop methodology, it uses a Finite State Machine, Mermaid context diagrams, and Circuit Breakers to prevent hallucinations and infinite loops.

๐Ÿ”ฅ The Killer Feature: Bring Your Own Auth (BYOA)
Darkzloop doesn't need your API keys. It pipes context directly to the tools you're already logged into:

Claude CLI โ€ข GitHub Copilot โ€ข Ollama โ€ข llm CLI โ€ข Aider


โšก Quick Start

1. Install

pip install darkzloop

2. Run

Navigate to your project and describe the task. Darkzloop auto-detects your stack.

darkzloop "Fix the retry logic in the webhook handler"

That's it. Darkzloop will:

  • ๏ฟฝ Darkz Loop through Plan โ†’ Execute โ†’ Observe โ†’ Critique โ†’ Checkpoint
  • ๐Ÿ” Auto-detect your project type (Rust/Python/Node/Go)
  • ๐Ÿ›ก๏ธ Create a safety backup branch
  • โšก Show animated spinner while working
๐ŸŸก [EXECUTING] iter=1 fails=0
โ ด ๐Ÿ”„ Darkz Looping...

Optional: Verify Setup

darkzloop doctor
# โœ“ Backend: claude
# โœ“ Project: Python
#   Tier 1: ['ruff check .']
#   Tier 2: ['pytest -x']

โšก Batch Processing (Parallel Workers)

Process multiple files concurrently with the new batch command:

# Process entire folder with 4 parallel workers
darkzloop batch ./src --workers 4 --task "Fix security vulnerabilities"

โšก Batch Processing: 51 files with 4 workers
Processing... โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100%

Results:
  โœ“ Success: 51
  โœ— Failed: 0

Batch Options

Option Description
--workers N Number of parallel Ralph workers (default: 4)
--task "..." Task to apply to each file
--backend X Override LLM backend

๐Ÿ›ก๏ธ Why Darkzloop?

Most AI agents are just "loops in a while(true) block." They drift, hallucinate, and overwrite good code. Darkzloop is different:

Feature The Problem The Darkzloop Solution
Ralph Loop Agent runs aimlessly FSM-controlled Planโ†’Executeโ†’Observeโ†’Critiqueโ†’Checkpoint
Circuit Breakers Agent tries the same wrong fix 10ร— Task Limits: Hard stop after 3 failed attempts
Tiered Gates Agent breaks the build Quality Control: Tests must pass before loop completes
Stdin Delivery Shell escaping mangles prompts Direct stdin: Complex prompts with Mermaid diagrams work perfectly
Git Safety Agent overwrites uncommitted work Backup Branches: Auto-creates restore points

๐Ÿง  Supported Backends

Darkzloop works with any tool that accepts text via stdin.

Backend Best For Auto-Detected
Claude CLI Complex refactors, high reasoning โœ“
Ollama Privacy, offline, free โœ“
GitHub Copilot Quick fixes with Enterprise license โœ“
llm CLI Universal adapter (50+ providers) โœ“

๐Ÿ› ๏ธ Usage Examples

Quick Fix

darkzloop "Login button not responding on mobile"

With Backend Override

darkzloop "Add rate limiting" --backend ollama

Skip Safety Prompts + Quality Gates (CI/CD)

darkzloop "Fix lint errors" --unattended --no-gates

Batch Process Directory

darkzloop batch ./vulnerable-code --workers 8 --task "Fix SQL injection"

Check Environment

darkzloop doctor

Auto-detected quality gates by stack:

  • Rust: cargo check โ†’ cargo test
  • Python: ruff check . โ†’ pytest -x
  • Node: npm run lint โ†’ npm test
  • Go: go build ./... โ†’ go test ./...

๐Ÿ“ฆ Architecture

Darkzloop implements the Ralph Wiggum Loop methodology with industrial-grade hardening:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    DARKZLOOP CONTROL PLANE                   โ”‚
โ”‚                                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚
โ”‚  โ”‚   FSM    โ”‚โ”€โ”€โ”€โ–ถโ”‚  Mermaid โ”‚โ”€โ”€โ”€โ–ถโ”‚  Gates   โ”‚               โ”‚
โ”‚  โ”‚  Engine  โ”‚    โ”‚ Context  โ”‚    โ”‚ (Tests)  โ”‚               โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ”‚
โ”‚        โ”‚              โ”‚               โ”‚                      โ”‚
โ”‚        โ–ผ              โ–ผ               โ–ผ                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚  โ”‚           Stdin Prompt Delivery          โ”‚                โ”‚
โ”‚  โ”‚   (Bypasses shell escaping entirely)     โ”‚                โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚   Executor Layer    โ”‚
              โ”‚  (Model-Agnostic)   โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ                โ–ผ                โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ Claude  โ”‚     โ”‚  Ollama  โ”‚     โ”‚   API   โ”‚
   โ”‚  CLI    โ”‚     โ”‚ (Local)  โ”‚     โ”‚ (SDK)   โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Ralph Loop FSM

The FSM enforces strict state transitionsโ€”no "hallucinated" jumps:

graph LR
    INIT --> PLAN
    PLAN --> EXECUTE
    EXECUTE --> OBSERVE
    OBSERVE --> CRITIQUE
    CRITIQUE --> CHECKPOINT
    CRITIQUE --> TASK_FAILURE
    TASK_FAILURE --> PLAN
    CHECKPOINT --> COMPLETE
    TASK_FAILURE --> BLOCKED
State Description Exit Condition
PLAN Agent receives FSM context + Mermaid diagram Plan ready
EXECUTE Agent works on task (๐Ÿ”„ Darkz Looping...) Changes made
OBSERVE Run quality gates Pass/Fail
CRITIQUE Evaluate results Success โ†’ CHECKPOINT
CHECKPOINT Task complete All done โ†’ COMPLETE
TASK_FAILURE Max 3 retries, then โ†’ BLOCKED Fix applied โ†’ retry

Context Reminder (Sent Every Iteration)

Each iteration, the agent receives structured context:

# DARKZLOOP AGENT CONTEXT
FSM: EXECUTE | iter=2 | fails=1 | max_fails=3

## FSM State Diagram
graph LR; PLAN-->EXECUTE; EXECUTE-->OBSERVE...

## Current Task
Fix the SQL injection vulnerability

## Instructions
You are inside a Ralph Wiggum loop. Your changes persist between iterations.

๐Ÿ“Š Commands

Command Description
darkzloop "task" Run a fix or feature (main usage)
darkzloop batch path/ Process files in parallel
darkzloop batch path/ --workers 8 Control parallelism
darkzloop "task" --backend ollama Override LLM backend
darkzloop "task" --unattended Skip safety prompts (for CI)
darkzloop "task" --no-gates Skip quality gates (for testing)
darkzloop doctor Verify environment and configuration

๐Ÿšจ Safety Features

Darkzloop is designed to never lose your work:

  1. Git Clean Check: Warns before running with uncommitted changes
  2. Backup Branches: Creates darkzloop-backup-YYYYMMDD-HHMMSS before execution
  3. Circuit Breakers: Max 3 consecutive failures before stopping
  4. Attended Mode: Requires approval at each major step
  5. Stdin Delivery: Complex prompts with special characters work perfectly

๐ŸŽฏ Philosophy

"The goal is not to build a smarter agent. It's to build a more disciplined one."

Darkzloop is based on the Ralph Wiggum Loop methodology:

  1. Plan: Receive task + FSM context + Mermaid diagram
  2. Execute: Let the agent work within strict boundaries
  3. Observe: Run quality gates (linters, tests)
  4. Critique: Evaluate results, decide next action
  5. Checkpoint: Accept changes or retry

The agent is powerful. The system keeps it honest.


๐Ÿ”ง Development

git clone https://github.com/darkzOGx/darkzloop
cd darkzloop
pip install -e ".[dev]"
pytest

Stress Testing

Generate a nightmare test suite:

cd vulnerable-api
python generate_nightmare_suite.py
# Creates 50 files with various vulnerabilities

darkzloop batch nightmare_suite --workers 4
# Processes all files in parallel

๐Ÿ“„ License

MIT ยฉ 2025


Stop debugging your debugger. Start shipping.
pip install darkzloop && darkzloop "your bug here"

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

darkzloop-0.8.1.tar.gz (101.2 kB view details)

Uploaded Source

Built Distribution

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

darkzloop-0.8.1-py3-none-any.whl (104.6 kB view details)

Uploaded Python 3

File details

Details for the file darkzloop-0.8.1.tar.gz.

File metadata

  • Download URL: darkzloop-0.8.1.tar.gz
  • Upload date:
  • Size: 101.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for darkzloop-0.8.1.tar.gz
Algorithm Hash digest
SHA256 7bfb86ea9d35b42e9fad4b28cb67d66f3cd3507c373ed7ba47583c5923d921d5
MD5 5e4eaabd0f9927bf5c85ae558a4eea70
BLAKE2b-256 e7bfccd7d5d0fa01fcf7eb1a44a0a931536681cccd233947b43a1a78ccc33317

See more details on using hashes here.

File details

Details for the file darkzloop-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: darkzloop-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 104.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for darkzloop-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2eb8afbbda68f359ad49a6716ee73b029aa9062c8a82ad428434deab8b3314c9
MD5 f57937a462a6a089357b38b7aa0d925b
BLAKE2b-256 3108fc88fdc271013fcd2e5606f58a1cfda521109d6c01371c82a34af83ae10d

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