Metadata-Version: 2.5
Name: harness-builder
Version: 1.0.1
Summary: Vendor-neutral AI Agent Engineering Harness CLI and Antigravity plugin
Project-URL: Homepage, https://github.com/Mr-Fred/harness-builder
Project-URL: Repository, https://github.com/Mr-Fred/harness-builder
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# harness-builder

Personal, open-source, vendor-neutral AI Agent Engineering Harness for Google
Antigravity (`agy` IDE & CLI).

`harness-builder` keeps methodology in a single globally installed Antigravity
plugin while keeping scaffolded repositories thin, deterministic, and strictly
within startup token budgets.

## Architecture

```text
harness-builder/
├── plugin/                     # Installable Antigravity plugin (rules, 11 skills, 4 subagents, templates, hooks)
└── src/harness_builder/        # Pure Python 3.11+ stdlib-only CLI (`hb`)
    ├── core/                   # Functional core (schema, frontmatter, token budget, design lint, plan, drift, repo detector)
    ├── adapters/               # Imperative shell (git, safe fs, repo scanner, scaffolder, doctor)
    └── cli.py                  # Thin argparse entrypoint (`hb`)
```

- **Zero runtime dependencies:** Python 3.11+ standard library only (`uv` manages dev tooling).
- **Plugin owns methodology; repos stay thin:** `hb init` never copies `plugin/` into target repos.
- **Strict startup token discipline:** Combined plugin + project `always_on` context stays `<= 3,000` tokens (hard cap `4,500`). Detailed project docs (`.agents/PROJECT_STRUCTURE.md`, `.agents/DEPENDENCIES.md`, `.agents/RULES.md`, `.agents/GETTING_STARTED.md`) load strictly on demand.

## Quickstart

### 1. Install Globally (Zero `git clone` Required)

Install the `hb` CLI from PyPI (with `plugin/` bundled inside the wheel) and
register the Antigravity plugin once on your machine—never clone
`harness-builder` inside your project repositories:

```bash
uv tool install harness-builder
hb install-plugin
hb doctor .
```

*(Install from `main` directly via `uv tool install git+https://github.com/Mr-Fred/harness-builder.git`, or for local contributor development run `uv sync --dev && uv tool install -e . && hb install-plugin`.)*

### 2. Onboard a New (Greenfield) or Existing (Brownfield) Repository

`harness-builder` uses a **2-Stage Hybrid Bootstrap** — deterministic offline
scaffolding via `hb init` followed by optional agentic hydration via
`/hb-bootstrap` inside Antigravity:

```bash
# Preview every CREATE / MERGE / SKIP action without touching disk
hb init --mode auto --dry-run /path/to/repo

# Scaffold safely (merges managed block into existing AGENTS.md; never clobbers CLAUDE.md, .cursorrules, GEMINI.md, or docs/)
hb init --mode auto /path/to/repo
```

For existing repositories, open the repo in Antigravity and run `/hb-bootstrap`
to hydrate `.agents/PROJECT_STRUCTURE.md`, `.agents/DEPENDENCIES.md`,
`.agents/rules/PROJECT_RULES.md`, and `.agents/GETTING_STARTED.md`, verify
detected test/lint commands, and confirm `hb check .` passes with startup tokens
`<= 3,000`.

## 3-Tier, 4-Stage SDLC Loop

| Tier | Blast Radius | Required Workflow |
| :--- | :--- | :--- |
| **Tier 1 (Surgical)** | `<= 100` LOC, single module or bugfix | Direct edit + paired test + Stop verification. Zero ceremony. |
| **Tier 2 (Feature / Refactor)** | `100–400` LOC | `/hb-design` (`brief`, `<= 750` words) → `/hb-plan` → `/hb-build` → `/hb-ship` (`hb drift` + fresh-context `zero-trust-verifier`). |
| **Tier 3 (Architecture / Epic)** | `> 400` LOC, new subsystem, schema, or API | `/hb-design` (`full`, `<= 1,800` words + 4-lens `design-gauntlet`) → `/hb-plan --scorecard` → iterative `/hb-build` → `/hb-ship` (`hb drift --mode strict`). |

## CLI Command Reference (`hb`)

```bash
hb install-plugin [--plugin-dir <dir>] [--dry-run] [--json]
hb init [--name <name>] [--mode auto|new|existing] [--stack python,ts,go,rust] [--docs-dir docs] [--dry-run] [--force] [dir]
hb check [--strict] [--plugin-dir ./plugin] [--json] [dir]
hb visualize [--plugin-dir ./plugin] [--json] [dir]
hb design-lint [--tier brief|full] [--json] <design.md>
hb plan [--scorecard] --out-dir <dir> [--json] <design.md>
hb drift [--mode advisory|strict|blocking] [--json] <design.md> <src_dir>
hb doctor [--strict] [--json] [dir]
```

*`hb drift` modes:* `advisory` always exits `0`; `blocking` exits `1` on `error`
findings (`missing_symbol`, `signature_mismatch`, `protected_file_missing`);
`strict` exits `1` on any error or `unspec_public_symbol` warning.

## Lifecycle Hooks & Safety Guards (`plugin/hooks/`)

All hooks run isolated via `python3 -I -B` with zero non-stdlib imports, zero
`shell=True`, explicit subprocess timeouts, and fail-open behavior on malformed
inputs or timeouts:

- **`PreToolUse` (`pre_tool_guard.py`, `< 150ms` p95):** Blocks deletion or
  tampering of protected files (`AGENTS.md`, `.agents/harness.json`,
  `.agents/rules/PROJECT_RULES.md`), catastrophic `rm`, force-push/deletion on
  protected branches (`main`, `master`), oversized `README.md` writes, unpaired
  production commits, `> 400`-line commits, and invalid commit subjects.
- **`PostToolUse` (`post_tool_format.py`, 10s timeout):** Fail-open runner for
  configured `verification_loop.format_commands`.
- **`Stop` (`verify_stop.py`, 60s timeout):** Runs configured test and lint
  commands when uncommitted changes exist, backed by a persistent atomic circuit
  breaker (`~/.cache/harness-builder/state/<conversation_id>.json`) and an
  emergency `HB_BYPASS_STOP_HOOK=1` escape hatch.

## Development & Verification

```bash
uv run pytest tests/unit tests/hooks tests/e2e -v
uv run ruff check src tests plugin/hooks
uv run mypy --strict src
agy plugin validate --strict ./plugin
hb check . && hb doctor .
```
