Architecture

Inverted repository structure. Constitution is the root. Everything descends from it.

Governance Stack

┌─────────────────────────────────────────────────────────────┐
│                  CONSTITUTION                               │
│  constitution/CONSTITUTION.md (86 lines)                    │
│  Supreme governance. Immutable.                             │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  TRUST DEED                                 │
│  deeds/TRUST_DEED.md (48 lines)                             │
│  TD-GAUNTLET-001. Multi-party obligations.                  │
│  deployment_allowed := security ∧ compliance                │
│                     ∧ logic ∧ human                         │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  AGENT RUNTIME                              │
│  8 source files. 996 lines. Zero runtime dependencies.      │
│  HTTP server → Middleware → State machine → WORM ledger     │
│  Ed25519 signing → Hash chain → Atomic writes → File lock   │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  SENTINEL REVIEW                            │
│  Security audit. Injection check. Auth verification.        │
│  25 findings. 15 patches. 0 remaining.                      │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  LEAN PROOF LAYER                           │
│  3 files. 7 proven theorems. 2 sorry. 5 axioms.            │
│  TrustDeed.lean · TaskInvariants.lean · LedgerChain.lean    │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  HUMAN APPROVAL                             │
│  OPERATOR: Jessica Westerhoff                               │
│  Final authority. Override power. Deployment gate.          │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  DEPLOYMENT GATE                            │
│  4 conditions from Trust Deed:                              │
│  1. security_passed = true (SENTINEL approved)             │
│  2. compliance_passed = true (constitution satisfied)      │
│  3. logic_passed = true (tests pass)                       │
│  4. human_approved = true (operator signed)                │
└───────────────────────┬─────────────────────────────────────┘
                        │
                        ▼
┌─────────────────────────────────────────────────────────────┐
│                  WORM LEDGER                                │
│  Append-only JSONL. SHA-256 hash chain.                     │
│  Ed25519 signatures. Sealed segments.                       │
│  Atomic writes. File locking. Tamper-evident.               │
└─────────────────────────────────────────────────────────────┘

Source Files

FileLinesPurpose
src/types.ts50AgentName, TaskStatus, LedgerEntryType, Task, LedgerEntry
src/hash.ts37SHA-256 hashing with | delimiters, timing-safe compare
src/validation.ts57Input validation, state transition validation
src/ledger.ts196WORM ledger, hash chain, sealed segments, signature verification
src/tasks.ts184Task CRUD, state machine, agent authorization
src/server.ts281HTTP server, signed middleware, regex routing
src/agent-keys.ts132Ed25519 keypair generation, signing, verification
src/file-lock.ts101File locking, atomic writes, PID stale detection

Task State Machine

pending ──→ in_progress ──→ completed
                │
                └──→ rejected

Valid transitions:
  pending     → in_progress
  pending     → rejected
  in_progress → completed
  in_progress → rejected

Terminal states: completed, rejected

Request Flow

HTTP Request
    │
    ▼
┌─────────────────────┐
│  parseBody()        │  100KB limit
└─────────┬───────────┘
          │
          ▼
┌─────────────────────┐
│  requireSignedAgent │  Ed25519 verification
│  ├── agent in set?  │
│  ├── key matches?   │
│  ├── sig valid?     │
│  └── hash matches?  │
└─────────┬───────────┘
          │
          ▼
┌─────────────────────┐
│  Task Manager       │  State machine validation
│  ├── createTask     │
│  ├── startTask      │
│  ├── completeTask   │
│  └── rejectTask     │
└─────────┬───────────┘
          │
          ▼
┌─────────────────────┐
│  Ledger.append()    │  WORM entry
│  ├── hash chain     │
│  ├── signature      │
│  ├── atomic write   │
│  └── file lock      │
└─────────┬───────────┘
          │
          ▼
     HTTP Response

Hash Chain

Entry[i].hash = SHA256(
  seq | type | agent | timestamp | payload | prev_hash
)

Entry[i].prev_hash = Entry[i-1].hash

Entry[1].prev_hash = "0000...0000" (genesis)

Tamper detection:
  Modify Entry[3]
    → Entry[4].prev_hash mismatch → CHAIN BREAK
    → Recompute Entry[4].hash
    → Entry[5].prev_hash mismatch → CASCADE

File Tree

agent-farm-gauntlet/
  constitution/
    CONSTITUTION.md — 62 lines, supreme governance
    SENTINEL_RULES.md — 28 lines, stop conditions
    FAILURE_MODES.md — 36 lines, F-001..F-007
  deeds/
    TRUST_DEED.md — 48 lines, TD-GAUNTLET-001
  schemas/
    task.json — 60 lines
    ledger.json — 68 lines
  agents/
    ALLOWED_AGENTS.md — 14 lines
  proofs/
    TrustDeed.lean — 70 lines, 3 proven
    TaskInvariants.lean — 76 lines, 4 proven
    LedgerChain.lean — 89 lines, 2 sorry
  apps/agent-task-ledger/
    src/ — 8 files, 996 lines
    tests/ — 21 tests, 291 lines
  worm/ — 8 entries, hash-chained
  audit/ — 6 reports, 1,497 lines
  scripts/ — doctor, verify-chain, demo
  docs/ — This site