huskies: merge 520_story_typed_pipeline_state_machine_in_rust_foundation_replaces_stringly_typed_crdt_views_with_strict_enums_subsumes_436

This commit is contained in:
dave
2026-04-09 21:24:11 +00:00
parent 1d9287389a
commit 84717b04bd
18 changed files with 1569 additions and 122 deletions
+1 -1
View File
@@ -1461,7 +1461,7 @@ mod tests {
assert!(names.contains(&"git_log"));
assert!(names.contains(&"status"));
assert!(names.contains(&"loc_file"));
assert_eq!(tools.len(), 57);
assert_eq!(tools.len(), 58);
}
#[test]
+5 -3
View File
@@ -376,8 +376,10 @@ pub(super) fn tool_update_story(args: &Value, ctx: &AppContext) -> Result<String
update_story_in_file(&root, story_id, user_story, description, front_matter_opt)?;
// Bug 503: warn if any depends_on in the (now updated) story points at an archived story.
let stage = crate::crdt_state::read_item(story_id)
.map(|i| i.stage)
let stage = crate::pipeline_state::read_typed(story_id)
.ok()
.flatten()
.map(|i| i.stage.dir_name().to_string())
.unwrap_or_else(|| "1_backlog".to_string());
let archived_deps = check_archived_deps(&root, &stage, story_id);
if !archived_deps.is_empty() {
@@ -525,7 +527,7 @@ pub(super) async fn tool_delete_story(args: &Value, ctx: &AppContext) -> Result<
// 4. Delete from database content store and CRDT.
let found_in_db = crate::db::read_content(story_id).is_some()
|| crate::crdt_state::read_item(story_id).is_some();
|| crate::pipeline_state::read_typed(story_id).ok().flatten().is_some();
crate::db::delete_item(story_id);
+27 -29
View File
@@ -202,21 +202,20 @@ pub fn list_bug_files(root: &Path) -> Result<Vec<(String, String)>, String> {
let mut bugs = Vec::new();
let mut seen = std::collections::HashSet::new();
// First: CRDT items in backlog that are bugs.
if let Some(items) = crate::crdt_state::read_all_items() {
for item in items {
if item.stage != "1_backlog" || !is_bug_item(&item.story_id) {
continue;
}
let name = item.name.clone()
.or_else(|| {
crate::db::read_content(&item.story_id)
.and_then(|c| extract_bug_name_from_content(&c))
})
.unwrap_or_else(|| item.story_id.clone());
seen.insert(item.story_id.clone());
bugs.push((item.story_id, name));
// First: typed projection items in backlog that are bugs.
for item in crate::pipeline_state::read_all_typed() {
if !matches!(item.stage, crate::pipeline_state::Stage::Backlog) || !is_bug_item(&item.story_id.0) {
continue;
}
let sid = item.story_id.0;
let name = if item.name.is_empty() { None } else { Some(item.name) }
.or_else(|| {
crate::db::read_content(&sid)
.and_then(|c| extract_bug_name_from_content(&c))
})
.unwrap_or_else(|| sid.clone());
seen.insert(sid.clone());
bugs.push((sid, name));
}
// Then: filesystem fallback.
@@ -267,22 +266,21 @@ pub fn list_refactor_files(root: &Path) -> Result<Vec<(String, String)>, String>
let mut refactors = Vec::new();
let mut seen = std::collections::HashSet::new();
// First: CRDT items.
if let Some(items) = crate::crdt_state::read_all_items() {
for item in items {
if item.stage != "1_backlog" || !is_refactor_item(&item.story_id) {
continue;
}
let name = item.name.clone()
.or_else(|| {
crate::db::read_content(&item.story_id)
.and_then(|c| parse_front_matter(&c).ok())
.and_then(|m| m.name)
})
.unwrap_or_else(|| item.story_id.clone());
seen.insert(item.story_id.clone());
refactors.push((item.story_id, name));
// First: typed projection items.
for item in crate::pipeline_state::read_all_typed() {
if !matches!(item.stage, crate::pipeline_state::Stage::Backlog) || !is_refactor_item(&item.story_id.0) {
continue;
}
let sid = item.story_id.0;
let name = if item.name.is_empty() { None } else { Some(item.name) }
.or_else(|| {
crate::db::read_content(&sid)
.and_then(|c| parse_front_matter(&c).ok())
.and_then(|m| m.name)
})
.unwrap_or_else(|| sid.clone());
seen.insert(sid.clone());
refactors.push((sid, name));
}
// Then: filesystem fallback.
+90 -35
View File
@@ -79,8 +79,11 @@ pub struct PipelineState {
pub fn load_pipeline_state(ctx: &AppContext) -> Result<PipelineState, String> {
let agent_map = build_active_agent_map(ctx);
// Try CRDT-first read.
if let Some(crdt_items) = crate::crdt_state::read_all_items() {
// Try CRDT-first read via the typed projection layer.
let typed_items = crate::pipeline_state::read_all_typed();
if !typed_items.is_empty() {
use crate::pipeline_state::Stage;
let mut state = PipelineState {
backlog: Vec::new(),
current: Vec::new(),
@@ -89,11 +92,12 @@ pub fn load_pipeline_state(ctx: &AppContext) -> Result<PipelineState, String> {
done: Vec::new(),
};
for item in crdt_items {
let agent = agent_map.get(&item.story_id).cloned();
for item in typed_items {
let sid = &item.story_id.0;
let agent = agent_map.get(sid).cloned();
// Enrich with content-derived metadata (merge_failure, review_hold, qa).
let (merge_failure, review_hold, qa) = crate::db::read_content(&item.story_id)
let (merge_failure, review_hold, qa) = crate::db::read_content(sid)
.and_then(|c| parse_front_matter(&c).ok())
.map(|meta| {
(
@@ -105,24 +109,45 @@ pub fn load_pipeline_state(ctx: &AppContext) -> Result<PipelineState, String> {
.unwrap_or((None, None, None));
let story = UpcomingStory {
story_id: item.story_id,
name: item.name,
story_id: sid.clone(),
name: if item.name.is_empty() {
None
} else {
Some(item.name.clone())
},
error: None,
merge_failure,
agent,
review_hold,
qa,
retry_count: item.retry_count.map(|r| r as u32),
blocked: item.blocked,
depends_on: item.depends_on,
retry_count: if item.retry_count > 0 {
Some(item.retry_count)
} else {
None
},
blocked: if item.stage.is_blocked() {
Some(true)
} else {
None
},
depends_on: if item.depends_on.is_empty() {
None
} else {
Some(
item.depends_on
.iter()
.filter_map(|d| d.0.split('_').next()?.parse::<u32>().ok())
.collect(),
)
},
};
match item.stage.as_str() {
"1_backlog" => state.backlog.push(story),
"2_current" => state.current.push(story),
"3_qa" => state.qa.push(story),
"4_merge" => state.merge.push(story),
"5_done" => state.done.push(story),
_ => {} // ignore archived or unknown stages
match &item.stage {
Stage::Backlog => state.backlog.push(story),
Stage::Coding => state.current.push(story),
Stage::Qa => state.qa.push(story),
Stage::Merge { .. } => state.merge.push(story),
Stage::Done { .. } => state.done.push(story),
Stage::Archived { .. } => {} // skip archived
}
}
@@ -256,22 +281,46 @@ fn load_stage_items_from_fs(
}
pub fn load_upcoming_stories(ctx: &AppContext) -> Result<Vec<UpcomingStory>, String> {
// Try CRDT first.
if let Some(crdt_items) = crate::crdt_state::read_all_items() {
let mut stories: Vec<UpcomingStory> = crdt_items
// Try typed projection first.
let typed_items = crate::pipeline_state::read_all_typed();
if !typed_items.is_empty() {
use crate::pipeline_state::Stage;
let mut stories: Vec<UpcomingStory> = typed_items
.into_iter()
.filter(|item| item.stage == "1_backlog")
.filter(|item| matches!(item.stage, Stage::Backlog))
.map(|item| UpcomingStory {
story_id: item.story_id,
name: item.name,
story_id: item.story_id.0,
name: if item.name.is_empty() {
None
} else {
Some(item.name)
},
error: None,
merge_failure: None,
agent: None,
review_hold: None,
qa: None,
retry_count: item.retry_count.map(|r| r as u32),
blocked: item.blocked,
depends_on: item.depends_on,
retry_count: if item.retry_count > 0 {
Some(item.retry_count)
} else {
None
},
blocked: if item.stage.is_blocked() {
Some(true)
} else {
None
},
depends_on: if item.depends_on.is_empty() {
None
} else {
Some(
item.depends_on
.iter()
.filter_map(|d| d.0.split('_').next()?.parse::<u32>().ok())
.collect(),
)
},
})
.collect();
stories.sort_by(|a, b| a.story_id.cmp(&b.story_id));
@@ -295,13 +344,16 @@ pub fn validate_story_dirs(
) -> Result<Vec<StoryValidationResult>, String> {
let mut results = Vec::new();
// Validate from CRDT + content store.
if let Some(crdt_items) = crate::crdt_state::read_all_items() {
for item in crdt_items {
if item.stage != "1_backlog" && item.stage != "2_current" {
// Validate from typed projection + content store.
{
let typed_items = crate::pipeline_state::read_all_typed();
for item in typed_items {
use crate::pipeline_state::Stage;
if !matches!(item.stage, Stage::Backlog | Stage::Coding) {
continue;
}
if let Some(content) = crate::db::read_content(&item.story_id) {
let sid = item.story_id.0.clone();
if let Some(content) = crate::db::read_content(&sid) {
match parse_front_matter(&content) {
Ok(meta) => {
let mut errors = Vec::new();
@@ -310,20 +362,20 @@ pub fn validate_story_dirs(
}
if errors.is_empty() {
results.push(StoryValidationResult {
story_id: item.story_id,
story_id: sid,
valid: true,
error: None,
});
} else {
results.push(StoryValidationResult {
story_id: item.story_id,
story_id: sid,
valid: false,
error: Some(errors.join("; ")),
});
}
}
Err(e) => results.push(StoryValidationResult {
story_id: item.story_id,
story_id: sid,
valid: false,
error: Some(e.to_string()),
}),
@@ -435,7 +487,10 @@ pub(super) fn write_story_content_with_fs(project_root: &Path, story_id: &str, s
/// Determine what stage a story is in (from CRDT).
pub(super) fn story_stage(story_id: &str) -> Option<String> {
crate::crdt_state::read_item(story_id).map(|item| item.stage)
crate::pipeline_state::read_typed(story_id)
.ok()
.flatten()
.map(|item| item.stage.dir_name().to_string())
}
/// Locate a work item file by searching all active pipeline stages on disk.