|
| 1 | +# Agent Contribution Contract |
| 2 | + |
| 3 | +> **Purpose:** Define the required gates and validation steps that any AI agent (Claude Code, Devin, subagent, or other harness) must pass before contributing to the TeaAgent repository. |
| 4 | +> |
| 5 | +> **Scope:** All automated commits to the TeaAgent repository, regardless of which agent harness authored them. |
| 6 | +> |
| 7 | +> **Status:** Active (V4-a, 2026-06-12) |
| 8 | +
|
| 9 | +## Problem Statement |
| 10 | + |
| 11 | +The TeaAgent repository is now edited by multiple agent harnesses (Claude Code sessions, subagent lanes, Devin, plus the human owner). TeaAgent's product is agent governance, but its own contribution path had no agent-facing contract. This led to V1 (drift gate failure on main) where a false "verified" claim landed via a second AI agent. |
| 12 | + |
| 13 | +## Required Pre-Commit Gates |
| 14 | + |
| 15 | +Before any agent-authored commit can be made, the following validations must pass: |
| 16 | + |
| 17 | +### 1. Docs Consistency Gate |
| 18 | + |
| 19 | +**Command:** `python3 scripts/validate_docs_consistency.py --test-quality-mode off` |
| 20 | + |
| 21 | +**Purpose:** Ensures documentation claims match runtime state and prevents drift. |
| 22 | + |
| 23 | +**What it checks:** |
| 24 | +- Acceptance test count in `docs/acceptance.md` matches pytest collection |
| 25 | +- Provider counts are consistent across README, architecture.md, and runtime |
| 26 | +- Docs inventory is up to date |
| 27 | +- Suite summary freshness (WDB-004) if test counts are cited |
| 28 | +- Roadmap required fields are present |
| 29 | +- Risk register and ticket index evidence coverage |
| 30 | + |
| 31 | +**Failure mode:** Gate exits non-zero; commit must not proceed. |
| 32 | + |
| 33 | +### 2. Test Collection Gate |
| 34 | + |
| 35 | +**Command:** `python3 -m pytest tests/acceptance --collect-only -q` |
| 36 | + |
| 37 | +**Purpose:** Ensures the test suite is collectible (no import errors, missing dependencies). |
| 38 | + |
| 39 | +**Failure mode:** Collection fails with import errors (e.g., missing `hypothesis` in system Python). |
| 40 | + |
| 41 | +**Note:** The repo venv (`.venv/bin/python`) is preferred for consistency with docs gate. |
| 42 | + |
| 43 | +### 3. Lint and Format Gate |
| 44 | + |
| 45 | +**Commands:** |
| 46 | +```bash |
| 47 | +ruff check . |
| 48 | +ruff format --check . |
| 49 | +``` |
| 50 | + |
| 51 | +**Purpose:** Ensures code style consistency and catches common errors. |
| 52 | + |
| 53 | +**Failure mode:** Non-zero exit from either command. |
| 54 | + |
| 55 | +### 4. Type Check Gate |
| 56 | + |
| 57 | +**Command:** `mypy teaagent/ tests/ --explicit-package-bases` |
| 58 | + |
| 59 | +**Purpose:** Ensures type annotations are correct and complete. |
| 60 | + |
| 61 | +**Failure mode:** Non-zero exit from mypy. |
| 62 | + |
| 63 | +## Claim-Bearing Files Requiring Passing Gates |
| 64 | + |
| 65 | +The following files contain governance-relevant claims and require a passing gate in the same commit that modifies them: |
| 66 | + |
| 67 | +| File | Claim Type | Required Gate | |
| 68 | +|------|------------|---------------| |
| 69 | +| `docs/acceptance.md` | Acceptance test count | `test_docs_acceptance_count_accuracy.py` must pass | |
| 70 | +| `README.md` | Provider count, feature claims | Provider consistency validation must pass | |
| 71 | +| `docs/architecture.md` | Architecture claims, provider counts | Provider consistency validation must pass | |
| 72 | +| `docs/roadmap-status.md` | Roadmap claims, status values | Roadmap validation must pass | |
| 73 | +| `docs/governance-compliance.md` | Governance gate mappings | Docs consistency validation must pass | |
| 74 | +| `docs/generated/suite-summary.json` | Test suite results | Must be regenerated with current commit | |
| 75 | + |
| 76 | +## Commit Trailer Requirements |
| 77 | + |
| 78 | +Agent-authored commits should include the following trailers for traceability: |
| 79 | + |
| 80 | +``` |
| 81 | +Agent: <agent-name> (e.g., "Claude Code", "Devin", "subagent") |
| 82 | +Agent-Session: <session-id-or-context> |
| 83 | +Reviewed-by: <human-optional> |
| 84 | +``` |
| 85 | + |
| 86 | +Example: |
| 87 | +``` |
| 88 | +fix: update acceptance test count to 646 |
| 89 | +
|
| 90 | +Agent: Devin |
| 91 | +Agent-Session: cli-2026-06-12-001 |
| 92 | +``` |
| 93 | + |
| 94 | +## CI Enforcement |
| 95 | + |
| 96 | +The `use-case-matrix` job in `.github/workflows/ci.yml` runs the docs consistency gate as a required check. Branch protection rules must require this check to pass before merging to main. |
| 97 | + |
| 98 | +## Emergency Override |
| 99 | + |
| 100 | +**NO SELF-SERVICE BYPASS ALLOWED** (V4-c fix): Agents cannot bypass their own governance gate via trailers or environment variables. This prevents the exact failure mode the contract is designed to prevent. |
| 101 | + |
| 102 | +In rare cases where a gate must be bypassed (e.g., fixing the gate itself): |
| 103 | +1. Human must temporarily disable the CI check via GitHub UI |
| 104 | +2. Commit with trailer: `Manual-bypass: <reason> <ticket-id>` |
| 105 | +3. Open a PR referencing the bypass |
| 106 | +4. Human review required before merge |
| 107 | +5. Re-enable CI check after merge |
| 108 | + |
| 109 | +## Implementation Status |
| 110 | + |
| 111 | +- ✅ Docs consistency gate exists and runs in CI |
| 112 | +- ✅ Test collection gate exists as acceptance count accuracy test |
| 113 | +- ✅ Lint/format/type check gates exist in CI |
| 114 | +- ✅ Agent contribution contract gate exists in CI (V4-a) |
| 115 | +- ✅ Anti-bypass enforcement implemented (V4-c) - no self-service bypass allowed |
| 116 | +- ✅ Fixture tests for contract gate (V4-d) - `tests/test_governance_compliance.py::TestAgentContributionContract` |
| 117 | +- ✅ Python interpreter preference (venv over system) for consistency (third-pass fix) |
| 118 | +- ✅ Auto-regenerate docs inventory to avoid staleness from multi-agent concurrent edits (third-pass fix) |
| 119 | +- ⚠️ Branch protection enforcement requires manual GitHub configuration (see V1-b) |
| 120 | + |
| 121 | +## References |
| 122 | + |
| 123 | +- V1 finding: Drift gate failed open on commit `e2e8317` |
| 124 | +- V4 finding: Multi-agent contribution surface ungoverned |
| 125 | +- `docs/governance-compliance.md` for full gate mapping |
| 126 | +- `scripts/validate_docs_consistency.py` for gate implementation |
0 commit comments