1use std::fs;
2use std::io::IsTerminal;
3
4use chub_core::config::chub_dir;
5use owo_colors::OwoColorize;
6
7const WELCOME_MARKER: &str = ".welcome_shown";
8
9pub fn show_welcome_if_needed(json: bool) {
11 if json {
12 return;
13 }
14
15 if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() {
17 return;
18 }
19
20 let chub = chub_dir();
21 let marker_path = chub.join(WELCOME_MARKER);
22 let config_path = chub.join("config.yaml");
23
24 if marker_path.exists() {
25 return;
26 }
27
28 eprintln!(
29 "\n{} Chub helps your AI coding agents make API calls correctly, by providing \
30the latest documentation.\n\n\
31By using chub, you agree to the Terms of Service at {}\n\n\
32Chub asks agents to provide feedback on documentation, and this feedback is used to improve docs for the developer \
33community. If you wish to disable this feedback, add {} to {}. See \
34{} for details.\n",
35 "Welcome to Context Hub (chub)!".bold(),
36 "https://www.aichub.org/tos.html".underline(),
37 "\"feedback: false\"".bold(),
38 config_path.display().to_string().bold(),
39 "https://github.com/nrl-ai/chub".underline(),
40 );
41
42 let _ = fs::create_dir_all(&chub);
44 let _ = fs::write(&marker_path, chub_core::util::now_iso8601());
45}