# @kolu/surface mini-ci — standalone example.
#
# `just run [host]` runs the TUI with the independent example flake as its
# exact agent source. @kolu/surface-remote probes the host and provisions the
# matching runner through its connector-owned Nix lifetime.
#
#   just run                    local (host = localhost)
#   just run user@host          remote (needs passwordless ssh + Nix on host)
#   just run localhost --json   scriptable (or --headless)

import '../binary-cache.just'

repo_root := justfile_directory() / "../../../.."
nix_shell := if env('IN_NIX_SHELL', '') != '' { '' } else { 'nix develop ' + repo_root + ' --accept-flake-config -c' }

# List available recipes
default:
    @just --list

# Install pnpm deps (delegates to the workspace at the repo root)
install:
    cd {{ repo_root }} && {{ nix_shell }} pnpm install

# Run the pipeline on `host` (default localhost).
run host='localhost' *args: install binary-cache
    #!/usr/bin/env bash
    set -euo pipefail
    cd {{ justfile_directory() }}
    agent_env=$({{ nix_shell }} node -p "require('{{ repo_root }}/packages/surface-remote/agent-env.json').flakeRef")
    echo "» host: {{ host }}" >&2
    env "$agent_env={{ agent_source_dir }}" \
      {{ nix_shell }} pnpm start -- {{ host }} {{ args }}

# Typecheck this example only
typecheck:
    cd {{ justfile_directory() }} && {{ nix_shell }} pnpm typecheck

# Run this example's unit tests
test:
    cd {{ justfile_directory() }} && {{ nix_shell }} pnpm test:unit
