#!/bin/bash
# bluera-knowledge statusline module
# Injected into ~/.claude/statusline.sh between boundary comments:
#   # --- bluera-knowledge ---
#   # --- end bluera-knowledge ---
#
# Expected variables from parent script:
#   PROJECT_DIR - project directory path (from statusline JSON input)
#
# Exports:
#   BK_STATUS - formatted status string (e.g. " 📘●3")

get_bk_status() {
    local project_dir="$1"
    local store_count=""
    local config_file="$project_dir/.bluera/bluera-knowledge/stores.config.json"
    if [ -f "$config_file" ]; then
        store_count=$(jq '.stores | length' "$config_file" 2>/dev/null)
        [ "$store_count" = "0" ] && store_count=""
    fi

    if pgrep -f "bluera-knowledge.*bootstrap" >/dev/null 2>&1 || \
       pgrep -f "bluera-knowledge-mcp" >/dev/null 2>&1; then
        printf " 📘\033[32m●\033[0m%s" "$store_count"
    else
        printf " 📘\033[31m●\033[0m%s" "$store_count"
    fi
}
BK_STATUS=$(get_bk_status "$PROJECT_DIR")
