/**
 * @fileoverview Environment Detector - Detects if running in Claude Code
 * @module morph-spec/llm/environment-detector
 */

/**
 * Detect if running inside Claude Code environment
 * @returns {boolean} True if Claude Code is available
 */
export function detectClaudeCode() {
  // Check for environment variables that Claude Code sets
  const claudeEnvVars = [
    'CLAUDE_CODE_SESSION',
    'CLAUDE_API_KEY',
    'ANTHROPIC_API_KEY'
  ];

  // Check if any Claude-specific env var is set
  const hasClaudeEnv = claudeEnvVars.some(varName => process.env[varName]);

  // Check if we can detect Claude Code CLI
  // (This is a heuristic - Claude Code sets these when running)
  const hasClaudeCLI = process.env.TERM_PROGRAM === 'claude' ||
                       process.env.CLAUDE_CODE_VERSION;

  return hasClaudeEnv || hasClaudeCLI;
}

/**
 * Get Claude Code version if available
 * @returns {string|null} Version string or null
 */
export function getClaudeCodeVersion() {
  return process.env.CLAUDE_CODE_VERSION || null;
}

/**
 * Check if running in interactive mode (user is present)
 * @returns {boolean} True if interactive
 */
export function isInteractive() {
  return process.stdout.isTTY && process.stdin.isTTY;
}
