Skip to main content

x2harness (玄心 Harness)

Production-grade Reference Architecture for Autonomous Coding Agents

License Python

The companion Python library for the book Coding Agents: Foundations, Architecture, Harnesses, and Enterprise Practice.

$$\text{Coding Agent} = \text{Foundation Model} + \text{Agent Harness}$$

x2harness provides a modular, zero-magic implementation of the Seven Subsystems that make autonomous coding agents reliable on production repositories.


The 7 Subsystems Architecture

  1. Model Policy Proposer (x2harness.providers): Adapters for DeepSeek, Claude, GPT, Ollama (Qwen2.5-Coder, MiniCPM5), SGLang, and deterministic mock providers.
  2. Context Assembler (x2harness.context): AST skeletonization, PageRank repository maps, FastCDC content-defined chunking, and working set token budgeting.
  3. Tool Dispatcher (x2harness.tools): Typed JSON Schema registry, Model Context Protocol (MCP) client, and ring-buffer output truncation.
  4. Execution Loop & Verifier (x2harness.core & x2harness.verifier): Deterministic turn execution, 5-stage progressive verification, SBFL (Ochiai/$D^*$) fault localization, and reward-hacking guards.
  5. Planning & Refactoring Engine (x2harness.planner & x2harness.engine): Spec-to-DAG topological wave solver, dynamic plan repair, and Tree-sitter AST surgery.
  6. Scale & Enterprise Concurrency (x2harness.scale): Tarjan SCC condensation for cyclic dependency graphs, Test Impact Analysis (TIA), and ephemeral Git worktree pools.
  7. Security, Policy & Telemetry (x2harness.security & x2harness.telemetry): Zero-trust process/bwrap sandbox, non-bypassable policy gates, hierarchical JSON-L tracing, and inference unit economics.

Quickstart

Installation

# Install from PyPI
pip install x2harness

# Or install editable from repository
pip install -e .

Python API

from x2harness import AgentHarness
from x2harness.providers import OllamaProvider, OpenAICompatProvider
from x2harness.context import RepoMapAssembler
from x2harness.verifier import TestPipelineVerifier
from x2harness.tools import ToolRegistry, make_file_tools

# 1. Choose your model provider (cloud or local)
provider = OllamaProvider(model="qwen2.5-coder:1.5b")

# 2. Assemble the harness
harness = AgentHarness(
    provider=provider,
    context_assembler=RepoMapAssembler(repo_root="."),
    tools=make_file_tools(workspace="."),
    verifier=TestPipelineVerifier(test_command="pytest tests/"),
    max_turns=10,
    cost_budget_usd=0.50
)

# 3. Run autonomous task with deterministic closed-loop verification
result = harness.run(task="Fix the ZeroDivisionError in math_utils.py")
print(f"Status: {result.status.value}, Verified: {result.verified}")

Command-Line Interface (x2)

# Run agent on a task
x2 run --model ollama/qwen2.5-coder:1.5b --task "Fix broken test in tests/test_db.py"

# Inspect execution trace
x2 trace runs/trace-20260908.jsonl

# Run deterministic benchmark
x2 bench --suite minibench

License

Apache-2.0 License.

Metadata

Release files for x2harness 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for x2harness 0.1.1
File
x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details

Total release size: 435.4 kB

Release files / x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 98.3 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
944184185c9f4912dc99c95f609b06385a61f09288986dc4b396b83550caa841
BLAKE2b-256 checksum
How to use checksums
cec39bf399621c29395bf24036548a49abf0ca311c0a46e502a5e3f8b2b5d6b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 85.2 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1bc32e0d0bb78c7a81c7ed2454ad14531456718796ed7b8e06ecf0ca53dab1fa
BLAKE2b-256 checksum
How to use checksums
185fd0953da3a3b199b00c664009ca5fff612350b7a90876a7c337d8dd99406d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 99.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bf43972eb1feb9d3e3d7038c3075425fb93b18e0275091d7d1acd74f58a64adb
BLAKE2b-256 checksum
How to use checksums
657e9527dec3412af16a395aeed21f798b7337e5ebaf5814ef834bf3c914ed56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 76.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
95a91361bffbe8e879a9b4abdc474aa921338106001cae41cbdb54a6b6bd54d3
BLAKE2b-256 checksum
How to use checksums
452ef7a586307859e689acc630941e2d0e9cd1f6b627d6c6271e02c73b4cd221
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 75.7 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
122d16ecd7ed355adf2ed236536bf5f80413cfd81b0f900f93da45b76f3b3a05
BLAKE2b-256 checksum
How to use checksums
86726d0c06a453d62c026cb9442ad59624378eb5c3fada2a6688307d7ee5a462
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for x2harness 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

5 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page