Skip to main content

wisp/
lib.rs

1// Items reachable only through the `testing` harness look dead in default
2// builds; the all-features lint gate still checks dead code for real.
3#![cfg_attr(not(feature = "testing"), allow(dead_code, unused_imports))]
4
5pub mod cli;
6pub mod error;
7pub mod settings;
8
9// The crate's public API is the entry points above plus [`Session`]. The
10// internal module graph opens up only under the `testing` feature, for the
11// integration suite's cohesive harness in [`testing`].
12#[cfg(not(feature = "testing"))]
13mod testing;
14#[cfg(feature = "testing")]
15pub mod testing;
16
17macro_rules! internal_modules {
18    ($($name:ident),* $(,)?) => {
19        $(
20            #[cfg(feature = "testing")]
21            pub mod $name;
22            #[cfg(not(feature = "testing"))]
23            mod $name;
24        )*
25    };
26}
27
28internal_modules!(
29    app,
30    attachment,
31    conversation,
32    command,
33    file_index,
34    git_review,
35    renderer,
36    request,
37    runtime,
38    screens,
39    session,
40    surfaces,
41    theme,
42    view,
43);
44
45pub use session::Session;
46
47use app::App;
48use error::AppError;
49use renderer::Renderer;
50use settings::UiSettings;
51use std::fs::create_dir_all;
52use tracing_appender::rolling::daily;
53use tracing_subscriber::EnvFilter;
54
55/// Launch the Wisp TUI with the given agent subprocess command.
56pub async fn run_tui(agent_command: &str, settings: UiSettings, log_dir: Option<&str>) -> Result<(), AppError> {
57    setup_logging(log_dir);
58    let session = Session::connect(agent_command).await?;
59    run_with_session(session, settings).await
60}
61
62/// Run the TUI from an already-initialized ACP session.
63pub async fn run_with_session(session: Session, settings: UiSettings) -> Result<(), AppError> {
64    let (app, event_rx, client_handle) = App::from_session(session, settings);
65    runtime::run(app, Renderer::new(), event_rx, client_handle).await
66}
67
68fn setup_logging(log_dir: Option<&str>) {
69    let dir = log_dir.unwrap_or(DEFAULT_LOG_DIR);
70    create_dir_all(dir).ok();
71    let _ = tracing_subscriber::fmt()
72        .with_writer(daily(dir, "wisp.log"))
73        .with_ansi(false)
74        .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
75        .try_init();
76}
77
78pub const DEFAULT_LOG_DIR: &str = "/tmp/wisp-logs";