# R15 + R16 box stand-up on irv-ml1 — NO-SUDO phase.
#
# Provisions everything that does NOT need root: uv, the R16 `world` venv +
# pyworld, and the engine-root dir skeleton. Two things are deliberately
# OUT of this playbook because they need sudo (separate operator-run phase):
#   - R + soundgen   (apt install r-base libfftw3-dev libsndfile1-dev; CRAN build)
#   - Ollama A6000 GPU pin (systemd drop-in CUDA_VISIBLE_DEVICES=1 + restart)
# The ollama model pulls are also run separately (long-running; ollama pull is
# itself idempotent).
#
# Setup contracts (brokkr-smithy @ irv-ml1:~/r14/brokkr-smithy, pulled to main):
#   R15 src/probes/P01/box_models.py  — ollama models @ $R15_OLLAMA_HOST (:11434)
#   R16 src/probes/P01/box_engines.py — R16_ENGINE_ROOT default ~/r16/engines;
#       world venv at $ROOT/world/.venv (pyworld); soundgen runner at $ROOT/soundgen
#
# Rerunnable: a second run should report mostly ok/skipped.

vars:
  engine_root: /home/lkraven/r16/engines
  uv_bin: /home/lkraven/.local/bin/uv

steps:
  - name: Install uv (user-local, no sudo)
    shell: curl -LsSf https://astral.sh/uv/install.sh | sh
    creates: "{{ uv_bin }}"

  - name: Create R16 engine-root dirs (soundgen + world)
    shell: mkdir -p {{ engine_root }}/soundgen {{ engine_root }}/world
    creates: "{{ engine_root }}/world"

  - name: Create the R16 world venv (python3.11)
    shell: "{{ uv_bin }} venv {{ engine_root }}/world/.venv --python 3.11"
    creates: "{{ engine_root }}/world/.venv/bin/python"

  - name: Install pyworld (+ setuptools<81 — pyworld imports pkg_resources, removed in setuptools 81)
    shell: "{{ uv_bin }} pip install --python {{ engine_root }}/world/.venv/bin/python pyworld 'setuptools<81'"
    when: "! {{ engine_root }}/world/.venv/bin/python -c 'import pyworld' 2>/dev/null"

verify:
  - name: uv present
    shell: test -x {{ uv_bin }}
    changed_when: "false"
  - name: world venv python present
    shell: test -x {{ engine_root }}/world/.venv/bin/python
    changed_when: "false"
  - name: pyworld importable in the world venv
    shell: "{{ engine_root }}/world/.venv/bin/python -c 'import pyworld; print(\"pyworld\", getattr(pyworld, \"__version__\", \"ok\"))'"
    changed_when: "false"
