zeph_agent_context/lib.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4// The graph-retrieval-strategy dispatch in `helpers::fetch_graph_facts` chains several
5// nested async fns (`run_graph_strategy`, `run_synapse_strategy`, `run_hybrid_strategy`, ...),
6// which pushes the compiler's Future-layout query depth beyond the default limit of 128
7// under the `postgres` feature's larger `DbPool`/`DbTransaction` types.
8#![recursion_limit = "256"]
9
10//! Agent context-assembly service for Zeph.
11//!
12//! This crate provides [`service::ContextService`] — a stateless façade for all
13//! context-assembly operations that were previously implemented directly on `Agent<C>`
14//! in `zeph-core`. Extracting this logic means that editing context-assembly code does
15//! not trigger recompilation of the tool dispatcher (`zeph-agent-tools`) or the
16//! persistence layer (`zeph-agent-persistence`).
17//!
18//! # Architecture
19//!
20//! `zeph-agent-context` depends on `zeph-memory`, `zeph-llm`, `zeph-context`,
21//! `zeph-config`, `zeph-common`, `zeph-skills`, and `zeph-sanitizer`. It does **not**
22//! depend on `zeph-core` — this is the core invariant that keeps context-assembly
23//! changes from triggering full workspace rebuilds.
24//!
25//! `zeph-core` depends on this crate and constructs narrow borrow-lens views
26//! ([`state::MessageWindowView`], [`state::ContextAssemblyView`],
27//! [`state::ContextSummarizationView`]) from `Agent<C>` field projections, then
28//! delegates to `ContextService`.
29//!
30//! # Features
31//!
32//! - `index` — enables `zeph-index` integration via the `IndexAccess` trait.
33
34pub mod compaction;
35pub mod error;
36pub mod helpers;
37pub mod memory_backend;
38pub mod retrieved;
39pub mod service;
40pub mod state;
41pub mod summarization;
42
43pub use compaction::{
44 BlockScore, ContentDensity, SubgoalExtractionResult, SubgoalId, SubgoalRegistry, SubgoalState,
45 classify_density, extract_scorable_text, partition_by_density, run_focus_auto_consolidation,
46 score_blocks_mig, score_blocks_subgoal, score_blocks_subgoal_mig, score_blocks_task_aware,
47};
48pub use error::ContextError;
49pub use helpers::BudgetHint;
50pub use service::{ContextService, SemanticRecallParams};
51pub use state::{
52 CompactionOutcome, CompactionPersistence, CompactionProbeCallback, ContextAssemblyView,
53 ContextDelta, ContextSummarizationView, MessageWindowView, MetricsCallback, MetricsCounters,
54 ProbeOutcome, ProviderHandles, QdrantPersistFuture, SecurityEventSink, StatusSink,
55 ToolOutputArchive, TrustGate,
56};
57
58pub use retrieved::{RetrievedContext, collect_retrieved_context};