summaryrefslogtreecommitdiff
path: root/makima/src/orchestration/directive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/orchestration/directive.rs')
-rw-r--r--makima/src/orchestration/directive.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs
index eb157a3..21053f3 100644
--- a/makima/src/orchestration/directive.rs
+++ b/makima/src/orchestration/directive.rs
@@ -1551,6 +1551,79 @@ IMPORTANT: You MUST run `makima directive update` with either `--pr-url` or `--s
)
}
+/// Build a prompt for cleaning up completed steps that have been merged into the PR branch.
+///
+/// The prompt instructs the Claude instance to verify which step branches are
+/// merged and remove merged steps, leaving unmerged steps alone.
+pub fn build_cleanup_prompt(
+ directive: &crate::db::models::Directive,
+ step_tasks: &[crate::db::repository::CompletedStepTask],
+ pr_branch: &str,
+ base_branch: &str,
+) -> String {
+ let step_list: String = step_tasks
+ .iter()
+ .map(|st| {
+ let branch = format!(
+ "makima/{}-{}",
+ crate::daemon::worktree::sanitize_name(&st.task_name),
+ crate::daemon::worktree::short_uuid(st.task_id),
+ );
+ format!("- Step ID: {}, Name: \"{}\", Branch: {}", st.step_id, st.step_name, branch)
+ })
+ .collect::<Vec<_>>()
+ .join("\n");
+
+ let pr_url_line = match &directive.pr_url {
+ Some(url) => format!("PR URL: {}", url),
+ None => String::new(),
+ };
+
+ format!(
+ r#"You are cleaning up completed steps for directive "{title}".
+
+The directive has a PR branch: {pr_branch}
+Base branch: {base_branch}
+{pr_url_line}
+
+Completed steps to verify:
+{step_list}
+
+## Instructions
+
+1. First, fetch the latest remote state:
+```bash
+git fetch origin
+```
+
+2. Check which branches have been merged into the PR branch:
+```bash
+git branch -r --merged origin/{pr_branch}
+```
+
+3. For each completed step listed above, check if its branch appears in the merged list.
+
+4. For steps whose branches ARE merged:
+ - Remove the step (this also cleans up associated data):
+```bash
+makima directive remove-step <step_id>
+```
+
+5. For steps whose branches are NOT merged into the PR branch:
+ - Do NOT remove them. Leave them for the next PR cycle.
+ - Report them as skipped.
+
+6. After processing all steps, report a summary of what was cleaned up and what was left.
+
+IMPORTANT: Only remove steps whose task branches have been verified as merged. Never remove unmerged steps."#,
+ title = directive.title,
+ pr_branch = pr_branch,
+ base_branch = base_branch,
+ pr_url_line = pr_url_line,
+ step_list = step_list,
+ )
+}
+
/// Build a specialized planning prompt for picking up open orders.
///
/// This prompt instructs the planner to evaluate available orders, select an