#!/usr/bin/env bash set -euo pipefail ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" cd "$ROOT" CACHE_DIR="${LINAAI_KNOWLEDGE_DIR:-Saved/LinaAIKnowledge}" RAW_DIR="${CACHE_DIR}/vendor/raw" INTERNAL_DIR="${CACHE_DIR}/internal" INDEX="${CACHE_DIR}/INDEX.md" mkdir -p "$RAW_DIR" "$INTERNAL_DIR" write_line() { printf '%s\n' "$1" >> "$INDEX" } : > "$INDEX" write_line "# LinaAI Knowledge Cache" write_line "" write_line "Generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" write_line "" write_line "This directory is ignored by Git. It is a local retrieval/cache area for LinaAI." write_line "Do not place raw credentials here." write_line "" write_line "## Tracked Project Memory" write_line "" project_docs=( "Docs/AI/LinaAIOperatingManual.md" "Docs/AI/LocalAgentGuardrails.md" "Docs/AI/LinaAISecretsPolicy.md" "Docs/AI/LinaAIKnowledgeMap.md" "Docs/Ops/HANDOFF.md" "AGRARIAN_DEVELOPMENT_ROADMAP.md" "Docs/CoreDesignDocument.md" "Docs/TechnicalDesignDocument.md" "Docs/SixMonthMvpDefinition.md" "Docs/MvpSurvivalReadinessCriteria.md" "Docs/Investor/InvestorDemoAcceptanceGate.md" "Docs/Art/AgrarianAssetPipeline.md" "Docs/Terrain/GroundZeroTile.md" "Docs/World/BiomeAndNaturalResourceGenerationPlan.md" "Docs/EconomyAndAgrDesignDocument.md" "Docs/MultiplayerNetworkingDesign.md" "Docs/PersistenceDesignDocument.md" ) for doc in "${project_docs[@]}"; do if [[ -f "$doc" ]]; then safe_name="$(printf '%s' "$doc" | tr '/ ' '__')" { printf '# %s\n\n' "$doc" grep -E '^(#|##|###) ' "$doc" 2>/dev/null || true } > "${INTERNAL_DIR}/${safe_name}.headings.md" write_line "- ${doc} -> ${INTERNAL_DIR}/${safe_name}.headings.md" else write_line "- missing: ${doc}" fi done write_line "" write_line "## Official Vendor Docs" write_line "" fetch_doc() { local name="$1" local url="$2" local out="${RAW_DIR}/${name}.html" if curl -L --fail --retry 2 --connect-timeout 10 --max-time 45 -o "$out" "$url"; then write_line "- ${name}: ${url} -> ${out}" else write_line "- ${name}: ${url} -> fetch failed" rm -f "$out" fi } fetch_doc "unraid" "https://docs.unraid.net/" fetch_doc "unreal-engine-5-7" "https://dev.epicgames.com/documentation/en-us/unreal-engine" fetch_doc "laravel-12" "https://laravel.com/docs/12.x" fetch_doc "mysql-8-4" "https://dev.mysql.com/doc/refman/8.4/en/" fetch_doc "gitea" "https://docs.gitea.com/" fetch_doc "ollama" "https://docs.ollama.com/" fetch_doc "open-webui" "https://docs.openwebui.com/" fetch_doc "aider" "https://aider.chat/docs/" write_line "" write_line "## Usage" write_line "" write_line "- Use this index as evidence that project/vendor docs were refreshed." write_line "- Use tracked docs as the source of truth for project policy." write_line "- Treat fetched vendor docs as reference material; verify details before risky edits." printf 'LinaAI knowledge cache refreshed: %s\n' "$INDEX"