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. Unlike flaky chat agents, Darkzloop uses a Finite State Machine, Circuit Breakers, and Manifest Protocols 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:

  • ๐Ÿ” Detect your project type (Rust/Python/Node/Go)
  • ๐Ÿ›ก๏ธ Create a safety backup branch
  • ๐Ÿ”„ Plan, Execute, and Test the fix using your project's own test suite

Optional: Verify Setup

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

๐Ÿ›ก๏ธ 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
Manifest Protocol Agent edits files blindly Read-Before-Write: Writes blocked unless file is in context
Circuit Breakers Agent tries the same wrong fix 10ร— Task Limits: Hard stop after 3 failed attempts per task
Tiered Gates Agent breaks the build Quality Control: Tests must pass before loop completes
Semantic Expansion "Fix billing" misses src/invoice.rs Synonyms: Auto-expands intent to find relevant files
Git Safety Agent overwrites uncommitted work Backup Branches: Auto-creates restore points before execution

๐Ÿง  Supported Backends

Darkzloop works with any tool that accepts text via stdin.

Backend Best For Setup
Claude CLI Complex refactors, high reasoning darkzloop config native claude
Ollama Privacy, offline, free darkzloop config native ollama
GitHub Copilot Quick fixes with Enterprise license darkzloop config native gh-copilot
llm CLI Universal adapter (50+ providers) darkzloop config native llm
Direct API Full control, streaming darkzloop config api anthropic

๐Ÿ› ๏ธ Usage Examples

Quick Fix

darkzloop "Login button not responding on mobile"

With Backend Override

darkzloop "Add rate limiting" --backend ollama

Skip Safety Prompts (CI/CD)

darkzloop "Fix lint errors" --unattended

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 Loop methodology with industrial-grade hardening:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    DARKZLOOP CONTROL PLANE                   โ”‚
โ”‚                                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚
โ”‚  โ”‚   FSM    โ”‚โ”€โ”€โ”€โ–ถโ”‚ Manifest โ”‚โ”€โ”€โ”€โ–ถโ”‚  Gates   โ”‚               โ”‚
โ”‚  โ”‚  Engine  โ”‚    โ”‚ Protocol โ”‚    โ”‚ (Tests)  โ”‚               โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ”‚
โ”‚        โ”‚              โ”‚               โ”‚                      โ”‚
โ”‚        โ–ผ              โ–ผ               โ–ผ                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚  โ”‚         Semantic Expansion Layer         โ”‚                โ”‚
โ”‚  โ”‚   (Synonyms, Learning Glossary, Search)  โ”‚                โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚   Executor Layer    โ”‚
              โ”‚  (Model-Agnostic)   โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ                โ–ผ                โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ Claude  โ”‚     โ”‚  Ollama  โ”‚     โ”‚   API   โ”‚
   โ”‚  CLI    โ”‚     โ”‚ (Local)  โ”‚     โ”‚ (SDK)   โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Finite State Machine

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

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚                                     โ”‚
                    โ–ผ                                     โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚ IDLE โ”‚โ”€โ”€โ”€โ–ถโ”‚ PLANNING  โ”‚โ”€โ”€โ”€โ–ถโ”‚ EXECUTING โ”‚โ”€โ”€โ”€โ–ถโ”‚ TESTING โ”‚โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜โ”‚
                                                   โ”‚     โ”‚
                              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚     โ”‚
                              โ”‚             โ”‚      โ”‚     โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค REMEDIATING โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
                    โ”‚         โ”‚             โ”‚ (tests     โ”‚
                    โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  failed)   โ”‚
                    โ”‚               โ”‚                    โ”‚
                    โ”‚               โ”‚ (fix applied)      โ”‚
                    โ”‚               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚
                    โ”‚ (max retries exceeded)
                    โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚ BLOCKED โ”‚         โ”‚ DONE โ”‚โ—€โ”€โ”€ (tests passed)
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
State Description Exit Condition
IDLE Waiting for task Plan approved
PLANNING Agent generates plan Plan validated
EXECUTING Agent works on current task Task complete
TESTING Running tiered gates Pass โ†’ DONE, Fail โ†’ REMEDIATING
REMEDIATING Self-healing after test failure (max 3 retries per task) Fix applied โ†’ TESTING
BLOCKED Circuit breaker tripped Human intervention required
DONE All tasks complete, all gates passed โ€”

Key Components

  • FSM Engine: 7-state machine with strict transitionsโ€”no skipping states
  • Manifest Protocol: Tracks every file read/write, enforces read-before-write, user must approve sensitive file additions
  • Circuit Breakers: Max iterations (100), consecutive failures (3), per-task retries (3)
  • Semantic Layer: Expands search terms using local synonym matching + learning glossary (no external API calls, no data leaves your machine)
  • Executor Interface: Pluggable backends via stdin/stdout protocol

The Manifest Protocol (Read-Before-Write)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      MANIFEST RULES                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โœ“ Agent wants to READ src/api/users.rs                     โ”‚
โ”‚    โ†’ Allowed (adds to manifest automatically)               โ”‚
โ”‚                                                              โ”‚
โ”‚  โœ— Agent wants to WRITE src/api/users.rs (not in manifest)  โ”‚
โ”‚    โ†’ BLOCKED: "Must read file before modifying"             โ”‚
โ”‚                                                              โ”‚
โ”‚  โš  Agent wants to READ config/secrets.json                  โ”‚
โ”‚    โ†’ PROMPT: "Add sensitive file to manifest? [y/N]"        โ”‚
โ”‚                                                              โ”‚
โ”‚  โœ“ Agent wants to WRITE src/api/users.rs (in manifest)      โ”‚
โ”‚    โ†’ Allowed (file was previously read)                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

This prevents the #1 agent failure mode: blindly overwriting files it hasn't seen.

Semantic Expansion

When you say darkzloop fix "billing issue", the semantic layer expands your intent:

Input:  "billing"
        โ†“
Synonyms: ["invoice", "payment", "charge", "subscription", "price"]
        โ†“
Learned: ["stripe", "checkout"] (from project glossary)
        โ†“
Search:  Finds src/billing.rs, src/invoice.rs, src/stripe/webhook.rs

Implementation: Local dictionary + project-specific learning glossary stored in .darkzloop/glossary.json. No embeddings, no external callsโ€”fast and private.


๐Ÿ”ง Configuration

Zero config by default. Darkzloop auto-detects everything.

Optional overrides via environment:

DARKZLOOP_BACKEND=ollama     # Use Ollama instead of Claude
DARKZLOOP_MAX_ITER=5         # Limit iterations

๐Ÿ“Š Commands

Command Description
darkzloop "task" Run a fix or feature (main usage)
darkzloop "task" --backend ollama Override LLM backend
darkzloop "task" --unattended Skip safety prompts (for CI)
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. Dry Run Mode: --dry-run shows what would happen without executing
  4. Attended Mode: Requires approval at each major step
  5. Read-Before-Write: Cannot modify files not explicitly loaded into context
  6. Sensitive File Prompts: Asks permission before reading config/secrets

๐ŸŽฏ Philosophy

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

Darkzloop is based on the Ralph Loop methodology:

  1. Spec: Define what you want (the "Pin")
  2. Plan: Break it into tasks with dependencies (DAG)
  3. Execute: Let the agent work within strict boundaries
  4. Verify: Run tests before accepting any change
  5. Learn: Build project-specific vocabulary over time

The agent is powerful. The system keeps it honest.


๐Ÿค Contributing

See CONTRIBUTING.md for guidelines.

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

๐Ÿ“„ 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.7.0.tar.gz (99.1 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.7.0-py3-none-any.whl (102.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for darkzloop-0.7.0.tar.gz
Algorithm Hash digest
SHA256 26c6dba8dd3ca9b43e5f6bd7aea950b07a6f1f6a367081a63ad15c071a9b155b
MD5 ccdca43bfad10540cb564797b8b09196
BLAKE2b-256 e9729ea0e7495c0d4a1dc627df618eda6a65274229620d57927d57619091998c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: darkzloop-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 102.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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee60e9d7a362171070e007dfcb839f3795694489a54bfaa7f19c4bd1d85cb5c9
MD5 db4b6f4aa908b121a31ceeb226c930f2
BLAKE2b-256 8e0a05dbe12ff6e8d9ce1916a627e553d180b46bd2e4bfc2e0888ef0aefba82e

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