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