Heuristic:1ay1 Agentty Purity Contract
| Knowledge Sources | |
|---|---|
| Domains | Architecture, Functional_Programming |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Domain types and value objects are pure data — no side effects, no IO, no hidden state — so they can be copied, compared, and tested without any environment setup.
Description
The Purity_Contract heuristic requires that domain-layer types (value objects, configuration structs, preference knobs, snapshots) are plain data with no side effects. They have no constructors that touch the filesystem, no methods that perform IO, no mutable global state. This makes them trivially testable, serializable, and safe to share across threads. The contract is enforced structurally: if a type needs IO, it lives in a different layer (runtime or io), not in the domain.
In agentty this appears in: web search policy config (`web_search_config.hpp`) as a pure data struct; auth view value type (`auth_view.hpp`) as a read-only projection; appearance preference knobs (`ui_prefs.hpp`) as plain serializable data; paste config (`paste_config.hpp`) as a value with no IO; and the scope resolution algebra (`scope.hpp`) as a pure function over config data.
= Usage
Apply this heuristic when designing domain or value types. If a type's constructor or method touches the filesystem, network, or global state, move that logic to a different layer and keep the domain type as pure data. The test: can you construct and use this type in a unit test with no filesystem, no network, and no mocks?
The Insight (Rule of Thumb)
- Action: Keep domain types as pure data; push all IO and side effects to the runtime or io layer.
- Value: No constructors that touch files, no methods that perform IO, no hidden mutable state.
- Trade-off: Requires a clean layer separation; domain types cannot "helpfully" load themselves from disk.
- Compatibility: Pairs with Heuristic:1ay1_Agentty_Effects_As_Values — IO is returned as effect descriptions, not performed inline.
Reasoning
A domain type that performs IO in its constructor is impossible to unit-test without a filesystem. A domain type that mutates global state is impossible to reason about in a multi-threaded context. By keeping domain types pure, the entire domain layer becomes a library of pure functions over plain data — testable in isolation, deterministic in behavior, and safe to share. The IO happens at the edges (runtime layer), where it can be controlled, mocked, and audited.
Related Pages
- Implementation:1ay1_Agentty_Web_Search_Policy_Config
- Implementation:1ay1_Agentty_Slash_Command_Catalog
- Implementation:1ay1_Agentty_Auth_View_Value_Type
- Implementation:1ay1_Agentty_Scope_Resolution_Algebra
- Implementation:1ay1_Agentty_Published_Appearance_Prefs
- Implementation:1ay1_Agentty_Paste_Config
- Implementation:1ay1_Agentty_PowerShell_Command_Encoder
- Implementation:1ay1_Agentty_Plugin_State_Snapshot
- Implementation:1ay1_Agentty_Persistence_As_Effects
- Implementation:1ay1_Agentty_Installed_Library_Value