use std::fs;
use std::path::PathBuf;
pub const LOOP_MD_BYTE_CAP: usize = 25_000;
pub const BUILT_IN_MAINTENANCE_PROMPT: &str = "\
On each iteration, work through the following in order:
1. Continue any unfinished work from the conversation.
2. Tend to the current branch's pull request: review comments, failed CI \
runs, merge conflicts.
3. If nothing else is pending, run a cleanup pass: bug hunts or \
simplification.
Do not start new initiatives outside that scope. Irreversible actions \
(pushing, deleting, force-push) only proceed when they continue something \
the transcript already authorized.";
pub fn resolve_prompt() -> String {
if let Some(p) = read_capped(PathBuf::from(".claude/loop.md")) {
return p;
}
if let Some(home) = dirs::home_dir() {
if let Some(p) = read_capped(home.join(".claude/loop.md")) {
return p;
}
}
BUILT_IN_MAINTENANCE_PROMPT.to_string()
}
fn read_capped(path: PathBuf) -> Option<String> {
let raw = fs::read_to_string(&path).ok()?;
if raw.len() <= LOOP_MD_BYTE_CAP {
Some(raw)
} else {
Some(raw[..LOOP_MD_BYTE_CAP].to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn built_in_prompt_is_non_empty() {
assert!(!BUILT_IN_MAINTENANCE_PROMPT.is_empty());
assert!(BUILT_IN_MAINTENANCE_PROMPT.contains("Continue"));
}
}