diff --git a/infra/ai-stack/README.md b/infra/ai-stack/README.md index 90a4d26..6a86bc5 100644 --- a/infra/ai-stack/README.md +++ b/infra/ai-stack/README.md @@ -7,6 +7,8 @@ Run: ```bash ./jeannie deploy-ai-stack +./jeannie deploy-hermes +./jeannie deploy-ai-tools ``` Runtime split: @@ -30,6 +32,12 @@ Secrets: - Jeannie discovers currently free OpenRouter models and NVIDIA catalog models, creates `agent-fast-free` and `agent-smart-free` OmniRoute combos, and writes `/data/homelab-ai-stack/models.env` for smoke tests and local tools. +- `deploy-ai-tools` writes `/data/homelab-ai-stack/ai-tools.env` and creates + `jeannie-goose`, `jeannie-holmes`, and `jeannie-hermes` wrappers in + `~/.local/bin` so each tool uses the local OmniRoute endpoint and generated + free/quota model routes. On fresh hosts, set `LAB_GOOSE_INSTALL_COMMAND`, + `LAB_HOLMES_INSTALL_COMMAND`, or `LAB_HERMES_INSTALL_COMMAND` if a CLI is not + already available. - Key files and generated env files are ignored by git. The container name defaults to `omniroute` so this command owns the same gateway diff --git a/jeannie b/jeannie index 6416069..cbc63b1 100755 --- a/jeannie +++ b/jeannie @@ -57,6 +57,7 @@ Build And Bootstrap deploy-dex Deploy the Debian-hosted Dex SSO stack. deploy-matrix Deploy the Matrix homeserver (Synapse + Element + Postgres). deploy-ai-stack Deploy the Debian-hosted AI gateway stack. + deploy-ai-tools Install/wire local AI CLIs to the AI gateway. deploy-omniroute Deploy the OmniRoute LLM routing gateway. deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service). bootstrap-gitea-repo Ensure the Gitea repo and SSH key wiring exist. @@ -406,6 +407,10 @@ case "${1:-}" in record_change_journal "deploy-ai-stack" "$@" deploy_ai_stack ;; + deploy-ai-tools) + record_change_journal "deploy-ai-tools" "$@" + deploy_ai_tools + ;; deploy-omniroute) record_change_journal "deploy-omniroute" "$@" deploy_omniroute diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 9b97481..534f183 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -2507,10 +2507,12 @@ ai_index() { ai_check() { local index_dir="${LAB_AI_KNOWLEDGE_INDEX_DIR:-/data/homelab-ai/index}" local routes_file="${LAB_AI_STACK_MODEL_ROUTES_FILE:-/data/homelab-ai-stack/models.env}" + local tools_env_file="${LAB_AI_STACK_TOOLS_ENV_FILE:-/data/homelab-ai-stack/ai-tools.env}" local endpoint="${LAB_AI_GATEWAY_URL:-${LAB_OLLAMA_URL:-http://127.0.0.1:11434}}" local model="${LAB_AI_GATEWAY_MODEL:-qwen2.5:0.5b}" local provider="${LAB_AI_GATEWAY_PROVIDER:-ollama}" local failures=0 + local tool require_debian_server "ai-check" @@ -2542,6 +2544,20 @@ ai_check() { printf '%-28s missing - install holmes for Kubernetes triage\n' "holmes k8s triage" fi + for tool in goose hermes holmes; do + if command -v "jeannie-${tool}" >/dev/null 2>&1; then + printf '%-28s ok - %s\n' "jeannie-${tool}" "$(command -v "jeannie-${tool}")" + else + printf '%-28s missing - run ./jeannie deploy-ai-tools\n' "jeannie-${tool}" + fi + done + + if [[ -s "${tools_env_file}" ]]; then + printf '%-28s ok - %s\n' "ai tools env" "${tools_env_file}" + else + printf '%-28s missing - run ./jeannie deploy-ai-tools\n' "ai tools env" + fi + if [[ -s "${routes_file}" ]]; then # shellcheck disable=SC1090 . "${routes_file}" diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index 62242a4..83c945b 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -63,6 +63,8 @@ mapping = { "services.ollama.igpu_enable": "LAB_OLLAMA_IGPU_ENABLE", "services.rpi_dns.pihole_web_port": "PIHOLE_WEB_PORT", "services.rpi_dns.uptime_kuma_port": "UPTIME_KUMA_PORT", + "services.ai_stack.install_dir": "LAB_AI_STACK_INSTALL_DIR", + "services.ai_stack.port": "LAB_OMNIROUTE_PORT", "ai_gateway.provider": "LAB_AI_GATEWAY_PROVIDER", "ai_gateway.enabled": "LAB_BACKSTAGE_BRAIN_ENABLED", "ai_gateway.url": "LAB_AI_GATEWAY_URL", diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 7041086..d99a41f 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -5399,6 +5399,108 @@ deploy_ai_stack() { else echo "Ollama is not reachable locally; run ./jeannie ollama-setup if local model fallback is required." >&2 fi + +} + +deploy_ai_tools() { + local mode="${LAB_AI_TOOLS_DEPLOY:-true}" + local install_dir="${LAB_AI_STACK_INSTALL_DIR:-/data/homelab-ai-stack}" + local model_routes_file="${LAB_AI_STACK_MODEL_ROUTES_FILE:-${install_dir}/models.env}" + local tools_env_file="${LAB_AI_STACK_TOOLS_ENV_FILE:-${install_dir}/ai-tools.env}" + local bin_dir="${LAB_AI_TOOLS_BIN_DIR:-/home/jv/.local/bin}" + local port="${LAB_OMNIROUTE_PORT:-20128}" + local endpoint="${LAB_AI_GATEWAY_URL:-http://127.0.0.1:${port}/v1}" + local api_key="${LAB_AI_GATEWAY_API_KEY:-${OMNIROUTE_API_KEY:-sk_omniroute}}" + local fast_model="${LAB_AI_TOOLS_FAST_MODEL:-agent-fast-free}" + local smart_model="${LAB_AI_TOOLS_SMART_MODEL:-agent-smart-free}" + local missing_tools=() + local tool + local install_var + local install_cmd + + require_debian_server "deploy-ai-tools" + + if disabled_value "${mode}"; then + return 0 + fi + + if [[ -s "${model_routes_file}" ]]; then + # shellcheck disable=SC1090 + . "${model_routes_file}" + fast_model="${LAB_AI_TOOLS_FAST_MODEL:-${AI_STACK_AGENT_FAST_MODEL:-${fast_model}}}" + smart_model="${LAB_AI_TOOLS_SMART_MODEL:-${AI_STACK_AGENT_SMART_MODEL:-${smart_model}}}" + else + echo "AI stack model routes are missing at ${model_routes_file}; run ./jeannie deploy-ai-stack first." >&2 + fi + + echo "Configuring bare-metal AI tools for OmniRoute at ${endpoint}..." + install -d -m 0755 "${bin_dir}" + sudo install -d -m 0750 -o "$(id -u)" -g "$(id -g)" "${install_dir}" + + for tool in goose holmes hermes; do + if command -v "${tool}" >/dev/null 2>&1; then + echo "${tool}: present at $(command -v "${tool}")" + continue + fi + + install_var="LAB_$(printf '%s' "${tool}" | tr '[:lower:]' '[:upper:]')_INSTALL_COMMAND" + install_cmd="${!install_var:-}" + if [[ -n "${install_cmd}" ]]; then + echo "${tool}: installing with ${install_var}..." + bash -lc "${install_cmd}" + fi + + if ! command -v "${tool}" >/dev/null 2>&1; then + missing_tools+=("${tool}") + else + echo "${tool}: installed at $(command -v "${tool}")" + fi + done + + if ((${#missing_tools[@]} > 0)); then + echo "Missing AI tool(s): ${missing_tools[*]}" >&2 + echo "Set LAB_GOOSE_INSTALL_COMMAND, LAB_HOLMES_INSTALL_COMMAND, or LAB_HERMES_INSTALL_COMMAND to make fresh installs fully automated." >&2 + echo "Existing Debian hosts with these tools already installed will pass this phase without manual work." >&2 + exit 1 + fi + + sudo tee "${tools_env_file}" >/dev/null </dev/null <&2 fi + if [[ -s "${ai_model_routes_file}" ]]; then + # shellcheck disable=SC1090 + . "${ai_model_routes_file}" + hermes_model="${HERMES_MODEL:-${AI_STACK_AGENT_SMART_MODEL:-${hermes_model}}}" + fi + if [[ -s "${ai_tools_env_file}" ]]; then + # shellcheck disable=SC1090 + . "${ai_tools_env_file}" + hermes_openai_base_url="${HERMES_OPENAI_BASE_URL:-${hermes_openai_base_url}}" + hermes_omniroute_api_key="${HERMES_OMNIROUTE_API_KEY:-${OPENAI_API_KEY:-${hermes_omniroute_api_key}}}" + hermes_model="${HERMES_MODEL:-${AI_STACK_AGENT_SMART_MODEL:-${hermes_model}}}" + fi + local secrets_file="${hermes_home}/.env" sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" "${hermes_home}" if [[ -f "${secrets_file}" ]]; then sudo cp "${secrets_file}" "${secrets_file}.bak-pre-jeannie" fi sudo tee "${secrets_file}" >/dev/null <