# Evolution 81 — Architecture

## Doctrine

```
AGENT PROPOSES -> CAIN DECIDES -> MCPGATE ENFORCES -> SYSTEM EXECUTES -> EVIDENCE REMEMBERS
NO AUTHORIZATION -> NO EXECUTION
```

Five concepts are kept separate in code, data and reports:

| concept | where it lives | what it is not |
|---|---|---|
| Intelligence | `models.py` + the model weights | not authority |
| Specialization | `registry.py` profiles | not domain expertise by declaration |
| Collective intelligence | `evaluation.py` arms + measured results | not assumed superiority |
| Autonomous operations | `durable.py` + `endurance.py` | not a claim of thousands of hours |
| Governance | `core.Gate`, `killswitch.py`, `resources.py` | not a model's opinion |

## Five levels

1. **CAIN-42 governance authority** — `core.Gate`: identities, signed single-use grants, attenuation,
   tenant isolation, revocation, budget, audit chain.
2. **Global workforce orchestrator** — `workforce.Orchestrator`: mission creation, deterministic
   planning, goal-drift refusal, dependency assignment, checkpoints, verification, completion.
3. **Domain commanders** — `workforce.COMMANDS`: 8 domains. A commander is a signed record with
   `authority: []`, `can_grant_authority: false`; it cannot grant or bypass CAIN.
4. **Specialist agents** — `registry.py`: 30 disciplines × 3 shapes = 90 versioned profiles, each
   with tools, memory scopes, risk ceiling, measured competency, reliability history.
5. **Execution workers** — real OS processes (`capacity.py`, `durable.run_worker`) that claim
   leased fenced tasks. Worker death never destroys identity, memory or mission state.

## Module map

| module | responsibility |
|---|---|
| `core.py` | canonical JSON, SHA-256, Merkle, stats, persistent Ed25519 identity store |
| `registry.py` | disciplines, profiles, measured levels, attenuated composition |
| `models.py` | model catalog, health, local/remote engines, routing, cache, governed inference |
| `durable.py` | SQLite mission/task/effect/checkpoint/dead-letter store, leases, fencing |
| `workforce.py` | logical agents, commanders, worker pools, orchestrator, goal-drift |
| `resources.py` | hierarchical budgets, admission control, retry caps, forecasting |
| `killswitch.py` | signed monotonic global emergency control across processes |
| `sandbox.py` | bubblewrap execution + isolation probes |
| `memory.py` | AES-256-GCM temporal memory, provenance, ACL, contradiction, promotion guard |
| `evidence.py` | hash-chained events, canonical manifest, Merkle root, signature |
| `capacity.py` | staged worker capacity with caps and shutdown conditions |
| `crosshost.py` | SSH second-host execution and lost-acknowledgement recovery drill |
| `clawx.py` | authenticated evidence HTTP backend |
| `endurance.py` | real wall-clock resumable campaign |
| `acceptance.py` | 40-gate matrix computed from artifacts |

## Mission state machine

`CREATED → AUTHORIZED → PLANNING → RUNNING → {PAUSED, REPLANNING, VERIFYING, SUSPENDED,
FAILED, CANCELLED, EXPIRED} → {COMPLETED, COMPLETED_WITH_UNVERIFIED_ITEMS}`

Transitions are transactional and legal-edge-only. Terminal states are irreversible. `COMPLETED`
requires every task `DONE`; verification may downgrade to `COMPLETED_WITH_UNVERIFIED_ITEMS`.

## Authority invariants (implemented, tested)

1. No identity → no decision (`UNKNOWN_IDENTITY`).
2. No grant → no execution; every grant is signed, scoped, expiring, single-use, fenced.
3. A child grant can only attenuate its parent.
4. Composition unions competence but **intersects** tools/scopes and takes the **minimum** risk ceiling.
5. A commander, model, memory record, skill or plan carries `authority: []`.
6. A revoked identity cannot be silently reinstated (explicit, signed, logged reinstate).
7. Budget exhaustion stops work; it is never swallowed.
8. An error is never a success: a failed task is FAILED or a dead letter.

## Evidence model

Every event carries: event_id, agent_id, mission_id, utc, host, authorization_ref, execution_ref,
payload + digest, provenance, execution_class, verification_status, prev hash, agent signature,
hash. The bundle manifest lists every file with SHA-256, a domain-separated RFC 6962-style Merkle
root, the verdict, the evidence class and the signer fingerprint, signed by Ed25519.

Evidence classes: `LOCAL`, `MOCK`, `SIMULATED`, `DEPLOYED`, `INDEPENDENTLY_VERIFIED`. This
evolution produces `LOCAL` only. Nothing is labelled `DEPLOYED` or `INDEPENDENTLY_VERIFIED`.

## What is deliberately absent

No new CAIN moat. No production change. No remote model call. No container runtime beyond
bubblewrap. No cloud provisioning. No claim of AGI or thousands of hours. No fabricated
live dashboard: ClawX reads only files written by executed runs.
