#!/bin/bash
#
# Directory Status Management Skill for Claude Code
# ==================================================
# Manages README.md and STATUS.md files across all subdirectories.
#
# Commands:
#   sweep [--fix]              Check all directories for README/STATUS files
#   update <dir> [options]     Update status for a directory
#   init <dir>                 Initialize README/STATUS in a directory
#   dashboard                  Show status overview of all directories
#   template [readme|status]   Show file templates
#
# Examples:
#   status sweep               Check all directories
#   status sweep --fix         Auto-create missing files
#   status update ./pipeline --phase "complete" --task "Pipeline unified"
#   status dashboard           Show project-wide status

set -euo pipefail

STATUS_SCRIPT="/opt/agent-governance/bin/status.py"

# Show help if no args or --help
if [[ $# -eq 0 ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "-h" ]]; then
    cat << 'EOF'
Directory Status Management
===========================

Commands:
  sweep [--fix]              Check all directories for README/STATUS
  update <dir> [options]     Update directory status
  init <dir>                 Initialize README/STATUS files
  dashboard                  Show status overview
  template [readme|status]   Show file templates

Update Options:
  --phase <phase>            Set phase (in_progress/complete/blocked/needs_review)
  --task <description>       Add task entry
  --note <note>              Add note to status log
  --deps <dependencies>      Set dependencies

Status Indicators:
  [COMPLETE]     Directory work is finished
  [IN_PROGRESS]  Active development
  [BLOCKED]      Waiting on dependencies
  [NEEDS_REVIEW] Requires attention

Examples:
  status sweep
  status sweep --fix
  status update ./pipeline --phase complete
  status update ./tests --task "Add chaos tests" --phase in_progress
  status dashboard
  status init ./new-module

Documentation: /opt/agent-governance/docs/STATUS_PROTOCOL.md
EOF
    exit 0
fi

# Verify status script exists
if [[ ! -f "${STATUS_SCRIPT}" ]]; then
    echo "Error: status.py not found at ${STATUS_SCRIPT}"
    exit 1
fi

# Execute status command
exec python3 "${STATUS_SCRIPT}" "$@"
