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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user