lean_ctx/setup/
onboard.rs1use super::options::SetupOptions;
2use super::with_options::run_setup_with_options;
3
4pub fn run_onboard() {
12 use crate::terminal_ui;
13
14 let dim = "\x1b[2m";
15 let bold = "\x1b[1m";
16 let cyan = "\x1b[36m";
17 let green = "\x1b[1;32m";
18 let yellow = "\x1b[33m";
19 let rst = "\x1b[0m";
20
21 println!();
22 println!(" {bold}Connecting lean-ctx to your AI tools…{rst}");
23 println!(
24 " {dim}No questions — using recommended defaults. Run `lean-ctx setup` for full control.{rst}"
25 );
26 println!();
27
28 let opts = SetupOptions {
29 non_interactive: true,
30 yes: true,
31 fix: true,
32 ..Default::default()
33 };
34
35 let report = match run_setup_with_options(opts) {
36 Ok(r) => r,
37 Err(e) => {
38 eprintln!(" {yellow}Onboarding could not complete: {e}{rst}");
39 eprintln!(" {dim}Try the guided setup instead: lean-ctx setup{rst}");
40 std::process::exit(1);
41 }
42 };
43
44 let connected: Vec<String> = report
45 .steps
46 .iter()
47 .find(|s| s.name == "editors")
48 .map(|s| {
49 s.items
50 .iter()
51 .filter(|i| matches!(i.status.as_str(), "created" | "updated" | "already"))
52 .map(|i| i.name.clone())
53 .collect()
54 })
55 .unwrap_or_default();
56
57 let data_dir = crate::core::data_dir::lean_ctx_data_dir()
58 .map_or_else(|_| "~/.lean-ctx".to_string(), |p| p.display().to_string());
59
60 println!();
61 if connected.is_empty() {
62 println!(" {yellow}No AI tools detected yet.{rst}");
63 println!(
64 " {dim}Install Cursor, Claude Code, VS Code, etc., then re-run: lean-ctx onboard{rst}"
65 );
66 } else {
67 println!(" {green}✓ lean-ctx is connected.{rst}");
68 println!();
69 println!(" {bold}Connected:{rst} {}", connected.join(", "));
70 }
71 println!(" {dim}Data dir:{rst} {data_dir}");
72
73 let source_cmd = crate::shell_hook::shell_source_command().unwrap_or("Restart your shell");
74 println!();
75 println!(" {bold}One last step:{rst}");
76 println!(" {cyan}1.{rst} Reload your shell: {bold}{source_cmd}{rst}");
77 if !connected.is_empty() {
78 println!(
79 " {cyan}2.{rst} {yellow}Fully restart your AI tool{rst} {dim}(so it reconnects to lean-ctx){rst}"
80 );
81 println!(
82 " {cyan}3.{rst} Ask your AI to read a file — lean-ctx optimizes it automatically."
83 );
84 }
85 println!();
86 println!(
87 " {dim}Check anytime:{rst} {bold}lean-ctx doctor{rst} {dim}·{rst} {bold}lean-ctx gain{rst}"
88 );
89 println!();
90 terminal_ui::print_command_box();
91
92 crate::cli::show_first_run_wow();
93}