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:
@@ -98,20 +98,33 @@ pub fn apply_transition_str(
|
||||
apply_transition(story_id, event, content_transform).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Freeze a story at its current stage.
|
||||
/// Freeze a story.
|
||||
///
|
||||
/// Story 929: the YAML write of `resume_to_stage` is gone; the projection
|
||||
/// layer no longer reads it (defaults to Coding). Story 934 will make
|
||||
/// frozen a flag orthogonal to Stage, so the story stays in its current
|
||||
/// Stage rather than encoding a "where to resume" payload — at which point
|
||||
/// the read-side default also becomes moot.
|
||||
pub fn transition_to_frozen(story_id: &str) -> Result<TransitionFired, ApplyError> {
|
||||
apply_transition(story_id, PipelineEvent::Freeze, None)
|
||||
/// Story 934, stage 4: `frozen` is now a CRDT flag orthogonal to [`Stage`],
|
||||
/// so the story stays at its current stage and only the boolean register
|
||||
/// changes. Returns `Err(NotFound)` if no item exists for `story_id`.
|
||||
pub fn transition_to_frozen(story_id: &str) -> Result<(), ApplyError> {
|
||||
if read_typed(story_id)?.is_none() {
|
||||
return Err(ApplyError::NotFound(story_id.to_string()));
|
||||
}
|
||||
crate::crdt_state::set_frozen(story_id, true);
|
||||
crate::slog!("[pipeline/transition] #{}: Freeze (flag set)", story_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Unfreeze a story.
|
||||
///
|
||||
/// Story 929: paired with `transition_to_frozen`, no longer touches YAML.
|
||||
pub fn transition_to_unfrozen(story_id: &str) -> Result<TransitionFired, ApplyError> {
|
||||
apply_transition(story_id, PipelineEvent::Unfreeze, None)
|
||||
/// Story 934, stage 4: paired with [`transition_to_frozen`]; clears the
|
||||
/// CRDT `frozen` flag without touching the stage register. Returns
|
||||
/// `Err(NotFound)` if no item exists for `story_id`.
|
||||
pub fn transition_to_unfrozen(story_id: &str) -> Result<(), ApplyError> {
|
||||
if read_typed(story_id)?.is_none() {
|
||||
return Err(ApplyError::NotFound(story_id.to_string()));
|
||||
}
|
||||
crate::crdt_state::set_frozen(story_id, false);
|
||||
crate::slog!(
|
||||
"[pipeline/transition] #{}: Unfreeze (flag cleared)",
|
||||
story_id
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user