use crate::commands::recall::{RecallArgs, handle_recall};
use crate::commands::util::exit_code;
use crate::runtime::CommandContext;
use crate::style::{self, sym};
const DEFAULT_TOP_K: usize = 5;
pub(crate) async fn handle_ask(
ctx: &CommandContext,
query: String,
file: Option<String>,
json: bool,
) {
let query = query.trim().to_owned();
if query.is_empty() {
eprintln!(
"{} `difflore ask` needs a question — try `difflore ask \"why do we ban unwrap?\"`",
style::err(sym::ERR),
);
exit_code(2);
}
handle_recall(
ctx,
RecallArgs {
intent: Some(query),
file,
diff: false,
top_k: DEFAULT_TOP_K,
json,
verbose: false,
copy: false,
},
)
.await;
if !json {
let client = ctx.cloud().await;
let (message, command) = if client.is_logged_in() {
(
"For fresher answers, sync team memory first",
"difflore cloud sync",
)
} else {
(
"For team memory, sign in to Cloud first",
"difflore cloud login",
)
};
println!(
" {} {message}: {}",
style::pewter(sym::BULLET),
style::cmd(command),
);
}
}