huskies: merge 1007

This commit is contained in:
dave
2026-05-14 08:36:46 +00:00
parent 13ab97a615
commit 761b6934f1
7 changed files with 215 additions and 7 deletions
+34
View File
@@ -158,6 +158,40 @@ pub(crate) fn tool_mesh_status(_args: &Value) -> Result<String, String> {
.map_err(|e| format!("Serialization error: {e}"))
}
/// MCP tool: find half-written (orphaned) pipeline items.
///
/// Scans the in-memory content store for story IDs that have no corresponding
/// live CRDT entry. These are items that were partially written before bug
/// 1001 was fixed — the content store (and optionally the SQLite shadow)
/// accepted the write, but the CRDT silently rejected it (because the ID was
/// tombstoned). They are invisible to every normal read path.
pub(crate) fn tool_find_orphaned_items(_args: &Value) -> Result<String, String> {
let orphans = crate::db::recover::find_half_written_items();
serde_json::to_string_pretty(&serde_json::json!({
"orphan_count": orphans.len(),
"orphans": orphans,
}))
.map_err(|e| format!("Serialization error: {e}"))
}
/// MCP tool: recover half-written (orphaned) pipeline items.
///
/// For each orphaned item (content store row with no live CRDT entry), lifts
/// the content onto a fresh non-tombstoned ID so it becomes addressable again.
/// Pass `only` to restrict recovery to specific orphan IDs; omit to recover all.
/// Returns a mapping of `old_id → new_id` for every successful recovery.
pub(crate) fn tool_recover_half_written_items(args: &Value) -> Result<String, String> {
let only: Option<Vec<String>> = args
.get("only")
.and_then(|v| serde_json::from_value(v.clone()).ok());
let results = crate::db::recover::recover_half_written_items(only.as_deref());
serde_json::to_string_pretty(&serde_json::json!({
"recovered_count": results.len(),
"mappings": results,
}))
.map_err(|e| format!("Serialization error: {e}"))
}
/// MCP tool: count lines in a specific file relative to the project root.
pub(crate) fn tool_loc_file(args: &Value, ctx: &AppContext) -> Result<String, String> {
let file_path = args