huskies: merge 572_story_edit_criterion_mcp_tool_to_update_acceptance_criteria_text

This commit is contained in:
dave
2026-04-15 12:59:49 +00:00
parent 52b21c22b1
commit ec40b4771b
4 changed files with 109 additions and 4 deletions
+58
View File
@@ -126,6 +126,64 @@ pub fn check_criterion_in_file(
Ok(())
}
/// Edit the text of an existing acceptance criterion without changing its checked state.
///
/// Finds the criterion at `criterion_index` (0-based, counting all criteria regardless
/// of checked state) and replaces its text with `new_text`.
pub fn edit_criterion_in_file(
project_root: &Path,
story_id: &str,
criterion_index: usize,
new_text: &str,
) -> Result<(), String> {
let contents = read_story_content(project_root, story_id)?;
let mut count: usize = 0;
let mut found = false;
let new_lines: Vec<String> = contents
.lines()
.map(|line| {
let trimmed = line.trim();
let prefix = if trimmed.starts_with("- [ ] ") {
Some("- [ ] ")
} else if trimmed.starts_with("- [x] ") {
Some("- [x] ")
} else {
None
};
if let Some(p) = prefix {
if count == criterion_index {
count += 1;
found = true;
let indent_len = line.len() - trimmed.len();
let indent = &line[..indent_len];
return format!("{indent}{p}{new_text}");
}
count += 1;
}
line.to_string()
})
.collect();
if !found {
return Err(format!(
"Criterion index {criterion_index} out of range. Story '{story_id}' has \
{count} criteria (indices 0..{}).",
count.saturating_sub(1)
));
}
let mut new_str = new_lines.join("\n");
if contents.ends_with('\n') {
new_str.push('\n');
}
let stage = story_stage(story_id).unwrap_or_else(|| "2_current".to_string());
write_story_content(project_root, story_id, &stage, &new_str);
Ok(())
}
/// Add a new acceptance criterion to a story.
///
/// Appends `- [ ] {criterion}` after the last existing criterion line in the