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_catalog;
32pub use core::session_journal;
33pub use core::session_lock;
34pub use core::watcher_types;
35
36/// Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
37#[inline]
38pub fn epoch_millis() -> u64 {
39    std::time::SystemTime::now()
40        .duration_since(std::time::UNIX_EPOCH)
41        .expect("system clock before Unix epoch")
42        .as_millis() as u64
43}
44
45// Expose Result + RuntimeError at crate root so `crate::Result<T>` resolves
46// inside agent-core modules (mirrors root lib.rs lines 28-29).
47pub use error::{Result, RuntimeError};
48
49/// Truncate a string to at most `max` bytes at a valid UTF-8 boundary.
50#[inline]
51pub fn truncate_str(s: &str, max: usize) -> &str {
52    if s.len() <= max {
53        return s;
54    }
55    let mut end = max;
56    while end > 0 && !s.is_char_boundary(end) {
57        end -= 1;
58    }
59    &s[..end]
60}
61
62pub mod orchestration;
63pub mod prompt;
64pub mod text;
65
66pub use text::BoundedText;
67
68#[path = "core/context_archive.rs"]
69pub mod context_archive;