Skip to main content

synaps_cli/
lib.rs

1pub mod core;
2pub mod runtime;
3pub mod tools;
4pub mod mcp;
5pub mod skills;
6pub mod events;
7pub mod extensions;
8pub mod memory;
9pub mod help;
10pub mod sidecar;
11pub mod toast;
12
13// Re-export core modules at crate root for backward compatibility
14pub use core::config;
15pub use core::session;
16pub use core::auth;
17pub use core::logging;
18pub use core::protocol;
19pub use core::error;
20pub use core::watcher_types;
21pub use core::models;
22pub use core::chain;
23
24pub use runtime::{Runtime, StreamEvent, LlmEvent, SessionEvent, AgentEvent};
25pub use tools::{Tool, ToolContext, ToolRegistry};
26pub use session::{Session, SessionInfo, find_session, latest_session, list_sessions, resolve_session, find_session_by_name, validate_name};
27pub use error::{RuntimeError, Result};
28pub use config::{SynapsConfig, load_config, resolve_system_prompt};
29pub use watcher_types::{
30    AgentConfig, SessionLimits, HandoffState, ExitReason, SessionStats,
31    WatcherCommand, WatcherResponse, AgentStatusInfo
32};
33
34// Re-export for convenience
35pub use serde_json::Value;
36pub use tokio_util::sync::CancellationToken;
37
38/// Flush stdout, ignoring errors (pipe closed, etc.)
39#[inline]
40pub fn flush_stdout() {
41    use std::io::Write;
42    let _ = std::io::stdout().flush();
43}
44
45/// Flush stderr, ignoring errors (pipe closed, etc.)
46#[inline]
47pub fn flush_stderr() {
48    use std::io::Write;
49    let _ = std::io::stderr().flush();
50}
51
52/// Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
53#[inline]
54pub fn epoch_millis() -> u64 {
55    std::time::SystemTime::now()
56        .duration_since(std::time::UNIX_EPOCH)
57        .expect("system clock before Unix epoch")
58        .as_millis() as u64
59}
60
61/// Current time as Unix epoch seconds.
62#[inline]
63pub fn epoch_secs() -> u64 {
64    std::time::SystemTime::now()
65        .duration_since(std::time::UNIX_EPOCH)
66        .expect("system clock before Unix epoch")
67        .as_secs()
68}
69
70/// Truncate a string to at most `max` bytes at a valid UTF-8 boundary.
71#[inline]
72pub fn truncate_str(s: &str, max: usize) -> &str {
73    if s.len() <= max {
74        return s;
75    }
76    let mut end = max;
77    while end > 0 && !s.is_char_boundary(end) {
78        end -= 1;
79    }
80    &s[..end]
81}