{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "VeilCLI Settings",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "port": { "type": "integer", "minimum": 1, "maximum": 65535 },
    "secret": { "type": ["string", "null"] },
    "models": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "main": { "$ref": "#/definitions/modelConfig" },
        "compact": { "$ref": "#/definitions/modelConfig" },
        "title": { "$ref": "#/definitions/modelConfig" }
      }
    },
    "permissions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "allow": { "type": "array", "items": { "type": "string" } },
        "deny": { "type": "array", "items": { "type": "string" } },
        "ask": { "type": "array", "items": { "type": "string" } }
      }
    },
    "hooks": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "PreToolUse": { "type": ["string", "null"] },
        "PostToolUse": { "type": ["string", "null"] }
      }
    },
    "compaction": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "threshold": { "type": "number", "minimum": 0.1, "maximum": 1.0 },
        "observationMaskingTurns": { "type": "integer", "minimum": 0 }
      }
    },
    "memory": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean" },
        "maxLines": { "type": "integer", "minimum": 10 }
      }
    },
    "storage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "retention": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "sessions": { "$ref": "#/definitions/retentionPolicy" },
            "tasks": { "$ref": "#/definitions/retentionPolicy" }
          }
        }
      }
    },
    "maxIterations": { "type": "integer", "minimum": 1 },
    "maxDurationSeconds": { "type": "integer", "minimum": 1 },
    "maxConcurrentTasks": { "type": "integer", "minimum": 1 },
    "maxSubAgentDepth": { "type": "integer", "minimum": 1 },
    "mcpServers": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "command": { "type": "string" },
          "args": { "type": "array", "items": { "type": "string" } },
          "url": { "type": "string" }
        }
      }
    },
    "ably": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean" },
        "key": { "type": ["string", "null"] }
      }
    },
    "providers": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/providerConfig" }
    },
    "routing": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "default": { "type": ["string", "null"] },
        "fallback": { "type": "array", "items": { "type": "string" } },
        "per_model": {
          "type": "object",
          "additionalProperties": { "$ref": "#/definitions/routingRule" }
        },
        "per_agent": {
          "type": "object",
          "additionalProperties": { "$ref": "#/definitions/routingRule" }
        }
      }
    }
  },
  "definitions": {
    "modelConfig": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "properties": {
        "model": { "type": "string" },
        "base_url": { "type": "string" },
        "api_key": { "type": "string" },
        "temperature": { "type": "number", "minimum": 0, "maximum": 2 },
        "reasoning": { "type": "string" },
        "maxTokens": { "type": "integer", "minimum": 1 }
      }
    },
    "retentionPolicy": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "maxAgeDays": { "type": "integer", "minimum": 1 },
        "maxCount": { "type": "integer", "minimum": 1 }
      }
    },
    "providerConfig": {
      "type": "object",
      "required": ["type"],
      "additionalProperties": false,
      "properties": {
        "type": { "type": "string", "enum": ["openai", "claude-cli"] },
        "base_url": { "type": "string" },
        "api_key": { "type": "string" },
        "path": { "type": "string" },
        "permission_mode": { "type": "string", "enum": ["default", "acceptEdits", "bypassPermissions", "plan"] },
        "env": { "type": "object", "additionalProperties": { "type": "string" } }
      }
    },
    "routingRule": {
      "type": "object",
      "required": ["default"],
      "additionalProperties": false,
      "properties": {
        "default": { "type": "string" },
        "fallback": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
