feat(934): typed Stage enum replaces directory-string state model
The state machine's `Stage` enum becomes the source of truth for pipeline
state. Six stages of work land together:
1. Clean wire vocabulary (`coding`, `merge`, `merge_failure`, ...) replaces
legacy directory-style strings (`2_current`, `4_merge`, ...) on the wire.
`Stage::from_dir` accepted both during deployment; new writes always
emit the clean form via `stage_dir_name`. Lexicographic `dir >= "5_done"`
checks in lifecycle.rs become typed `matches!` checks since the new
vocabulary doesn't sort in pipeline order.
2. `crdt_state::write_item` takes typed `&Stage`, serialising via
`stage_dir_name` at the CRDT boundary. `#[cfg(test)] write_item_str`
parses legacy strings for test fixtures.
3. `WorkItem::stage()` returns typed `crdt_state::Stage`; `stage_str()`
is gone from the public API. Projection dispatches on the typed enum.
4. `frozen` becomes an orthogonal CRDT register. `Stage::Frozen` and
`PipelineEvent::Freeze`/`Unfreeze` are removed; `transition_to_frozen`/
`unfrozen` set the flag directly without touching the stage register.
5. Watcher sweep and `tool_update_story`'s `blocked` setter route through
`apply_transition` so the typed transition table validates every
stage change. `update_story` gains a `frozen` field for symmetry.
6. One-shot startup migration rewrites pre-934 directory-style stage
registers (and sets `frozen=true` on items previously at `7_frozen`).
`Stage::from_dir` drops legacy aliases. The db boundary keeps a small
normaliser so callers with legacy strings (MCP, tests) still work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,7 @@ mod tests {
|
||||
stage,
|
||||
depends_on: Vec::new(),
|
||||
retry_count: 0,
|
||||
frozen: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +82,7 @@ mod tests {
|
||||
stage,
|
||||
depends_on: deps.iter().map(|n| StoryId(n.to_string())).collect(),
|
||||
retry_count: 0,
|
||||
frozen: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ mod tests {
|
||||
.expect("read_typed should succeed")
|
||||
.expect("item should be present");
|
||||
assert!(
|
||||
item.stage.is_frozen(),
|
||||
item.is_frozen(),
|
||||
"stage should be Frozen after freeze: {:?}",
|
||||
item.stage
|
||||
);
|
||||
|
||||
@@ -13,6 +13,7 @@ fn make_item(id: &str, name: &str, stage: Stage) -> PipelineItem {
|
||||
stage,
|
||||
depends_on: Vec::new(),
|
||||
retry_count: 0,
|
||||
frozen: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ fn make_item_with_deps(id: &str, name: &str, stage: Stage, deps: Vec<u32>) -> Pi
|
||||
stage,
|
||||
depends_on: deps.iter().map(|n| StoryId(n.to_string())).collect(),
|
||||
retry_count: 0,
|
||||
frozen: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ mod tests {
|
||||
);
|
||||
// Seed the story in the CRDT in 2_blocked stage so the typed
|
||||
// Blocked → Coding transition fires and clears `blocked` properly.
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
"9903_story_stuck",
|
||||
"2_blocked",
|
||||
Some("Stuck Story"),
|
||||
@@ -273,7 +273,7 @@ mod tests {
|
||||
);
|
||||
// Seed CRDT registers: blocked=true, retry_count=5, with a name so the
|
||||
// response can echo it back instead of falling through to the raw id.
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
story_id,
|
||||
stage,
|
||||
Some("Stuck Story"),
|
||||
|
||||
@@ -33,18 +33,14 @@ pub(crate) fn find_story_by_number(
|
||||
if let Some(items) = crate::crdt_state::read_all_items() {
|
||||
for item in items {
|
||||
if item.story_id().split('_').next().unwrap_or("") == number {
|
||||
let stage_dir = item.stage().as_dir().to_string();
|
||||
let path = project_root
|
||||
.join(".huskies")
|
||||
.join("work")
|
||||
.join(item.stage_str())
|
||||
.join(&stage_dir)
|
||||
.join(format!("{}.md", item.story_id()));
|
||||
let content = crate::db::read_content(item.story_id());
|
||||
return Some((
|
||||
item.story_id().to_string(),
|
||||
item.stage_str().to_string(),
|
||||
path,
|
||||
content,
|
||||
));
|
||||
return Some((item.story_id().to_string(), stage_dir, path, content));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,8 +54,8 @@ pub(crate) fn find_story_by_number(
|
||||
continue;
|
||||
}
|
||||
let stage_dir = crate::crdt_state::read_item(&id)
|
||||
.map(|v| v.stage_str().to_string())
|
||||
.unwrap_or_else(|| "1_backlog".to_string());
|
||||
.map(|v| v.stage().as_dir().to_string())
|
||||
.unwrap_or_else(|| "backlog".to_string());
|
||||
let path = project_root
|
||||
.join(".huskies")
|
||||
.join("work")
|
||||
|
||||
@@ -313,7 +313,7 @@ mod tests {
|
||||
None,
|
||||
);
|
||||
// Seed CRDT so set_agent can write to the item.
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
"9972_story_test",
|
||||
"1_backlog",
|
||||
Some("Test Feature"),
|
||||
@@ -369,7 +369,7 @@ mod tests {
|
||||
"---\nname: Small Story\n---\n",
|
||||
None,
|
||||
);
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
"9973_story_small",
|
||||
"1_backlog",
|
||||
Some("Small Story"),
|
||||
@@ -420,7 +420,7 @@ mod tests {
|
||||
"---\nname: Existing\nagent: coder-sonnet\n---\n",
|
||||
None,
|
||||
);
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
"9974_story_existing",
|
||||
"1_backlog",
|
||||
Some("Existing"),
|
||||
|
||||
@@ -112,7 +112,6 @@ fn stage_display_name(stage: &str) -> &str {
|
||||
Some(Stage::Done { .. }) => "done",
|
||||
Some(Stage::Archived { .. }) => "archived",
|
||||
Some(Stage::MergeFailure { .. }) => "merge-failure",
|
||||
Some(Stage::Frozen { .. }) => "frozen",
|
||||
None => stage,
|
||||
}
|
||||
}
|
||||
@@ -239,7 +238,7 @@ mod tests {
|
||||
let story_number = "9977";
|
||||
|
||||
// Seed in CRDT.
|
||||
crate::crdt_state::write_item(
|
||||
crate::crdt_state::write_item_str(
|
||||
story_id,
|
||||
"1_backlog",
|
||||
Some("CRDT Tombstone Check"),
|
||||
|
||||
Reference in New Issue
Block a user