use anyhow::Result;
use std::path::{Path, PathBuf};
use tracing::info;
pub fn artifact_dir() -> Result<PathBuf> {
Ok(crate::runtime::config::omk_data_dir()
.join("artifacts")
.join("ask"))
}
pub fn artifact_path(name: &str, timestamp: &str) -> Result<PathBuf> {
let dir = artifact_dir()?;
Ok(dir.join(format!("{}-{name}.md", timestamp)))
}
pub async fn save_artifact_to(
base_dir: &Path,
name: &str,
content: &str,
timestamp: &str,
) -> Result<PathBuf> {
let path = base_dir.join(format!("{}-{name}.md", timestamp));
if let Some(parent) = path.parent() {
tokio::fs::create_dir_all(parent).await?;
}
tokio::fs::write(&path, content).await?;
info!(path = %path.display(), name = name, "Saved artifact");
Ok(path)
}
pub async fn save_artifact(name: &str, content: &str, timestamp: &str) -> Result<PathBuf> {
let dir = artifact_dir()?;
save_artifact_to(&dir, name, content, timestamp).await
}