# Tool Safety Limits Configuration
# Controls per-tool: timeout, input/output sizes, rate limits, concurrency.
# Applied by tool_governance.py middleware before dispatch.

# ─── Global Defaults ─────────────────────────────────────────────────────────
defaults:
  timeout_ms: 30000           # 30s
  max_chars_in: 200000        # 200KB input
  max_bytes_out: 524288       # 512KB output
  rate_limit_rpm: 60          # 60 req/min per agent
  concurrency: 5              # max parallel calls per agent

# ─── Per-Tool Overrides ───────────────────────────────────────────────────────
tools:

  repo_tool:
    timeout_ms: 10000
    max_chars_in: 10000        # path + params only, not file content input
    max_bytes_out: 524288      # 512KB (file read result)
    rate_limit_rpm: 120

  kb_tool:
    timeout_ms: 15000
    max_chars_in: 5000
    max_bytes_out: 262144      # 256KB
    rate_limit_rpm: 60

  oncall_tool:
    timeout_ms: 10000
    max_chars_in: 10000
    max_bytes_out: 131072      # 128KB
    rate_limit_rpm: 30
    concurrency: 3
    actions:
      incident_followups_summary:
        timeout_ms: 10000
        rate_limit_rpm: 10

  incident_escalation_tool:
    timeout_ms: 30000
    max_bytes_out: 524288
    rate_limit_rpm: 10

  risk_engine_tool:
    actions:
      service:
        timeout_seconds: 10
        rpm: 20
      dashboard:
        timeout_seconds: 20
        rpm: 5
      policy:
        timeout_seconds: 2
        rpm: 60

  risk_history_tool:
    actions:
      snapshot:
        timeout_seconds: 60
        rpm: 1
      cleanup:
        timeout_seconds: 30
        rpm: 2
      series:
        timeout_seconds: 5
        rpm: 30
      digest:
        timeout_seconds: 30
        rpm: 2

  incident_intelligence_tool:
    timeout_ms: 30000
    max_bytes_out: 524288      # 512KB (digests can be large)
    rate_limit_rpm: 5
    actions:
      correlate:
        timeout_ms: 10000
        rate_limit_rpm: 10
      recurrence:
        timeout_ms: 15000
        rate_limit_rpm: 5
      buckets:
        timeout_ms: 15000
        rate_limit_rpm: 5
      weekly_digest:
        timeout_ms: 30000      # longer: writes artifacts + autofollowups
        rate_limit_rpm: 2

  alert_ingest_tool:
    timeout_ms: 5000
    max_chars_in: 32768           # 32KB — alert payload cap
    max_bytes_out: 65536          # 64KB
    rate_limit_rpm: 60            # monitor can send up to 60 alerts/min
    concurrency: 5
    actions:
      ingest:
        rate_limit_rpm: 60        # monitor rate: 1/s
      list:
        rate_limit_rpm: 30
        timeout_ms: 5000
      ack:
        rate_limit_rpm: 20
      claim:
        rate_limit_rpm: 10
        timeout_ms: 5000
      fail:
        rate_limit_rpm: 20

  observability_tool:
    timeout_ms: 15000
    max_chars_in: 5000
    max_bytes_out: 524288      # 512KB (metrics can be large)
    rate_limit_rpm: 30
    concurrency: 3
    actions:
      slo_snapshot:
        timeout_ms: 10000
        rate_limit_rpm: 30

  pr_reviewer_tool:
    timeout_ms: 60000          # 60s (diff analysis can be slow)
    max_chars_in: 409600       # 400KB (diff text)
    max_bytes_out: 262144      # 256KB
    rate_limit_rpm: 10
    concurrency: 2

  contract_tool:
    timeout_ms: 30000
    max_chars_in: 819200       # 800KB (openapi specs)
    max_bytes_out: 262144
    rate_limit_rpm: 20

  config_linter_tool:
    timeout_ms: 30000
    max_chars_in: 409600       # 400KB
    max_bytes_out: 131072
    rate_limit_rpm: 20

  threatmodel_tool:
    timeout_ms: 30000
    max_chars_in: 614400       # 600KB
    max_bytes_out: 262144
    rate_limit_rpm: 10

  job_orchestrator_tool:
    timeout_ms: 600000         # 10 min (job execution)
    max_chars_in: 10000
    max_bytes_out: 131072
    rate_limit_rpm: 10
    concurrency: 2

  memory_search:
    timeout_ms: 5000
    max_chars_in: 2000
    max_bytes_out: 65536
    rate_limit_rpm: 120

  graph_query:
    timeout_ms: 5000
    max_chars_in: 2000
    max_bytes_out: 65536
    rate_limit_rpm: 60

  web_search:
    timeout_ms: 15000
    max_chars_in: 500
    max_bytes_out: 131072
    rate_limit_rpm: 30

  web_extract:
    timeout_ms: 30000
    max_chars_in: 2000
    max_bytes_out: 524288
    rate_limit_rpm: 20

  crawl4ai_scrape:
    timeout_ms: 60000
    max_chars_in: 2000
    max_bytes_out: 1048576     # 1MB
    rate_limit_rpm: 10

  image_generate:
    timeout_ms: 60000
    max_chars_in: 5000
    max_bytes_out: 5242880     # 5MB (base64 image)
    rate_limit_rpm: 5
    concurrency: 1

  comfy_generate_image:
    timeout_ms: 120000
    max_chars_in: 5000
    max_bytes_out: 10485760    # 10MB
    rate_limit_rpm: 3
    concurrency: 1

  comfy_generate_video:
    timeout_ms: 300000
    max_chars_in: 5000
    max_bytes_out: 52428800    # 50MB
    rate_limit_rpm: 1
    concurrency: 1

  tts_speak:
    timeout_ms: 30000
    max_chars_in: 5000
    max_bytes_out: 5242880
    rate_limit_rpm: 10

  presentation_create:
    timeout_ms: 120000
    max_chars_in: 100000
    max_bytes_out: 20971520    # 20MB
    rate_limit_rpm: 5

  file_tool:
    timeout_ms: 60000
    max_chars_in: 524288
    max_bytes_out: 20971520
    rate_limit_rpm: 10

  data_governance_tool:
    timeout_ms: 30000          # 30s (file I/O + regex scanning)
    max_chars_in: 3000         # params only
    max_bytes_out: 1048576     # 1MB (findings list can be verbose)
    rate_limit_rpm: 5          # read-heavy, limit frequency
    concurrency: 1             # serial: filesystem-bound
    actions:
      digest_audit:
        timeout_ms: 20000
        rate_limit_rpm: 5

  cost_analyzer_tool:
    timeout_ms: 30000          # raised: Postgres queries may take longer
    max_chars_in: 2000         # params only
    max_bytes_out: 1048576     # 1MB (report may include many breakdowns)
    rate_limit_rpm: 10         # light reads, allow more
    concurrency: 2
    actions:
      digest:
        timeout_ms: 20000
        rate_limit_rpm: 5

  dependency_scanner_tool:
    timeout_ms: 45000          # 45s (online mode may need more time)
    max_chars_in: 3000         # params only
    max_bytes_out: 1048576     # 1MB (vuln list can be verbose)
    rate_limit_rpm: 5          # expensive scan
    concurrency: 1             # serial: avoids hammering OSV API

  drift_analyzer_tool:
    timeout_ms: 30000          # 30s (reads many files)
    max_chars_in: 5000         # params only, no large input
    max_bytes_out: 524288      # 512KB (findings can be verbose)
    rate_limit_rpm: 5          # expensive — limit calls
    concurrency: 1

  market_data:
    timeout_ms: 10000
    max_chars_in: 1000
    max_bytes_out: 65536
    rate_limit_rpm: 60

  architecture_pressure_tool:
    service:
      timeout_ms: 10000
      rate_limit_rpm: 30
    dashboard:
      timeout_ms: 20000
      rate_limit_rpm: 10
    digest:
      timeout_ms: 30000
      rate_limit_rpm: 2

  backlog_tool:
    list:
      timeout_ms: 10000
      rate_limit_rpm: 30
    get:
      timeout_ms: 5000
      rate_limit_rpm: 60
    dashboard:
      timeout_ms: 10000
      rate_limit_rpm: 20
    create:
      timeout_ms: 20000
      rate_limit_rpm: 5
    upsert:
      timeout_ms: 20000
      rate_limit_rpm: 5
    set_status:
      timeout_ms: 10000
      rate_limit_rpm: 10
    add_comment:
      timeout_ms: 5000
      rate_limit_rpm: 20
    close:
      timeout_ms: 10000
      rate_limit_rpm: 5
    auto_generate_weekly:
      timeout_ms: 30000
      rate_limit_rpm: 2
    cleanup:
      timeout_ms: 30000
      rate_limit_rpm: 2

  calendar_tool:
    timeout_ms: 30000
    max_chars_in: 12000
    max_bytes_out: 262144
    rate_limit_rpm: 20
    concurrency: 2

  agent_email_tool:
    timeout_ms: 30000
    max_chars_in: 10000
    max_bytes_out: 262144
    rate_limit_rpm: 10
    concurrency: 1

  browser_tool:
    timeout_ms: 60000
    max_chars_in: 8000
    max_bytes_out: 262144
    rate_limit_rpm: 8
    concurrency: 1

  safe_code_executor_tool:
    timeout_ms: 10000
    max_chars_in: 12000
    max_bytes_out: 131072
    rate_limit_rpm: 12
    concurrency: 2

  secure_vault_tool:
    timeout_ms: 15000
    max_chars_in: 4000
    max_bytes_out: 65536
    rate_limit_rpm: 20
    concurrency: 2
