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