# iFlow CLI官方Hook配置文件
# 基于iFlow CLI官方文档的9种Hook类型配置

# 跨CLI集成系统配置
cross_cli_integration:
  enabled: true
  adapter: "IFlowOfficialHookAdapter"
  version: "1.0.0"

# iFlow官方Hook配置
hooks:
  # 1. PreToolUse - 工具执行前触发
  PreToolUse:
    - matcher: "*"  # 匹配所有工具
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter PreToolUse"
          timeout: 30
          description: "检测跨CLI调用意图和工具拦截"
    - matcher: "Edit|Write|Replace"  # 专门匹配文件编辑工具
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter PreToolUse"
          timeout: 15
          description: "文件编辑工具的跨CLI检测"

  # 2. PostToolUse - 工具执行后触发
  PostToolUse:
    - matcher: "*"
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter PostToolUse"
          timeout: 15
          description: "工具执行结果处理"

  # 3. SetUpEnvironment - 环境设置时触发
  SetUpEnvironment:
    - hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter SetUpEnvironment"
          timeout: 30
          description: "初始化跨CLI环境"

  # 4. Stop - 主会话结束时触发
  Stop:
    - hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter Stop"
          timeout: 10
          description: "清理跨CLI资源"

  # 5. SubagentStop - 子代理会话结束时触发
  SubagentStop:
    - hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter SubagentStop"
          timeout: 10
          description: "清理子代理资源"

  # 6. SessionStart - 会话开始时触发
  SessionStart:
    - matcher: "startup|resume"  # 匹配新启动和恢复的会话
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter SessionStart"
          timeout: 15
          description: "会话开始时的跨CLI环境设置"
    - matcher: "clear|compress"  # 匹配清理和压缩会话
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter SessionStart"
          timeout: 10
          description: "特殊会话类型的处理"

  # 7. SessionEnd - 会话结束时触发
  SessionEnd:
    - hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter SessionEnd"
          timeout: 15
          description: "会话结束时的跨CLI总结"

  # 8. UserPromptSubmit - 用户提示词提交时触发
  UserPromptSubmit:
    - matcher: ".*"  # 匹配所有用户提示词
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter UserPromptSubmit"
          timeout: 30
          description: "核心跨CLI调用检测"
    - matcher: ".*claude.*|.*gemini.*|.*qwencode.*|.*qoder.*|.*codebuddy.*|.*codex.*"
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter UserPromptSubmit"
          timeout: 45
          description: "包含CLI名称的提示词优先处理"

  # 9. Notification - 通知发送时触发
  Notification:
    - matcher: ".*"  # 匹配所有通知
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter Notification"
          timeout: 10
          description: "跨CLI状态通知"
    - matcher: ".*permission.*|.*error.*|.*warning.*"
      hooks:
        - type: "command"
          command: "python -m src.adapters.iflow.official_hook_adapter Notification"
          timeout: 5
          description: "重要通知的特殊处理"

    # 插件配置
    config:
      # 跨CLI功能配置
      cross_cli_enabled: true
      collaboration_mode: "active"  # active, passive, disabled
      auto_detection: true

      # 性能配置
      timeout: 30
      max_concurrent_calls: 5
      retry_count: 3
      retry_delay: 1

      # 错误处理配置
      error_handling: "continue"   # continue, abort, fallback
      fallback_to_iflow: true
      show_error_details: true

      # 协作配置
      collaboration_enabled: true
      project_spec_enabled: true
      auto_collaboration: false

      # 事件配置
      event_bus_enabled: true
      event_logging: true
      performance_monitoring: true

# Hook事件配置
hook_events:
  # 用户输入事件
  on_user_input:
    description: "用户输入时触发，用于检测跨CLI调用意图"
    priority: 100
    async: true
    timeout: 10

  # 命令生命周期事件
  on_command_start:
    description: "命令开始执行时触发"
    priority: 90
    async: true
    timeout: 5

  on_command_end:
    description: "命令执行完成时触发"
    priority: 90
    async: true
    timeout: 5

  # 工作流事件
  on_workflow_stage:
    description: "工作流阶段执行时触发"
    priority: 80
    async: true
    timeout: 15

  on_pipeline_execute:
    description: "流水线执行时触发"
    priority: 70
    async: true
    timeout: 20

  # 错误处理事件
  on_error:
    description: "错误发生时触发"
    priority: 95
    async: true
    timeout: 5

  # 输出处理事件
  on_output_render:
    description: "输出渲染时触发"
    priority: 60
    async: true
    timeout: 10

# 协作协议配置
collaboration_protocols:
  # 中文协议
  chinese:
    - pattern: "请用{cli}帮我{task}"
      priority: 100
    - pattern: "调用{cli}来{task}"
      priority: 95
    - pattern: "用{cli}帮我{task}"
      priority: 90
    - pattern: "让{cli}帮我{task}"
      priority: 85
    - pattern: "启动{cli}工作流{task}"
      priority: 80
    - pattern: "通过{cli}执行{task}"
      priority: 75

  # 英文协议
  english:
    - pattern: "use {cli} to {task}"
      priority: 100
    - pattern: "call {cli} to {task}"
      priority: 95
    - pattern: "ask {cli} for {task}"
      priority: 90
    - pattern: "start {cli} workflow for {task}"
      priority: 85
    - pattern: "execute {task} with {cli}"
      priority: 80
    - pattern: "process {task} using {cli}"
      priority: 75

# 支持的CLI工具
supported_clis:
  - name: "claude"
    display_name: "Claude CLI"
    description: "Anthropic Claude CLI工具"
    integration_type: "hook"

  - name: "gemini"
    display_name: "Gemini CLI"
    description: "Google Gemini CLI工具"
    integration_type: "extension"

  - name: "qwencode"
    display_name: "QwenCode CLI"
    description: "阿里巴巴QwenCode CLI工具"
    integration_type: "inheritance"

  - name: "qoder"
    display_name: "Qoder CLI"
    description: "Qoder编程助手CLI工具"
    integration_type: "plugin"

  - name: "codebuddy"
    display_name: "CodeBuddy CLI"
    description: "CodeBuddy编程助手CLI工具"
    integration_type: "buddy"

  - name: "codex"
    display_name: "Codex CLI"
    description: "OpenAI Codex CLI工具"
    integration_type: "extension"

# 事件总线配置
event_bus:
  enabled: true
  buffer_size: 1000
  async_dispatch: true

  # 事件监听器
  listeners:
    - event: "cross_cli_detected"
      handler: "handle_cross_cli_detected"
      async: true

    - event: "workflow_started"
      handler: "handle_workflow_started"
      async: true

    - event: "workflow_completed"
      handler: "handle_workflow_completed"
      async: true

    - event: "error_occurred"
      handler: "handle_error_occurred"
      async: true

# 性能监控配置
performance_monitoring:
  enabled: true
  metrics:
    - "hook_execution_time"
    - "cross_cli_call_count"
    - "success_rate"
    - "error_count"
    - "response_time"

  # 报告配置
  reporting:
    interval: 60  # 秒
    log_file: "~/.config/iflow/logs/performance.log"
    max_file_size: "10MB"

# 日志配置
logging:
  level: "INFO"
  format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

  # 日志文件
  handlers:
    - type: "file"
      filename: "~/.config/iflow/logs/hooks.log"
      max_size: "20MB"
      backup_count: 5

    - type: "console"
      enabled: true

# 安全配置
security:
  # 输入验证
  input_validation:
    enabled: true
    max_length: 10000
    sanitize_html: true

  # 权限检查
  permission_check:
    enabled: true
    check_file_access: true

  # 审计日志
  audit_logging:
    enabled: true
    log_file: "~/.config/iflow/logs/audit.log"

# 缓存配置
cache:
  enabled: true
  ttl: 300  # 5分钟
  max_size: "100MB"

  # 缓存策略
  strategies:
    - "result_cache"      # 结果缓存
    - "adapter_cache"     # 适配器缓存
    - "config_cache"      # 配置缓存