devbrain 0.1.0

Local-first CLI to capture, search, and recall developer workflow (commands, errors, and fixes)
use crate::error::DevbrainError;
use chrono::{SecondsFormat, Utc};
use std::env;

const MAX_INPUT_LENGTH: usize = 500;

pub fn get_timestamp() -> String {
    Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)
}

pub fn get_project_name() -> String {
    env::current_dir()
        .ok()
        .and_then(|path| {
            path.file_name()
                .map(|name| name.to_string_lossy().into_owned())
        })
        .filter(|name| !name.is_empty())
        .unwrap_or_else(|| "unknown".to_string())
}

pub fn normalize_input(input: &str) -> Result<String, DevbrainError> {
    let normalized = input.trim();

    if normalized.is_empty() {
        return Err(DevbrainError::Other("Input cannot be empty".to_string()));
    }

    if normalized.chars().count() > MAX_INPUT_LENGTH {
        return Err(DevbrainError::Other("Input too long".to_string()));
    }

    Ok(normalized.to_string())
}