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::reasoning;
29pub use core::retention;
30pub use core::session;
31pub use core::session_catalog;
32pub use core::session_journal;
33pub use core::session_lock;
34
35/// The release that removed `synaps agent`, `synaps watcher` and `synaps
36/// server`. The one-release CLI stubs and the warnings for their config keys
37/// name it.
38pub const REMOVED_IN: &str = "0.12.0";
39
40/// The release that removed the built-in Axel memory backend and built-in
41/// automatic memory. Separate from [`REMOVED_IN`]: that one moves when the
42/// command stubs go, this removal must not move with it.
43pub const AXEL_BACKEND_REMOVED_IN: &str = "0.12.0";
44
45/// The release that removed the plugin sidecar system (`provides.sidecar`,
46/// `/sidecar`, `sidecar_toggle_key`).
47pub const SIDECAR_REMOVED_IN: &str = "0.12.0";
48
49/// Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
50#[inline]
51pub fn epoch_millis() -> u64 {
52    std::time::SystemTime::now()
53        .duration_since(std::time::UNIX_EPOCH)
54        .expect("system clock before Unix epoch")
55        .as_millis() as u64
56}
57
58// Expose Result + RuntimeError at crate root so `crate::Result<T>` resolves
59// inside agent-core modules (mirrors root lib.rs lines 28-29).
60pub use error::{Result, RuntimeError};
61
62/// Truncate a string to at most `max` bytes at a valid UTF-8 boundary.
63#[inline]
64pub fn truncate_str(s: &str, max: usize) -> &str {
65    if s.len() <= max {
66        return s;
67    }
68    let mut end = max;
69    while end > 0 && !s.is_char_boundary(end) {
70        end -= 1;
71    }
72    &s[..end]
73}
74
75pub mod orchestration;
76pub mod prompt;
77pub mod text;
78
79pub use text::BoundedText;
80
81#[path = "core/context_archive.rs"]
82pub mod context_archive;