60 lines
2.5 KiB
Rust
60 lines
2.5 KiB
Rust
//! Review prompt composition: building the system prompt for the
|
|||
|
|
//! quality-review subagent, embedding git diff, chat history, and
|
||
|
|
//! build/test probe results.
|
||
|
|
|
||
|
|
use crate::app::state::rest::AppStateRest;
|
||
|
|
|
||
|
|
/// Number of days without update after which a memory is flagged as stale.
|
||
|
|
pub(crate) const STALE_AFTER_DAYS: i64 = 60;
|
||
|
|
|
||
|
|
/// Compose the system prompt for the quality-review subagent.
|
||
|
|
pub(crate) fn compose_review_prompt(state: &AppStateRest, probe_note: &str) -> String {
|
||
|
|
let diff_output = if let Some(workspace) = state.workspace_roots.first() {
|
||
|
|
std::process::Command::new("git")
|
||
|
|
.arg("diff")
|
||
|
|
.arg("HEAD")
|
||
|
|
.current_dir(workspace)
|
||
|
|
.output()
|
||
|
|
.ok()
|
||
|
|
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
|
||
|
|
.unwrap_or_default()
|
||
|
|
} else {
|
||
|
|
String::new()
|
||
|
|
};
|
||
|
|
|
||
|
|
let history_output = if let Some(rt) = &state.session_runtime {
|
||
|
|
let msgs: Vec<String> = rt
|
||
|
|
.messages
|
||
|
|
.iter()
|
||
|
|
.filter(|m| {
|
||
|
|
m.role == crate::dto::chat::message::Role::Assistant
|
||
|
|
|| m.role == crate::dto::chat::message::Role::User
|
||
|
|
})
|
||
|
|
.rev()
|
||
|
|
.take(10)
|
||
|
|
.map(|m| format!("{:?}: {}", m.role, m.content.as_deref().unwrap_or("")))
|
||
|
|
.collect();
|
||
|
|
let mut rev_msgs = msgs;
|
||
|
|
rev_msgs.reverse();
|
||
|
|
rev_msgs.join("\n\n")
|
||
|
|
} else {
|
||
|
|
String::new()
|
||
|
|
};
|
||
|
|
|
||
|
|
let session_dir_disp = state.session_dir.display();
|
||
|
|
format!(
|
||
|
|
"You are a code quality reviewer and lesson generator. Your goal is to review recent code changes.\n\n\
|
||
|
|
Session directory: {session_dir_disp}\n\n\
|
||
|
|
--- Build/Test Probe ---\n{probe_note}\n\n\
|
||
|
|
--- Recent Chat History (Last 10 messages) ---\n{history_output}\n\n\
|
||
|
|
--- Recent Code Diffs (git diff HEAD) ---\n{diff_output}\n\n\
|
||
|
|
INSTRUCTIONS:\n\
|
||
|
|
1. Compare the 'Recent Chat History' (what the AI promised or discussed) with the 'Recent Code Diffs' (what was actually changed).\n\
|
||
|
|
2. Ensure that the AI's promises match the actual code changes.\n\
|
||
|
|
3. Evaluate the code quality in the diff (check for best practices, clean code).\n\
|
||
|
|
4. Write your findings and learning points as a lesson to a file in `docs/lesson/` (e.g., docs/lesson/lesson_01.md).\n\
|
||
|
|
5. Use the `write` tool to save this markdown file.\n\
|
||
|
|
6. Your verdict should briefly summarize what lesson was created.",
|
||
|
|
)
|
||
|
|
}
|