huskies: merge 572_story_edit_criterion_mcp_tool_to_update_acceptance_criteria_text
This commit is contained in:
@@ -7,7 +7,8 @@ pub use bug_ops::{
|
||||
create_bug_file, create_refactor_file, create_spike_file, list_bug_files, list_refactor_files,
|
||||
};
|
||||
pub use story_ops::{
|
||||
add_criterion_to_file, check_criterion_in_file, create_story_file, update_story_in_file,
|
||||
add_criterion_to_file, check_criterion_in_file, create_story_file, edit_criterion_in_file,
|
||||
update_story_in_file,
|
||||
};
|
||||
pub use test_results::{
|
||||
read_test_results_from_story_file, write_coverage_baseline_to_story_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
|
||||
|
||||
Reference in New Issue
Block a user