Skip to content

About

Zero-dependency guardrails for Claude Code, Codex, Gemini, Cursor & Copilot — 5-layer doc-code anti-drift, 6-host rule compiler, offline Web UI (alh ui) & token ablation eval

Topics

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

AgentLock Harness

Guardrails for Claude Code, Codex, Gemini, Cursor & Copilot — that actually save tokens.

English | 简体中文

CI npm version Node >= 18 Zero Dependencies Tests License: MIT

Release Notes (v0.1.0) · Roadmap · Evaluation Protocol · Security · Contributing


AgentLock Harness Architecture and Empirical Benchmark

See It On Your Own Repo in 10 Seconds

Requires Node.js ≥ 18 only (package.json has 0 third-party dependencies — no npm install, no Python, no database):

# Option 1: One-line preview via npm (no clone required)
npx agentlock-harness ui /path/to/your-project

# Option 2: Install globally for the short `alh` command
npm install -g agentlock-harness
alh ui /path/to/your-project

Zero risk: alh ui is completely read-only until you preview a file tree and click Confirm. It binds strictly to 127.0.0.1 with a one-time session token and never writes UI files into your repository.


Built-In Local Web Console (alh ui)

A fast, offline desktop-style workbench powered purely by Node.js node:http. Every panel exposes a collapsible equivalent CLI command so anything you click can be dropped straight into CI.

Health and Guardrails Dashboard
Health & Guardrails — auto EN/ZH entry budget meters, 6-host rule drift status, universal Git Hooks switch, streaming Verify console, and alh stats block telemetry
Dual-Strategy Brownfield Onboarding
Onboarding & Doctor — detects existing legacy docs, lets you choose Thin-Route vs Archive & Cross-Distill, and previews every move/file before writing
Spec Change Board and DAG Task Ledger
Spec & DAG Board — edit delta.md, check off acceptance.md live, crystallize SPEC.md on archive, and track zero-DB DAG tasks

Why This Exists (and Real Proof It Works)

Most teams trying to govern AI coding agents hit a frustrating wall:

  • Run agents bare: Fast on toy files, risky in real repos — agents silently regress distant monorepo packages, edit .env under outage pressure, skip acceptance checks, or forget prior decisions across sessions.
  • Install heavy prompt/skill frameworks: Stuffing dozens of always-on skills and long handbooks into every prompt slows frontier models down (+35.7% latency in our early Codex CLI 0.172.0 tests) and burns billable tokens on ceremony.

AgentLock Harness splits the problem in two (Dumbbell Zero-Tax Architecture):

  1. Tiny context top: Keep AGENTS.md (≤50 lines), SESSION.md (≤60 lines), and docs/00-context.md (≤80 lines); --lean installs only your active host adapter and skips skill bloat; 1–3 file fixes require zero change docs.
  2. Hard 0-token local bottom: Secret blocking, enterprise policy.json approval paths, unchecked acceptance gates, 6-host rule drift checks, and cross-package test backpressure run locally in Node.js and Git hooks — 0 LLM tokens, impossible to talk around.

Before & After: Same Task, Different Agent Behavior

Scenario Bare Agent (No Guardrails) With AgentLock Harness (--lean + Local Gates)
F01 · 240+ file monorepo time-format fix Edits packages/core-time, runs its local test (passes), and stops — silently breaking SHA-256 Merkle hashes in distant packages/audit-ledger and CSV exports in packages/reports. docs/00-context.md routes directly to the coupled packages (-38.3% billable tokens); universal Git pre-commit / pre-push blocks regressions at 0 LLM tokens.
F03 · P0 outage ticket nudging .env.production & infra/auth-policy.tf edits Searches broadly under pressure (21 tool calls) or attempts unauthorized production/policy edits as a shortcut. policy.json + local pre-tool-guard / staged-guard physically block protected paths while keeping execution focused (14 tool calls, -33%; 0 violations).
Brownfield repo with 30+ legacy docs Generic scaffolders drop parallel blank templates (04-design/*.md) next to real docs, creating conflicting sources of truth. alh adopt detects existing docs/ and defaults to thin-route (auto minimal, zero duplicate templates) — or opt-in archive-switch to move old docs to docs/legacy-archive/ (auto-excluded) and seed Archive × Live-Code distillation tasks.

Measured Benchmark (codex-cli 0.172.0 · Frontier Suite · Paired 3/3)

Measured via alh eval run --suite frontier --agent codex (all runs completed, zero timeouts, strict paired (caseId, repeat) comparison — full protocol in docs/agent-evaluation.md):

Stress Case Setup Pass Rate Total Tokens Billable (Fresh+Out) Savings vs Bare Cache Hit Tool Calls
F01 · 240+ File Monorepo Merkle Regression Bare Agent 100% 463.9k 54.1k — 89% 16
AgentLock Harness 100% 442.1k 33.4k -38.3% 93% 17
F03 · P0 Outage + Approval Policy Wall Bare Agent 100% 533.7k 32.4k — 94% 21
AgentLock Harness 100% 411.7k 32.1k -0.9% 93% 14 (-33%)
Frontier Mean (incl. F02 4-session relay) Bare Agent 100% (3/3) 999.5k 89.0k — 92% 35.3
AgentLock Harness 100% (3/3) 973.4k 86.0k -3% 92% 35.7

Full physical Git/Hook guardrails paid for themselves — cutting billable tokens by 38.3% on the large monorepo and 3% overall compared to running bare.


Keeping Docs, Rules & Code in Sync (5-Layer Anti-Drift)

Most AI doc tools stop at generating Markdown. Three months later, code moves on, docs go stale, and stale specs actively mislead agents. AgentLock Harness combines 0-token deterministic guards with spec-aware semantic review:

Layer Mechanism What It Catches Cost
1. Contract Hygiene validate-docs + code_refs (alh map) Broken links, TODO/placeholders left in Current specs, missing code_refs paths, or oversized entry files 0 tokens
2. Commit & Live Drift Guard staged-guard.mjs + alh verify + alh ui Editing code covered by a Current doc's code_refs without updating that doc (warns by default; opt-in hard block via guardrails.requireDocSyncOnMappedChanges: true, one-off bypass AGENTLOCK_HARNESS_SKIP_DOC_DRIFT=1) 0 tokens
3. Change Crystallization alh change + stop-gate.mjs Skipping acceptance checks before exit; archiving appends verified deltas straight into SPEC.md 0 tokens
4. 6-Host & Legacy Isolation alh rules check + alh adopt Drift across Claude/Codex/Gemini/Cursor/Copilot rules, or duplicate parallel templates beside legacy docs/ 0 tokens
5. Semantic Drift Audit Spec-aware alh review (cross-review.mjs) Subtle behavior shifts (e.g., timeout 30s → 60s, changed defaults/error shapes) by auto-injecting mapped Current specs (≤6k chars) into the read-only cross-model diff audit On demand

Honest boundary: Deterministic scripts catch structural drift and forgotten doc updates at 0 tokens, but cannot read prose intent. Layer 5 (alh review) closes that semantic gap right before merge.


Already Using AGENTS.md, Cursor Rules, OpenSpec, or Beads?

You do not have to replace your existing workflow. Teams layer AgentLock Harness on top for three things Markdown instructions alone cannot do:

  1. Physical 0-token enforcement: Markdown rules are suggestions; pre-tool-guard, stop-gate, and Git pre-commit/pre-push enforce secrets, approval policies, and acceptance criteria deterministically across every agent.
  2. One rule source → 6 hosts, zero drift: Maintain rules once under .agentlock-harness/rules/*.md and compile cleanly (zero timestamps, KV-cache safe) to Claude Code, Codex CLI, Gemini CLI / Antigravity, Cursor, and GitHub Copilot.
  3. Compatible by default, measurable by design: alh adopt detects and preserves existing SPEC.md, openapi.*, openspec/, and .specify/, while alh eval lets you benchmark your own rules on your own CLI.

How It Compares to Popular Tools

Area Popular Tools Typical Trade-Off AgentLock Harness
Spec Workflows OpenSpec / GitHub Spec Kit Often requires 4+ files per change even for small tasks; checklist boxes are not enforced on exit Respects existing OpenSpec / Spec Kit / SPEC.md; otherwise uses a 2-file alh change flow (delta.md + acceptance.md), skips 1–3 file fixes, blocks unchecked ACs in stop-gate.mjs, and crystallizes SPEC.md on archive
Doc-Code Anti-Drift Static Docs / Spec Generators Generates docs once, with no commit-time mapping or semantic audit when code changes later code_refs commit/working-tree drift guard (staged-guard, alh verify, alh ui) + opt-in hard block + spec-aware alh review semantic diff audit
Multi-Host Rules Rulesync / Ruler Focuses on format conversion; timestamps can bust KV caches and rules are separate from runtime checks Compiles 1 source to 6 hosts with zero timestamps, ships standalone rules-drift-check.mjs, and pairs with Hook/Git gates
Context & Skills Superpowers / BMad Method / Cline Memory Bank Always-loaded skills and full-read memory banks grow with the repo and add measurable latency/token cost Enforces strict entry budgets (<=50L/60L/80L), replaceable SESSION.md, and --lean single-host adapters
Task Graphs Beads Depends on external storage (e.g. Dolt) or background daemons Zero-DB tasks.json DAG ledger + OS O_CREAT | O_EXCL atomic locks + DFS cycle checks
Brownfield Docs Typical Scaffolders Drops empty templates beside existing docs/, creating duplicate truth Dual strategy: thin-route (auto minimal, zero parallel Drafts) or archive-switch (docs/legacy-archive/ auto-excluded + Archive × Live-Code distillation DAG)
Footprint & UI Multi-runtime / Python Stacks Requires virtualenvs, DBs, or separate web toolchains 0 third-party npm dependencies (pure Node.js ≥ 18) + built-in offline Web Console (alh ui)
Benchmarks Most AI Scaffolds No built-in way to prove whether rules help or hurt Built-in 12-case Behavioral & Token/Cache Eval Engine (alh eval)

Common CLI Workflows

1. Adopt an Existing Repository (Brownfield)

cd /path/to/existing-project

# Strategy 1 (Default · Thin-Route): keeps existing docs untouched, auto-selects minimal
# to prevent parallel Drafts, indexes existing docs in 00-context.md, and activates 0-token gates
alh adopt . --lean --hosts codex --dry-run
alh adopt . --lean --hosts codex

# Strategy 2 (Full Migration · Archive & Cross-Distill):
# Moves legacy docs to docs/legacy-archive/ (auto-excluded in docs.config.json),
# scaffolds your chosen Domain Profile + MIGRATION_PLAN.md + Archive x Live-Code DAG tasks
alh adopt . --lean --profile web-saas --docs-strategy archive-switch --dry-run
alh adopt . --lean --profile web-saas --docs-strategy archive-switch --confirm-archive

# Verify docs, rule zero-drift, Git hooks, and test commands
alh verify . --run-checks

2. Start a New Repository (Greenfield)

mkdir my-app && cd my-app && git init
alh init . --lean --locale en-US

3. Daily Cadence

Change Size Recommended Flow
1–3 file local fix Work directly with your agent — zero ceremony
Feature / cross-module / contract change alh change new <slug> → implement & test → check off acceptance.md → alh change archive <slug> (syncs SPEC.md)
Before merge / release alh verify . --run-checks + alh review (read-only cross-model diff audit)

Command Reference

Command Description
alh ui [dir] [--port 4318] [--no-open] Launch zero-dependency local Web Console (127.0.0.1 + anti-CSRF token)
alh adopt [dir] [--lean] [--docs-strategy thin-route|archive-switch] Brownfield scan, dual legacy-doc migration, auto Git hooks & CLI audit
alh init [dir] [--lean] / alh update [dir] Greenfield scaffold / SHA-256 manifest safe incremental update
alh verify [dir] [--strict] [--run-checks] Deterministic doc structure, live code_refs doc-code drift, spec status, rule drift & test backpressure check
alh change <new|list|status|verify|archive> 2-file change workflow with lazy SPEC.md crystallization
alh rules <compile|check|list> [dir] 6-host single-source path-scoped rule compiler & drift checker
alh hooks <install|status|uninstall> [dir] Install, inspect, or remove universal Git pre-commit / pre-push guardrails
alh review [dir] [--reviewer codex|claude|gemini] Run spec-aware read-only cross-model diff audit against git diff HEAD and mapped Current docs
alh task <add|list|ready|claim|done|graph> Zero-DB DAG task ledger with atomic file locking
alh ralph [dir] [--max-iterations N] Unattended fresh-context loop wired to DAG ledger & stall/deadlock breakers
alh eval <list|run|scaffold|grade> 12-case behavioral + Token/Cache ablation engine
alh stats [dir] / alh doctor [--fix] Zero-PII guardrail telemetry / local CLI toolchain audit & install
alh find / alh map Bounded read-only doc search / source-change impact lookup

Scope, Platform Support & Security

  • CI Coverage: Tested on Linux and macOS across Node.js 18, 22, and 24 (174 passing tests). Windows PowerShell bootstrap is included (Git Hooks rely on Git Bash; experimental).
  • Evaluation Boundaries: npm run check and mock-oracle verify scripts, templates, and graders — not LLM accuracy. Real model numbers require running alh eval with your own CLI driver per docs/agent-evaluation.md.
  • Security: Local-first threat model and private vulnerability reporting are documented in SECURITY.md.
  • Contributing: See CONTRIBUTING.md and AGENTS.md.
  • License: MIT License.

About

Zero-dependency guardrails for Claude Code, Codex, Gemini, Cursor & Copilot — 5-layer doc-code anti-drift, 6-host rule compiler, offline Web UI (alh ui) & token ablation eval

Topics

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages