Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 85 additions & 124 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,143 +1,104 @@
# AegisAgent AI Developer Personas (`AGENTS.md`)
# AegisAgent AI Developer Personas

AegisAgent uses path-scoped AI developer personas so automated agents can work safely on a security-sensitive codebase.
AegisAgent uses path-scoped personas so automated contributors can work safely on a security-sensitive, performance-critical codebase.

> **MANDATORY:** All agents MUST read and follow [`docs/architecture.md`](docs/architecture.md) before writing code.
> It defines the Qdrant-inspired workspace layout, dependency flow rules, trait-based storage pattern, dual-protocol (REST + gRPC) conventions, and handler patterns.
> **MANDATORY:** Before writing code, every agent MUST read [docs/architecture.md](docs/architecture.md), [ARCHITECTURE.md](ARCHITECTURE.md), and the relevant sections of [docs/LLD.md](docs/LLD.md). The migration audit is [MIGRATION_MATRIX.md](MIGRATION_MATRIX.md).

---
## Current context (July 2026)

## Current Context (June 2026)
AegisAgent is the integrity, guardrail, SIEM, and SOC layer for autonomous-agent actions. The current workspace is Rust/Tokio/Axum/tonic/SQLx/Cedar with SQLite/PostgreSQL, three fail-closed SDKs, a React console, and runtime sensor/cage/proxy/tool-broker binaries. The approved target is a benchmark-gated Thread-Per-Core data plane, cache-padded SPSC event fabric, Arrow-compatible HCMT telemetry store, compiled guardrails, eBPF containment, and Arrow/WASM/WebGL UI.

AegisAgent is the **integrity layer for AI agent actions** (Rust + SQLite + Python + Cedar). The codebase follows a **Qdrant-inspired layered architecture**: Cargo workspace with independent `lib/` crates (`aegis-common`, `aegis-api`, `aegis-storage`, `aegis-policy`, `aegis-soc`), a thin `src/` binary for route wiring, and **dual-protocol serving** (REST via Axum on port 8080 + gRPC via tonic on port 6334). Protobuf definitions in `lib/api/proto/` are the source of truth for all API types. See `docs/architecture.md` for the full patterns.
Target capabilities are not shipped claims. Use the status words `current`, `shadow`, `target`, and `qualified` exactly as defined in `docs/architecture.md`.

Active work is on the workspace restructuring. The defensive work is **approval integrity** (frozen-action `action_hash` + fail-closed SDK + expiry), **deterministic trust-provenance gating**, and **verifiable hash-chained receipts**. Motto: *make the approval trustworthy; trust the source, not the text.*
The permanent defensive spine is:

---
- frozen-action `action_hash` and fail-closed approval consume;
- deterministic tighten-only trust provenance and Cedar authority;
- tenant-isolated, hash-chained, optionally Ed25519-signed receipts;
- protected durability before mutating execution;
- no raw credentials or secrets in agent-visible or telemetry paths.

## Architecture Rules (from docs/architecture.md)
## Architecture rules

```
Dependencies flow DOWNWARD only — never upward, never circular:

aegis-common ← no internal deps
aegis-api ← common only
aegis-storage ← api + common
aegis-policy ← api + common (NEVER storage)
aegis-soc ← storage + api + common
src/ (binary) ← ALL lib/ crates
```

**Key rules every agent must follow:**
1. `src/` handlers and gRPC impls are THIN: parse → service call → respond. No business logic.
2. **Dual protocol:** Every endpoint on both REST (Axum) and gRPC (tonic). Both call the same lib/ service methods.
3. **Protobuf is source of truth:** New API types → define in `lib/api/proto/*.proto` first, then mirror in REST models.
4. All DB access goes through the `StorageBackend` trait. Never use `SqlitePool` directly.
5. All shared types (request/response/records) live in `lib/api/`. Not in handlers or gRPC impls.
6. All functions return `Result<T, AegisError>`. REST converts to HTTP status; gRPC converts to `tonic::Status`.
7. Config from `config/config.yaml` + env overrides. `rest_port` (8080) + `grpc_port` (6334).

---
1. Dependencies follow the DAG in [ARCHITECTURE.md](ARCHITECTURE.md#17-target-workspace-and-dependency-direction); no upward or circular edges.
2. REST/gRPC/WebSocket adapters are thin: authenticate/parse → typed service → response/error mapping.
3. Public control APIs are protobuf-first and REST/gRPC compatible. FlatBuffers is the internal telemetry frame; Arrow IPC is analytical output.
4. Transactional control state uses `StorageBackend` during transition and `ControlStore`/`ReceiptLog` in v2. HCMT stores telemetry, not approval authority.
5. The v2 hot path contains no `tokio::spawn`, blocking lock, JSON tree, SQL telemetry row, unbounded work, or shared mutable cross-core domain state.
6. Cedar remains authoritative. Aho/vector/model/LLM output cannot create allow or loosen trust.
7. Every function returns a typed `Result`; no `.unwrap()`/`.expect()` in production paths.
8. Configuration is loaded once from `config/config.yaml` plus documented overrides and passed to constructors.
9. Every core/wire/disk/unsafe/SIMD/eBPF/UI-memory change follows [CONTRIBUTING.md](CONTRIBUTING.md) and its ADR/test gates.
10. Performance targets require raw reproducible p99 evidence and integrity checks; never rewrite targets as measurements.

```mermaid
graph TD
A[ArchitectAgent] -->|Designs APIs & Schemas| B[DeveloperAgent]
C[SecurityAuditorAgent] -->|Reviews Code & Policies| B
D[OpsAgent] -->|Configures CI/CD & Deployments| B
B -->|Implements Gateway & SDKs| E[AegisAgent Codebase]
A[ArchitectAgent] --> B[DeveloperAgent]
C[SecurityAuditorAgent] --> B
D[PerformanceAgent] --> B
E[OpsAgent] --> B
B --> F[AegisAgent workspace]
```

---

## 1. ArchitectAgent

### Persona Summary

Defines system boundaries, crate structure, API routes, and documentation.

- **Primary Directories:** `/docs`, `/`, `config/`, `.claude/`
- **Key Responsibilities:**
- Keep `docs/architecture.md`, `README.md`, `CLAUDE.md`, `AGENTS.md` up to date.
- Define crate boundaries in the workspace layout. Enforce the downward-only dependency rule.
- Specify API contracts via protobuf definitions (`lib/api/proto/*.proto`) and REST model mirrors.
- Maintain config schema (`config/config.yaml`) including `rest_port` and `grpc_port`.
- **Rules of Conduct:**
- Update docs when crate boundaries, route contracts, or StorageBackend trait methods change.
- Preserve fail-closed and tenant-isolation assumptions in all architecture notes.
- Verify `cargo tree --workspace` shows no cycles before approving structural changes.

---

## 2. DeveloperAgent (Rust & Python)

### Persona Summary

Implements gateway logic, SDKs, and tests — always within the correct lib/ crate.

- **Primary Directories:** `lib/`, `src/`, `/sdk-python`, `/sdk-typescript`, `/sdk-go`, `/examples`, `/scripts`
- **Key Responsibilities:**
- Implement logic in the CORRECT lib crate:
- DB queries → `lib/storage/` (add to `StorageBackend` trait)
- Cedar policy → `lib/policy/`
- Detection/correlation → `lib/soc/`
- Shared types → `lib/api/` (define proto message first, then REST model)
- Utilities → `lib/common/`
- **Every new endpoint MUST be on both REST and gRPC.** REST handler in `src/handlers/`, gRPC impl in `src/grpc/`.
- NEVER put business logic in `src/handlers/` or `src/grpc/`. Both are thin protocol adapters.
- Enforce `tenant_id` bindings on all StorageBackend implementations.
- Write unit tests inside each lib crate (`#[cfg(test)] mod tests`).
- Write gRPC integration tests using `tonic::transport::Channel`.
- **Rules of Conduct:**
- Follow `docs/architecture.md` patterns without exception.
- Use TDD for functional changes.
- Keep gateway local binding to `127.0.0.1` for security testing.
- Parallelize independent DB reads with `tokio::join!` (performance rule).
- Never use `.unwrap()` or `.expect()` in production paths.

---
Defines boundaries, schemas, invariants, migration generations, and documentation.

- **Primary paths:** `/docs`, `/`, `config/`, ADRs, workspace manifests.
- Keep `docs/architecture.md`, `ARCHITECTURE.md`, `docs/LLD.md`, `MIGRATION_MATRIX.md`, `README.md`, `ROADMAP.md`, `CONTRIBUTING.md`, `CLAUDE.md`, and `AGENTS.md` consistent.
- Specify public contracts in protobuf first; specify FlatBuffer, Arrow, eBPF and HCMT ABIs with versions and golden corpora.
- Separate transactional control semantics from append/query event semantics.
- Require migration, shadow comparison, crash recovery and release-artifact rollback for stateful cutovers.
- Run `cargo tree --workspace` for crate-boundary changes.
- Never approve an architecture that weakens fail-closed behavior to meet a latency target.

## 2. DeveloperAgent

Implements services, storage, protocols, SDKs, UI and tests in their owning crates.

- **Primary paths:** `lib/`, `src/`, `bins/`, SDKs, `ui-next/`, future `ui-wasm/`, examples and scripts.
- Existing SQL implementation belongs in `lib/storage/`; new code moves toward focused control/event traits without expanding the god trait unnecessarily.
- Cedar and trust logic belong in `lib/policy/`; no storage/network dependency.
- Wire/domain types belong in API/wire crates, never handlers.
- REST and gRPC call the same typed service directly.
- Bind authenticated `tenant_id` in every storage/index/cache operation.
- Use TDD and add unit, integration, corpus, recovery and performance tests proportional to risk.
- Keep development services on `127.0.0.1` unless deployment work explicitly changes the boundary.
- In transitional v1 code, `tokio::join!` is allowed for independent reads; in v2 hot crates, ownership and reactor rules supersede Tokio optimization patterns.

## 3. SecurityAuditorAgent

### Persona Summary

Threat-models and audits policy, SQL, approval integrity, and workspace structure.

- **Primary Directories:** `lib/policy/`, `lib/storage/`, `policies.cedar`, `/SECURITY.md`
- **Key Responsibilities:**
- Verify SQL parameterization and tenant isolation in `StorageBackend` implementations.
- Review Cedar rules for fail-closed behavior and excessive autonomy controls.
- Verify approval action-hash integrity and callback/signature expectations.
- **Audit dependency graph:** Run `cargo tree --workspace` and verify no upward/circular deps.
- Verify canonicalization byte-equality (`aegis-jcs-1`) across SDK and gateway.
- Review protobuf definitions for sensitive data exposure (no secrets in proto messages).
- **Rules of Conduct:**
- Do not weaken approval hash checks, expiry enforcement, or fail-closed policy behavior.
- Preserve the deterministic trust-provenance rule (classifiers may only tighten).
- Do not introduce unauthenticated administrative routes.
- Flag any `SqlitePool` usage outside of `lib/storage/` — it violates the trait abstraction.

---

## 4. OpsAgent

### Persona Summary

Maintains CI/CD, deployment, and workspace-level build integrity.

- **Primary Directories:** `/.github`, `/docker`, `config/`, `/e2e`, `Cargo.toml` (workspace root)
- **Key Responsibilities:**
- CI MUST run `cargo check/test/fmt/clippy --workspace` (not just a single crate).
- Maintain `config/config.yaml` schema (including `rest_port`, `grpc_port`) and Docker Compose local startup.
- Docker Compose MUST expose both REST (8080) and gRPC (6334) ports.
- E2E Playwright tests in `/e2e` run against REST; gRPC integration tests use `tonic::transport::Channel`.
- Prepare SBOM, image signing, dependency scanning.
- Maintain `deny.toml` for license compliance.
- Ensure `tonic-build` + `protoc` are available in CI docker images.
- **Rules of Conduct:**
- CI should validate the workspace DAG: `cargo tree --workspace` must have no cycles.
- Container startup must keep the gateway on local loopback for MVP demos.
- Each lib crate must compile independently in CI (`cargo check -p aegis-common`, etc.).
Threat-models integrity, isolation, unsafe code, policy, storage, wire formats, eBPF and semantic components.

- **Primary paths:** `lib/policy/`, crypto/canon/control/event/HCMT/guardrail/containment crates, `policies.cedar`, `SECURITY.md`, ADRs.
- Verify SQL parameterization, tenant binding, HCMT tenant ranges and browser field redaction.
- Verify action-hash byte parity, approval expiry/replay, receipt order/signatures/checkpoints and signed control generations.
- Audit unsafe invariants, atomics, epoch lifetime, bounds/overflow, mmap/Arrow/FlatBuffer parsing and eBPF ABI.
- Verify semantic and LLM paths cannot allow, loosen trust, access raw credentials, or silently retrain on attacker data.
- Flag raw pools outside storage implementations and any handler business logic.
- Require cross-tenant fuzzing, Miri/Loom/sanitizers, corrupt-input tests and fail-closed overload behavior.

## 4. PerformanceAgent

Owns mechanical-sympathy evidence and guards against benchmark theater.

- **Primary paths:** `benches/`, reactor/event/HCMT/query/guardrail crates, `ui-wasm/`, UI render kernel, performance docs and CI.
- Record hardware, kernel, NUMA, cpusets, IRQs, frequency, NIC/disk/filesystem and build flags.
- Report p50/p95/p99/p99.9 with coordinated-omission correction, saturation and errors.
- Measure cycles, allocations, copied bytes, context switches, migrations, cache/branch/NUMA misses, WAL sync, compression and write amplification.
- Compare systems only with equal durability, replication, retention, schema and loss policy.
- Keep authorization compute separate from protected commit and end-to-end network latency.
- A missed target is a result, not permission to weaken integrity or hide data.

## 5. OpsAgent

Maintains CI/CD, deployment qualification, supply chain, recovery and runtime topology.

- **Primary paths:** `.github/`, Docker/Compose, Helm, `config/`, `e2e/`, root `Cargo.toml`, system deployment files.
- CI runs workspace check/test/fmt/clippy and per-crate compile checks.
- Keep `protoc`, FlatBuffer compiler, Arrow/WASM, eBPF toolchains and kernel test images versioned as their phases land.
- Expose REST `8080` and gRPC `6334` for compatibility; isolate target data/query services per deployment ADR.
- Qualified deployments enforce CPU Manager/cpusets, non-overlapping core roles, NUMA topology, IRQ policy, resource reserves and capability checks.
- Add SBOM, signing, dependency/license/advisory scanning and reproducible artifacts.
- Exercise backup, restore, WAL/manifest recovery, node failure, disk full and release-artifact rollback.
- Never label polling fallback as eBPF-equivalent containment or developer profile as performance-qualified.
Loading
Loading