session_core/
review_command.rs1pub fn review_prompt(args: &str) -> String {
11 let trimmed = jsrt::string::trim(args);
12 let literal = serde_json::to_string(trimmed).unwrap_or_else(|_| "\"\"".into());
14 let mut lines = vec![
15 if trimmed.is_empty() {
16 "/review".to_string()
17 } else {
18 format!("/review {trimmed}")
19 },
20 String::new(),
21 "Run Ultron's built-in code review in one REPL cell, exactly:".into(),
22 String::new(),
23 "import review_api".into(),
24 format!("review = await review_api.run(rlm, {literal})"),
25 "print(review.report)".into(),
26 String::new(),
27 "Then reply with the printed report as it is. Do not review the code yourself, edit files, or run the review again unless the cell raised an error.".into(),
28 ];
29 if posts(trimmed) {
30 lines.push(String::new());
31 lines.push("If the report says a post is pending, ask me whether to post it to the pull request. Post only after I answer yes in a later message, with `await review_api.post(review, confirm=True)`; without that answer, never post.".into());
32 }
33 lines.join("\n")
34}
35
36fn posts(args: &str) -> bool {
38 args.match_indices("--post").any(|(at, flag)| {
39 let before = args[..at].chars().next_back();
40 let after = args[at + flag.len()..].chars().next();
41 before.is_none_or(jsrt::string::is_space) && after.is_none_or(|c| jsrt::string::is_space(c) || c == '=')
42 })
43}
44
45pub fn expand_review_command(text: &str) -> String {
48 let Some(rest) = jsrt::string::trim(text).strip_prefix("/review") else {
49 return text.to_string();
50 };
51 if rest.is_empty() {
52 return review_prompt("");
53 }
54 if rest.starts_with(jsrt::string::is_space) {
55 return review_prompt(rest);
56 }
57 text.to_string()
58}