Skip to main content

agent_core/
lib.rs

1//! `agent-core` — foundational types, config, session, auth, logging,
2//! protocol, memory, and pricing. Leaf crate: no in-repo upward deps.
3
4pub mod core;
5pub mod memory;
6pub mod pricing;
7
8// Re-export stream event types at crate root so engine/tui can import them
9// cleanly as `agent_core::{StreamEvent, LlmEvent, ...}` without digging
10// into the internal module path.
11pub use core::stream_types::{
12    next_turn_correlation_id, AgentEvent, BudgetDimension, LlmEvent, SessionEvent, SharedMessage,
13    StreamEvent, TurnError, TurnOutcome,
14};
15
16// Replicate the root lib.rs aliases so internal `crate::config`,
17// `crate::models`, `crate::session`, etc. resolve INSIDE agent-core.
18pub use core::auth;
19pub use core::chain;
20pub use core::compaction;
21pub use core::config;
22pub use core::disclosure;
23pub use core::error;
24pub use core::logging;
25pub use core::models;
26pub use core::private_fs;
27pub use core::protocol;
28pub use core::reasoning;
29pub use core::retention;
30pub use core::session;
31pub use core::session_journal;
32pub use core::session_lock;
33pub use core::watcher_types;
34
35/// Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
36#[inline]
37pub fn epoch_millis() -> u64 {
38    std::time::SystemTime::now()
39        .duration_since(std::time::UNIX_EPOCH)
40        .expect("system clock before Unix epoch")
41        .as_millis() as u64
42}
43
44// Expose Result + RuntimeError at crate root so `crate::Result<T>` resolves
45// inside agent-core modules (mirrors root lib.rs lines 28-29).
46pub use error::{Result, RuntimeError};
47
48/// Truncate a string to at most `max` bytes at a valid UTF-8 boundary.
49#[inline]
50pub fn truncate_str(s: &str, max: usize) -> &str {
51    if s.len() <= max {
52        return s;
53    }
54    let mut end = max;
55    while end > 0 && !s.is_char_boundary(end) {
56        end -= 1;
57    }
58    &s[..end]
59}
60
61pub mod orchestration;
62pub mod prompt;
63pub mod text;
64
65pub use text::BoundedText;
66
67#[path = "core/context_archive.rs"]
68pub mod context_archive;