# core/context — AGENTS.md

## Purpose

Context synthesis, compression, and token budgeting: assembles a `ContextPack` from layered `ContextEntry` records, applies compression strategies to fit token budgets, and tracks context state via the standard event-sourcing stack.

## Ownership

CORREX kernel team.

## Local Contracts

- `ContextPack` / `ContextPackBuilder` (`DefaultContextPackBuilder`) — assembles ordered context entries for an inference call.
- `ContextEntry` — single context item with a `ContextLayer` ordinal for ordering.
- `ContextLayer` — enum defining layer priority (system, L0–L3, etc.). All SYSTEM-role entries fold into the leading system message; non-system entries order by `ContextEntry.ordinal`.
- `ContextCompressor` (`DefaultContextCompressor`) — applies `CompressionStrategy` to reduce context size within `TokenBudget`.
- `CompressionMetadata` — records what was compressed and why (non-authoritative; does not replace original events — Hard Invariant #6).
- `ContextState` rebuilt from events via `DefaultContextReducer` + `ContextProjector`.
- `DefaultContextRepository` wraps `EventReplayer<ContextState>`.
- `DecisionPointBuilder` — constructs context snapshots at decision boundaries.
- `ContextSerializationModule` — registers context types for serialization.

## Work Guidance

- Follow the standard Events→State→Reducer→Projector→Repository pattern (see `core/AGENTS.md`).
- Compression output is informational only (Hard Invariant #6). Never replace event-sourced context with a compressed snapshot.
- `DefaultContextReducer` only does `state.copy(...)`.

## Verification

```bash
./gradlew :core:context:test --rerun-tasks
```

Tests in `testing/projections/` (ContextProjectorTest, DefaultContextReducerTest, DefaultContextPackBuilderTest) and `testing/deterministic/` (ContextCompressionDeterminismTest, PromptRendererOrderingTest).

## Child DOX Index

No child AGENTS.md (leaf module).
