#!/usr/bin/env bash
# install-harness.sh
# Copies the agent operating system (Constitution, skills, context, memory, and the
# virtual expert team) into a target project so any coding agent starts with your
# rules and procedures in hand. It does NOT overwrite files that already exist.
#
# Usage:
#   bash scripts/install-harness.sh /path/to/your/project
#
# After this, install the config and CI/CD templates too. See templates/README.md.

set -euo pipefail

here="$(cd "$(dirname "$0")/.." && pwd)"
target="${1:-}"

if [ -z "$target" ]; then
  echo "Usage: bash scripts/install-harness.sh /path/to/your/project"
  echo
  echo "Copies CLAUDE.md, AGENTS.md, GEMINI.md, skills/, context/, memory/, and"
  echo ".claude/ into the target project (without overwriting existing files)."
  exit 1
fi

if [ ! -d "$target" ]; then
  echo "Target directory does not exist: $target"
  exit 1
fi

copy() {
  # copy <relative-path>  (file or directory). Skips anything already present.
  local rel="$1"
  local src="$here/$rel"
  local dst="$target/$rel"
  if [ -e "$dst" ]; then
    echo "  skip  $rel (already exists in target)"
    return
  fi
  mkdir -p "$(dirname "$dst")"
  cp -R "$src" "$dst"
  echo "  copy  $rel"
}

echo "Installing the agent harness into: $target"
echo

copy "CLAUDE.md"
copy "AGENTS.md"
copy "GEMINI.md"
copy "skills"
copy "context"
copy "memory"
copy ".claude/agents"
copy ".claude/commands"
copy ".claude/settings.json"
copy ".claude/settings.local.example.json"

echo
echo "Done. Next steps:"
echo "  1. Adapt CLAUDE.md to your project (keep it lean)."
echo "  2. Install config and CI/CD templates: see $here/templates/README.md"
echo "  3. Start filling in context/architecture.md as you build."
