#!/bin/bash
# Search the wiki — usable by both humans and LLM agents
# Usage: ./wiki/tools/search.sh "query" [--files-only]

WIKI_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
QUERY="$1"
MODE="${2:---content}"

if [ -z "$QUERY" ]; then
    echo "Usage: $0 <query> [--files-only]"
    exit 1
fi

if [ "$MODE" = "--files-only" ]; then
    grep -rl --include="*.md" --include="*.yaml" "$QUERY" "$WIKI_DIR" 2>/dev/null | sort
else
    grep -rn --include="*.md" --include="*.yaml" --color=auto -i "$QUERY" "$WIKI_DIR" 2>/dev/null
fi
