#!/bin/sh
# Copy all AGENTS.md files to a target directory while preserving structure.
out_dir=$1

if [ -z "$out_dir" ]; then
    echo "Error: Output directory required." >&2
    echo "Usage: extract_agents <absolute_or_relative_output_path>" >&2
    exit 1
fi

mkdir -p "$out_dir"

# Find and copy preserving relative paths
fd -t f -g "AGENTS.md" -x cp --parents "{}" "$out_dir"

echo "Extraction complete. Check $out_dir."
