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:
Timmy
2026-05-12 22:31:59 +01:00
parent 93443e2ff1
commit d78dd9e8f9
55 changed files with 783 additions and 584 deletions
@@ -116,14 +116,13 @@ pub(super) fn check_archived_dependencies(
crate::crdt_state::check_archived_deps_crdt(story_id)
}
/// Return `true` if the story is in the `Frozen` pipeline stage.
/// Return `true` if the story's `frozen` CRDT flag is set (story 934, stage 4).
///
/// Checks the typed CRDT stage via `read_typed`.
/// `frozen` is orthogonal to [`Stage`]: a frozen story keeps its current stage
/// register but is skipped by the auto-assigner.
pub(super) fn is_story_frozen(_project_root: &Path, _stage_dir: &str, story_id: &str) -> bool {
crate::pipeline_state::read_typed(story_id)
.ok()
.flatten()
.map(|item| item.stage.is_frozen())
crate::crdt_state::read_item(story_id)
.map(|view| view.frozen())
.unwrap_or(false)
}
@@ -140,7 +139,7 @@ mod tests {
crate::crdt_state::init_for_test();
crate::db::ensure_content_store();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"890_spike_held",
"3_qa",
Some("Held Spike"),
@@ -161,7 +160,7 @@ mod tests {
crate::crdt_state::init_for_test();
crate::db::ensure_content_store();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"890_spike_active_qa",
"3_qa",
Some("Active QA Spike"),
@@ -253,7 +252,7 @@ mod tests {
fn has_unmet_dependencies_returns_true_when_dep_not_done() {
crate::crdt_state::init_for_test();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"10_story_blocked",
"2_current",
Some("Blocked"),
@@ -276,7 +275,7 @@ mod tests {
fn has_unmet_dependencies_returns_false_when_dep_done() {
crate::crdt_state::init_for_test();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"999_story_dep",
"5_done",
Some("Dep"),
@@ -288,7 +287,7 @@ mod tests {
None,
None,
);
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"10_story_ok",
"2_current",
Some("Ok"),
@@ -311,7 +310,7 @@ mod tests {
fn has_unmet_dependencies_returns_false_when_no_deps() {
crate::crdt_state::init_for_test();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"5_story_free",
"2_current",
Some("Free"),
@@ -337,7 +336,7 @@ mod tests {
fn check_archived_dependencies_returns_archived_ids() {
crate::crdt_state::init_for_test();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"500_spike_crdt",
"6_archived",
Some("CRDT Spike"),
@@ -349,7 +348,7 @@ mod tests {
None,
None,
);
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"503_story_dependent",
"1_backlog",
Some("Dependent"),
@@ -371,7 +370,7 @@ mod tests {
fn check_archived_dependencies_empty_when_dep_in_done() {
crate::crdt_state::init_for_test();
let tmp = tempfile::tempdir().unwrap();
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"490_story_done",
"5_done",
Some("Done"),
@@ -383,7 +382,7 @@ mod tests {
None,
None,
);
crate::crdt_state::write_item(
crate::crdt_state::write_item_str(
"503_story_waiting",
"1_backlog",
Some("Waiting"),