"""Core module for claude-ctx - refactored into domain-specific submodules.

This __init__.py provides backward compatibility by re-exporting all functions
from the submodules, allowing existing code to continue using:
    from claude_ctx_py.core import function_name

The module is now organized as:
- base.py: Utility functions and constants
- agents.py: Agent management
- skills.py: Skill management
- rules.py: Rule management
- mcp.py: MCP server management
- worktrees.py: Git worktree management
- hooks.py: Hook management
- backup.py: Backup management
- context_export.py: Context export functionality
"""

# Re-export optional dependency handle for compatibility
try:  # pragma: no cover - optional dependency
    import yaml
except ImportError:  # pragma: no cover
    yaml = None  # type: ignore[assignment]

# Export all constants
from .base import (
    BLUE,
    GREEN,
    YELLOW,
    RED,
    NC,
    FrontMatterToken,
)

# Export all functions from base
from .base import (
    _color,
    _resolve_cortex_root,
    _resolve_claude_dir,
    _resolve_init_dirs,
    _ensure_claude_structure,
    _init_slug_for_path,
    _strip_ansi_codes,
    _run_detection_command,
    _run_detect_project_type,
    _run_analyze_project,
    _is_disabled,
    _iter_md_files,
    _iter_all_files,
    _parse_active_entries,
    _write_active_entries,
    _update_with_backup,
    _uncomment_rule_line,
    _comment_rule_line,
    _remove_exact_entries,
    _parse_claude_md_refs,
    _extract_front_matter,
    _tokenize_front_matter,
    _strip_inline_comment,
    _clean_scalar,
    _inactive_category_dir,
    _ensure_inactive_category_dir,
    _inactive_dir_candidates,
    _parse_inline_list,
    _find_key,
    _locate_path,
    _collect_list_items,
    _extract_values_for_path,
    _extract_values_from_paths,
    _extract_scalar_from_paths,
    _backup_config,
    _render_section,
    _refresh_claude_md,
    _load_yaml,
    _load_yaml_dict,
    _flatten_mixed,
    _ensure_list,
    _now_iso,
    _load_detection_file,
    _resolve_init_target,
    _prompt_user,
    _confirm,
    _format_detection_summary,
    _format_header,
    _parse_selection,
    _append_session_log,
    _list_available_agents,
    show_status,
)

# Export all functions from agents
from .agents import (
    AgentGraphNode,
    _agent_basename,
    _normalize_agent_filename,
    _find_disabled_agent_file,
    _find_agent_file_any_state,
    _normalize_dependency_name,
    _parse_agent_dependencies,
    _read_agent_front_matter_lines,
    _parse_agent_metadata_name,
    _parse_dependencies_from_front,
    _display_agent_name,
    _extract_agent_name,
    _generate_dependency_map,
    _active_agent_files,
    _find_agent_dependents,
    build_agent_graph,
    _format_dependency_entries,
    render_agent_graph,
    export_agent_graph,
    agent_graph,
    _iter_agent_paths,
    _resolve_agent_validation_target,
    _load_agent_schema,
    agent_validate,
    _agent_activate_recursive,
    agent_activate,
    agent_deactivate,
    list_agents,
    agent_status,
    agent_deps,
)

# Export all functions from skills
from .skills import (
    list_skills,
    skill_info,
    skill_versions,
    skill_validate,
    skill_analyze,
    skill_deps,
    skill_agents,
    skill_suggest,
    skill_metrics,
    skill_metrics_reset,
    skill_analytics,
    skill_report,
    skill_trending,
    skill_compose,
    skill_context,
    skill_recommend,
    skill_feedback,
    skill_rate,
    skill_ratings,
    skill_top_rated,
    skill_ratings_export,
    skill_community_list,
    skill_community_install,
    skill_community_validate,
    skill_community_rate,
    skill_community_search,
)

# Export all functions from rules
from .rules import (
    rules_status,
    rules_activate,
    rules_deactivate,
    list_rules,
)

# Export all functions from codex_skills (provider-based + backward-compat)
from .codex_skills import (
    # Types and constants
    SkillProvider,
    SKILL_PROVIDERS,
    PROVIDER_LABELS,
    PROVIDER_ICONS,
    # Provider-parameterized functions
    _resolve_provider_skills_dir,
    _resolve_provider_native_skills_dir,
    scan_provider_native_skills,
    scan_provider_skill_status,
    link_provider_skill,
    unlink_provider_skill,
    link_provider_skills_by_category,
    unlink_provider_skills_by_category,
    link_all_provider_skills,
    unlink_all_provider_skills,
    # Backward-compatible codex wrappers
    scan_codex_skill_status,
    scan_codex_native_skills,
    _resolve_codex_native_skills_dir,
    link_codex_skill,
    unlink_codex_skill,
    link_codex_skills_by_category,
    unlink_codex_skills_by_category,
    link_all_codex_skills,
    unlink_all_codex_skills,
)

# Export all functions from worktrees
from .worktrees import (
    WorktreeInfo,
    worktree_discover,
    worktree_list,
    worktree_default_path,
    worktree_get_base_dir,
    worktree_set_base_dir,
    worktree_clear_base_dir,
    worktree_add,
    worktree_remove,
    worktree_prune,
)

# Export all functions from context_export
from .context_export import (
    collect_context_components,
    export_agents,
    export_context,
    list_context_components,
)

# Export all functions from mcp
from .mcp import (
    MCPServerInfo,
    MCPServerCapabilities,
    MCPConfigError,
    MCPServerNotFoundError,
    discover_servers,
    list_doc_only_servers,
    get_server_info,
    list_server_tools,
    get_server_docs_path,
    validate_server_config,
    generate_config_snippet,
    list_available_servers,
    get_server_command_line,
    export_servers_list,
    mcp_list,
    mcp_show,
    mcp_docs,
    mcp_test,
    mcp_diagnose,
    mcp_snippet,
    list_doc_only_servers,
    # MCP docs activation
    mcp_activate,
    mcp_deactivate,
    mcp_list_docs,
    mcp_docs_status,
)


# Export hooks functions
from .hooks import (
    HookDefinition,
    InstalledHook,
    HOOK_EVENTS,
    get_settings_path,
    load_settings,
    save_settings,
    get_installed_hooks,
    get_available_hooks,
    parse_hook_file,
    install_hook,
    uninstall_hook,
    get_hook_events,
    create_hook_template,
    validate_hooks_config,
    validate_hooks_config_file,
)

# Export backup functions
from .backup import (
    BackupInfo,
    get_backup_dir,
    create_backup,
    list_backups,
    restore_backup,
    delete_backup,
    get_backup_summary,
    auto_cleanup_backups,
)

__all__ = [
    # Constants
    "BLUE",
    "GREEN",
    "YELLOW",
    "RED",
    "NC",
    "yaml",
    "FrontMatterToken",
    # Dataclasses
    "AgentGraphNode",
    # Base functions
    "_color",
    "_resolve_cortex_root",
    "_resolve_claude_dir",
    "_resolve_init_dirs",
    "_ensure_claude_structure",
    "_init_slug_for_path",
    "_strip_ansi_codes",
    "_run_detection_command",
    "_run_detect_project_type",
    "_run_analyze_project",
    "_is_disabled",
    "_iter_md_files",
    "_iter_all_files",
    "_parse_active_entries",
    "_write_active_entries",
    "_update_with_backup",
    "_uncomment_rule_line",
    "_comment_rule_line",
    "_remove_exact_entries",
    "_parse_claude_md_refs",
    "_extract_front_matter",
    "_tokenize_front_matter",
    "_strip_inline_comment",
    "_clean_scalar",
    "_inactive_category_dir",
    "_ensure_inactive_category_dir",
    "_inactive_dir_candidates",
    "_parse_inline_list",
    "_find_key",
    "_locate_path",
    "_collect_list_items",
    "_extract_values_for_path",
    "_extract_values_from_paths",
    "_extract_scalar_from_paths",
    "_backup_config",
    "_render_section",
    "_refresh_claude_md",
    "_load_yaml",
    "_load_yaml_dict",
    "_flatten_mixed",
    "_ensure_list",
    "_now_iso",
    "_load_detection_file",
    "_resolve_init_target",
    "_prompt_user",
    "_confirm",
    "_format_detection_summary",
    "_format_header",
    "_parse_selection",
    "_append_session_log",
    "_list_available_agents",
    "show_status",
    # Agent functions
    "_agent_basename",
    "_normalize_agent_filename",
    "_find_disabled_agent_file",
    "_find_agent_file_any_state",
    "_normalize_dependency_name",
    "_parse_agent_dependencies",
    "_read_agent_front_matter_lines",
    "_parse_agent_metadata_name",
    "_parse_dependencies_from_front",
    "_display_agent_name",
    "_extract_agent_name",
    "_generate_dependency_map",
    "_active_agent_files",
    "_find_agent_dependents",
    "build_agent_graph",
    "_format_dependency_entries",
    "render_agent_graph",
    "export_agent_graph",
    "agent_graph",
    "_iter_agent_paths",
    "_resolve_agent_validation_target",
    "_load_agent_schema",
    "agent_validate",
    "_agent_activate_recursive",
    "agent_activate",
    "agent_deactivate",
    "list_agents",
    "agent_status",
    "agent_deps",
    # Skill functions
    "list_skills",
    "skill_info",
    "skill_versions",
    "skill_validate",
    "skill_analyze",
    "skill_deps",
    "skill_agents",
    "skill_suggest",
    "skill_metrics",
    "skill_metrics_reset",
    "skill_analytics",
    "skill_report",
    "skill_trending",
    "skill_compose",
    "skill_context",
    "skill_recommend",
    "skill_feedback",
    "skill_rate",
    "skill_ratings",
    "skill_top_rated",
    "skill_ratings_export",
    "skill_community_list",
    "skill_community_install",
    "skill_community_validate",
    "skill_community_rate",
    "skill_community_search",
    # Rule functions
    "rules_status",
    "rules_activate",
    "rules_deactivate",
    "list_rules",
    # Provider skills types and constants
    "SkillProvider",
    "SKILL_PROVIDERS",
    "PROVIDER_LABELS",
    "PROVIDER_ICONS",
    # Provider-parameterized skill functions
    "_resolve_provider_skills_dir",
    "_resolve_provider_native_skills_dir",
    "scan_provider_native_skills",
    "scan_provider_skill_status",
    "link_provider_skill",
    "unlink_provider_skill",
    "link_provider_skills_by_category",
    "unlink_provider_skills_by_category",
    "link_all_provider_skills",
    "unlink_all_provider_skills",
    # Codex skills functions (backward-compat)
    "scan_codex_skill_status",
    "scan_codex_native_skills",
    "_resolve_codex_native_skills_dir",
    "link_codex_skill",
    "unlink_codex_skill",
    "link_codex_skills_by_category",
    "unlink_codex_skills_by_category",
    "link_all_codex_skills",
    "unlink_all_codex_skills",
    # Worktree functions
    "WorktreeInfo",
    "worktree_discover",
    "worktree_list",
    "worktree_default_path",
    "worktree_get_base_dir",
    "worktree_set_base_dir",
    "worktree_clear_base_dir",
    "worktree_add",
    "worktree_remove",
    "worktree_prune",
    # Context export functions
    "collect_context_components",
    "export_agents",
    "export_context",
    "list_context_components",
    # MCP functions
    "MCPServerInfo",
    "MCPServerCapabilities",
    "MCPConfigError",
    "MCPServerNotFoundError",
    "discover_servers",
    "get_server_info",
    "list_server_tools",
    "get_server_docs_path",
    "validate_server_config",
    "generate_config_snippet",
    "list_available_servers",
    "get_server_command_line",
    "export_servers_list",
    "mcp_list",
    "mcp_show",
    "mcp_docs",
    "mcp_test",
    "mcp_diagnose",
    "mcp_snippet",
    "list_doc_only_servers",
    # MCP docs activation
    "mcp_activate",
    "mcp_deactivate",
    "mcp_list_docs",
    "mcp_docs_status",
    # Hooks functions
    "HookDefinition",
    "InstalledHook",
    "HOOK_EVENTS",
    "get_settings_path",
    "load_settings",
    "save_settings",
    "get_installed_hooks",
    "get_available_hooks",
    "parse_hook_file",
    "install_hook",
    "uninstall_hook",
    "get_hook_events",
    "create_hook_template",
    "validate_hooks_config",
    "validate_hooks_config_file",
    # Backup functions
    "BackupInfo",
    "get_backup_dir",
    "create_backup",
    "list_backups",
    "restore_backup",
    "delete_backup",
    "get_backup_summary",
    "auto_cleanup_backups",
]
