huskies: merge 512_story_migrate_chat_commands_from_filesystem_lookup_to_crdt_db

This commit is contained in:
dave
2026-04-09 23:00:01 +00:00
parent c324452b38
commit 0de9200d48
9 changed files with 318 additions and 452 deletions
+10 -71
View File
@@ -9,16 +9,6 @@
use super::CommandContext;
use crate::io::story_metadata::{parse_front_matter, write_depends_on};
/// All pipeline stage directories searched when finding a work item by number.
const SEARCH_DIRS: &[&str] = &[
"1_backlog",
"2_current",
"3_qa",
"4_merge",
"5_done",
"6_archived",
];
/// Handle the `depends` command.
///
/// Syntax: `depends <number> [dep1 dep2 ...]`
@@ -60,69 +50,18 @@ 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;
// --- 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 Ok(Some(item)) = crate::pipeline_state::read_typed(&id) {
let path = ctx
.project_root
.join(".huskies")
.join("work")
.join(item.stage.dir_name())
.join(format!("{id}.md"));
found = Some((path, id));
break;
}
}
// --- 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;
// Find the story by numeric prefix: CRDT → content store → filesystem.
let (story_id, _stage_dir, path, content) =
match crate::chat::lookup::find_story_by_number(ctx.project_root, num_str) {
Some(found) => found,
None => {
return Some(format!(
"No story, bug, or spike with number **{num_str}** found."
));
}
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;
}
}
}
}
}
}
};
let (path, story_id) = match found {
Some(f) => f,
None => {
return Some(format!(
"No story, bug, or spike with number **{num_str}** found."
));
}
};
// Try the content store first, then fall back to reading from disk.
let story_name = crate::db::read_content(&story_id)
let story_name = content
.or_else(|| std::fs::read_to_string(&path).ok())
.and_then(|c| parse_front_matter(&c).ok())
.and_then(|m| m.name)