pub(super) fn requests_execution(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    [
        " run ",
        " execute ",
        " use a tool",
        "use the tool",
        "tools you can use",
        "pick one at random",
        "introspection tool",
        "introspection skill",
        "introspect",
        "list entries",
        "list files",
        "file distribution",
        "schedule a cron",
        "schedule cron",
        "create cron",
        "order a subagent",
        "delegate",
        "orchestrate",
        "ls ",
        "/status",
    ]
    .iter()
    .any(|m| lower.contains(m))
}

pub(super) fn requests_delegation(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    if lower.contains("delegate") || lower.contains("orchestrate") {
        return true;
    }
    if lower.contains("assign") && (lower.contains("subagent") || lower.contains("sub agent")) {
        return true;
    }
    (lower.contains("subagent") || lower.contains("sub agent"))
        && (lower.contains("order")
            || lower.contains("ask")
            || lower.contains("task")
            || lower.contains("run ")
            || lower.contains("to a subagent")
            || lower.contains("to a sub agent")
            || lower.contains("to the subagent")
            || lower.contains("to the sub agent"))
}

pub(super) fn requests_cron(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    lower.contains("cron") || (lower.contains("schedule") && lower.contains("minute"))
}

pub(super) fn requests_file_distribution(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    lower.contains("file distribution")
}

pub(super) fn requests_current_events(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    [
        "geopolitical situation",
        "geopolitical",
        "geo political",
        "geopolitical sitrep",
        "sitrep",
        "current events",
        "latest news",
        "what's happening",
        "what is happening",
        "goings on",
        "going on in the",
        "what does the",
        "today's",
        "as of today",
    ]
    .iter()
    .any(|m| lower.contains(m))
}

pub(super) fn requests_introspection(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    [
        "introspection tool",
        "introspection skill",
        "introspect",
        "what tools can you use",
        "what tools do you have",
        "available tools",
        "subagent functionality",
        "current subagent functionality",
        "summarize the results",
        "summarize introspection",
    ]
    .iter()
    .any(|m| lower.contains(m))
}

pub(super) fn requests_acknowledgement(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    (lower.contains("acknowledge") || lower.contains("acknowledg"))
        && (lower.contains("one sentence") || lower.contains("then wait"))
}

pub(super) fn requests_provider_inventory(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    lower.contains("which llm providers")
        || lower.contains("what llm providers")
        || lower.contains("which providers")
        || lower.contains("what providers")
}

pub(super) fn requests_personality_profile(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    (lower.contains("personality") && (lower.contains("your") || lower.contains("you")))
        || lower.contains("who are you")
}

pub(super) fn requests_capability_summary(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    lower.contains("what are you able to do")
        || lower.contains("what can you do")
        || lower.contains("what are you able")
        || lower.contains("what can you help")
}

pub(super) fn requests_obsidian_insights(prompt: &str) -> bool {
    let lower = prompt.to_ascii_lowercase();
    let mentions_vault = lower.contains("obsidian") || lower.contains("vault");
    let asks_for_summary = lower.contains("insight")
        || lower.contains("summary")
        || lower.contains("summarize")
        || lower.contains("what")
        || lower.contains("say about")
        || lower.contains("status");
    mentions_vault && asks_for_summary
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn execution_markers_cover_shortcut_and_guard_triggers() {
        assert!(requests_execution(
            "tell me about the tools you can use, pick one at random, and use it"
        ));
        assert!(requests_execution("/status"));
        assert!(requests_execution("please execute ls /tmp"));
    }

    #[test]
    fn delegation_and_cron_markers_match_expected_prompts() {
        assert!(requests_delegation("order a subagent to do this"));
        assert!(requests_delegation("ask the sub agent to do this"));
        assert!(!requests_delegation(
            "use your introspection tool to discover current subagent functionality"
        ));
        assert!(requests_cron("schedule a cron job every 5 minute"));
    }

    #[test]
    fn current_events_markers_match_expected_prompts() {
        assert!(requests_current_events(
            "What's the geopolitical situation?"
        ));
        assert!(requests_current_events("Give me a geopolitical sitrep"));
        assert!(requests_current_events(
            "What does the geo political sub agent say about goings on in the US?"
        ));
        assert!(requests_current_events("What are today's current events?"));
    }

    #[test]
    fn introspection_markers_match_expected_prompts() {
        assert!(requests_introspection(
            "I want you to use your introspection skill"
        ));
        assert!(requests_introspection(
            "use your introspection tool to discover current subagent functionality"
        ));
        assert!(requests_introspection("what tools do you have available?"));
    }

    #[test]
    fn acknowledgement_markers_match_expected_prompts() {
        assert!(requests_acknowledgement(
            "Good evening Duncan. Acknowledge this request in one sentence, then wait."
        ));
        assert!(requests_acknowledgement(
            "acknowledge this in one sentence and then wait for my next command"
        ));
        assert!(!requests_acknowledgement("please acknowledge receipt"));
    }

    #[test]
    fn provider_inventory_markers_match_expected_prompts() {
        assert!(requests_provider_inventory("which llm providers?"));
        assert!(requests_provider_inventory("what providers are configured"));
        assert!(!requests_provider_inventory("what model are you using"));
    }

    #[test]
    fn personality_and_capability_markers_match_expected_prompts() {
        assert!(requests_personality_profile(
            "Tell me about your personality"
        ));
        assert!(requests_personality_profile("who are you"));
        assert!(requests_capability_summary(
            "Duncan, what are you able to do for me right now?"
        ));
    }

    #[test]
    fn obsidian_insight_markers_match_expected_prompts() {
        assert!(requests_obsidian_insights(
            "Any insights you care to draw from the obsidian vault?"
        ));
        assert!(requests_obsidian_insights("summarize my vault"));
        assert!(!requests_obsidian_insights("vault token price"));
    }
}
