huskies: merge 492_story_remove_filesystem_pipeline_state_and_store_story_content_in_database

This commit is contained in:
dave
2026-04-08 03:03:59 +00:00
parent f43d30bdae
commit 8fd49d563e
27 changed files with 1663 additions and 1295 deletions
+45 -25
View File
@@ -61,32 +61,51 @@ pub(super) fn handle_depends(ctx: &CommandContext) -> Option<String> {
}
// Find the story file across all pipeline stages by numeric prefix.
// Try the content store / CRDT state first, then fall back to filesystem.
let mut found: Option<(std::path::PathBuf, String)> = None;
'outer: for stage_dir in SEARCH_DIRS {
let dir = ctx
.project_root
.join(".huskies")
.join("work")
.join(stage_dir);
if !dir.exists() {
continue;
// --- DB-first lookup ---
for id in crate::db::all_content_ids() {
let file_num = id.split('_').next().unwrap_or("");
if file_num == num_str && let Some(item) = crate::crdt_state::read_item(&id) {
let path = ctx
.project_root
.join(".huskies")
.join("work")
.join(&item.stage)
.join(format!("{id}.md"));
found = Some((path, id));
break;
}
if let Ok(entries) = std::fs::read_dir(&dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|e| e.to_str()) != Some("md") {
continue;
}
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
let file_num = stem
.split('_')
.next()
.filter(|s| !s.is_empty() && s.chars().all(|c| c.is_ascii_digit()))
.unwrap_or("");
if file_num == num_str {
found = Some((path.to_path_buf(), stem.to_string()));
break 'outer;
}
// --- Filesystem fallback ---
if found.is_none() {
'outer: for stage_dir in SEARCH_DIRS {
let dir = ctx
.project_root
.join(".huskies")
.join("work")
.join(stage_dir);
if !dir.exists() {
continue;
}
if let Ok(entries) = std::fs::read_dir(&dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|e| e.to_str()) != Some("md") {
continue;
}
if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
let file_num = stem
.split('_')
.next()
.filter(|s| !s.is_empty() && s.chars().all(|c| c.is_ascii_digit()))
.unwrap_or("");
if file_num == num_str {
found = Some((path.to_path_buf(), stem.to_string()));
break 'outer;
}
}
}
}
@@ -102,8 +121,9 @@ pub(super) fn handle_depends(ctx: &CommandContext) -> Option<String> {
}
};
let story_name = std::fs::read_to_string(&path)
.ok()
// Try the content store first, then fall back to reading from disk.
let story_name = crate::db::read_content(&story_id)
.or_else(|| std::fs::read_to_string(&path).ok())
.and_then(|c| parse_front_matter(&c).ok())
.and_then(|m| m.name)
.unwrap_or_else(|| story_id.clone());