#!/bin/bash
# Launch Claude Code with plugin development environment
#
# Usage:
#   ./bin/claude-dev              # Start Claude in plugin dev mode
#   ./bin/claude-dev --resume     # Resume previous session
#   ./bin/claude-dev -p "prompt"  # Start with a prompt
#
# This script sets CLAUDE_PLUGIN_ROOT so hooks work correctly
# when developing the plugin itself (vs using it in another repo).
#
# Note: --dangerously-skip-permissions is enabled by default for dev workflow.

set -euo pipefail

# Resolve plugin root (parent of bin directory)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export CLAUDE_PLUGIN_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Enable LSP tool for code intelligence
export ENABLE_LSP_TOOL=1

# Avoid slow or hanging hooks in dev mode unless explicitly disabled
: "${ORCHESTKIT_SKIP_SETUP:=1}"
: "${ORCHESTKIT_SKIP_SLOW_HOOKS:=1}"
export ORCHESTKIT_SKIP_SETUP ORCHESTKIT_SKIP_SLOW_HOOKS

# Note: ANTHROPIC_API_KEY not needed for Claude Code (uses claude.ai login)
# Only needed for standalone bin/memory-fabric-agent.py script
# If you need it, run: export ANTHROPIC_API_KEY manually before the script

# Explicitly unset API key to avoid auth conflicts with claude.ai
unset ANTHROPIC_API_KEY 2>/dev/null || true

# Optional: Show dev mode indicator
if [[ "${CLAUDE_DEV_QUIET:-0}" != "1" ]]; then
    echo "🔧 Plugin dev mode: CLAUDE_PLUGIN_ROOT=$CLAUDE_PLUGIN_ROOT"
fi

exec claude --dangerously-skip-permissions "$@"