依存レイヤー
src/ は六つの layer (L0–L5) に分かれています。dependencies は upward only です。higher layer から lower layer への import は許可されず、review と architecture checks で捕まえます。
| Layer | Modules | Role |
|---|---|---|
| L0 | contracts/, config/, utils/ | Cross-boundary types, IDs, TOML schema |
| L1 | core/memory/, core/persona/, core/providers/, core/sessions/, core/subagents/, core/experience/, core/eval/ | Durable state, identity, provider abstraction, shared runtime domain |
| L2 | core/tools/, security/ | Tool system, approval, policy, taint, governance |
| L3 | core/agent/, core/affect/, media/ | Turn executor, affect detection, multimodal processing |
| L4 | runtime/services/, runtime/diagnostics/, runtime/observability/ | Composition root, DI, telemetry |
| L5 | transport/, cli/, platform/, plugins/, ui/, onboard/ | Gateway, channels, CLI, desktop plugins |
Layering が守るもの
Section titled “Layering が守るもの”layering が守る property は一つです。continuity state (L1) は、それを読んでいる surface を知らない。
- Memory、persona、sessions は
transport/やcli/を import しません。Discord message の形や HTTP request の形に accidental coupling しません。 - Core agent logic (L3) は security / tool layer (L2) を飛び越えて channel と直接話しません。
- Transports (L5) は、新しい channel、desktop panel、新しい gateway route などに変わっても、それが表示する state を触らずに変えられます。
この barrier が porous だと、runtime は一回の refactor で Discord-shaped memory や gateway-flavored persona に近づきます。layering は shared turn pipeline を honest に保つための仕組みです。
Composition root
Section titled “Composition root”すべては src/runtime/services/ で wire されます。この module は次を行います。
- auth、security policy、memory、rate limiter を初期化する
- provider を build する。provider は reliability と OAuth recovery layers で wrap される
- tool registry を assemble する
- every tool call に渡す
ExecutionContextを construct する
composition root はすべての pieces を同時に知る唯一の場所です。他の module は narrow slice だけを見ます。
Key trait surfaces
Section titled “Key trait surfaces”module boundaries で特に重要なのは三つの traits です。
Memory—MemoryWriter(append_event)、MemoryReader(recall_scoped,resolve_slot)、MemoryGovernance(health_check,forget_slot) を合わせた supertrait。backends は PostgreSQL (default) または Markdown fallback。Tool—name()、description()、parameters_schema()、execute(args, ctx)。core/tools/registry.rsに registered。Provider— required method はchat_with_system()。ReliableProvider(retry + circuit-breaker) とOAuthRecoveryProviderで wrap される。implementations は Anthropic、OpenAI、OpenRouter、Ollama、Gemini。
この三つは cross-layer communication の主要 contract です。変更を trace していてここに辿り着いたなら、正しい境界を見ています。
Experimental code
Section titled “Experimental code”experimental または retired code は、active module tree から export され architecture checks で守られていない限り、production layering contract の一部ではありません。現在の companion runtime は上の layers が所有します。古い planner、simulation、evolution surfaces は product-bearing entrypoints ではありません。