{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Nightly Code Configuration Schema",
  "type": "object",
  "properties": {
    "session": {
      "type": "object",
      "description": "Session-level configuration settings",
      "properties": {
        "max_duration": {
          "type": "integer",
          "minimum": 300,
          "maximum": 28800,
          "default": 28800,
          "description": "Maximum session duration in seconds (default: 8 hours)"
        },
        "time_zone": {
          "type": "string",
          "default": "UTC",
          "description": "Timezone for scheduling and logging"
        },
        "max_concurrent_tasks": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5,
          "default": 1,
          "description": "Maximum number of tasks to run concurrently"
        },
        "checkpoint_interval": {
          "type": "integer",
          "minimum": 60,
          "maximum": 3600,
          "default": 300,
          "description": "Interval between checkpoints in seconds"
        }
      },
      "additionalProperties": false
    },
    
    "project": {
      "type": "object",
      "description": "Project-specific configuration",
      "properties": {
        "root_directory": {
          "type": "string",
          "default": "./",
          "description": "Root directory of the project"
        },
        "package_manager": {
          "type": "string",
          "enum": ["npm", "yarn", "pnpm", "pip", "cargo", "go"],
          "default": "npm",
          "description": "Package manager used by the project"
        },
        "test_command": {
          "type": "string",
          "default": "",
          "description": "Command to run tests"
        },
        "lint_command": {
          "type": "string",
          "default": "",
          "description": "Command to run linting"
        },
        "build_command": {
          "type": "string",
          "default": "",
          "description": "Command to build the project"
        },
        "setup_commands": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": [],
          "description": "Commands to run before starting the session"
        }
      },
      "additionalProperties": false
    },
    
    "git": {
      "type": "object",
      "description": "Git integration settings",
      "properties": {
        "branch_prefix": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9-_]+$",
          "default": "nightly-",
          "description": "Prefix for automatically created branches"
        },
        "auto_push": {
          "type": "boolean",
          "default": true,
          "description": "Automatically push branches to remote"
        },
        "create_pr": {
          "type": "boolean",
          "default": true,
          "description": "Automatically create pull requests"
        },
        "pr_template": {
          "type": "string",
          "default": "",
          "description": "Path to pull request template file"
        },
        "pr_strategy": {
          "type": "string",
          "enum": ["task", "session"],
          "default": "task",
          "description": "PR creation strategy: 'task' for one PR per task, 'session' for one PR per session"
        },
        "cleanup_branches": {
          "type": "boolean",
          "default": false,
          "description": "Clean up branches after session completion"
        }
      },
      "additionalProperties": false
    },
    
    "validation": {
      "type": "object",
      "description": "Validation and quality control settings",
      "properties": {
        "skip_tests": {
          "type": "boolean",
          "default": false,
          "description": "Skip running tests during validation"
        },
        "skip_lint": {
          "type": "boolean",
          "default": false,
          "description": "Skip running linting during validation"
        },
        "skip_build": {
          "type": "boolean",
          "default": false,
          "description": "Skip running build during validation"
        },
        "custom_validators": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "description": "Name of the custom validator"
              },
              "command": {
                "type": "string",
                "description": "Command to run for validation"
              },
              "timeout": {
                "type": "integer",
                "minimum": 1,
                "maximum": 3600,
                "default": 300,
                "description": "Timeout for the validator in seconds"
              },
              "required": {
                "type": "boolean",
                "default": true,
                "description": "Whether this validator must pass"
              }
            },
            "required": ["name", "command"],
            "additionalProperties": false
          },
          "default": [],
          "description": "Custom validation commands"
        }
      },
      "additionalProperties": false
    },
    
    "notifications": {
      "type": "object",
      "description": "Notification settings",
      "properties": {
        "email": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": false,
              "description": "Enable email notifications"
            },
            "smtp_host": {
              "type": "string",
              "description": "SMTP server hostname"
            },
            "smtp_port": {
              "type": "integer",
              "minimum": 1,
              "maximum": 65535,
              "default": 587,
              "description": "SMTP server port"
            },
            "smtp_secure": {
              "type": "boolean",
              "default": false,
              "description": "Use secure connection (TLS)"
            },
            "smtp_user": {
              "type": "string",
              "description": "SMTP username"
            },
            "smtp_pass": {
              "type": "string",
              "description": "SMTP password"
            },
            "from": {
              "type": "string",
              "format": "email",
              "description": "From email address"
            },
            "to": {
              "type": "array",
              "items": {
                "type": "string",
                "format": "email"
              },
              "description": "Recipient email addresses"
            }
          },
          "additionalProperties": false,
          "if": {
            "properties": {
              "enabled": {
                "const": true
              }
            }
          },
          "then": {
            "required": ["smtp_host", "smtp_user", "smtp_pass", "from", "to"]
          }
        },
        
        "slack": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": false,
              "description": "Enable Slack notifications"
            },
            "webhook_url": {
              "type": "string",
              "format": "uri",
              "description": "Slack webhook URL"
            },
            "channel": {
              "type": "string",
              "default": "#general",
              "description": "Slack channel to post to"
            }
          },
          "additionalProperties": false,
          "if": {
            "properties": {
              "enabled": {
                "const": true
              }
            }
          },
          "then": {
            "required": ["webhook_url"]
          }
        },
        
        "webhook": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": false,
              "description": "Enable webhook notifications"
            },
            "url": {
              "type": "string",
              "format": "uri",
              "description": "Webhook URL"
            },
            "method": {
              "type": "string",
              "enum": ["POST", "PUT"],
              "default": "POST",
              "description": "HTTP method for webhook"
            },
            "headers": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              },
              "default": {},
              "description": "Additional headers for webhook"
            }
          },
          "additionalProperties": false,
          "if": {
            "properties": {
              "enabled": {
                "const": true
              }
            }
          },
          "then": {
            "required": ["url"]
          }
        }
      },
      "additionalProperties": false
    },
    
    "rate_limiting": {
      "type": "object",
      "description": "Rate limiting and retry configuration for Claude AI",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Enable rate limiting and retry logic"
        },
        "max_retries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 20,
          "default": 5,
          "description": "Maximum number of retries for rate-limited requests"
        },
        "base_delay": {
          "type": "integer",
          "minimum": 5000,
          "maximum": 300000,
          "default": 60000,
          "description": "Base delay in milliseconds before first retry (default: 60 seconds)"
        },
        "max_delay": {
          "type": "integer",
          "minimum": 60000,
          "maximum": 18000000,
          "default": 18000000,
          "description": "Maximum delay in milliseconds for usage limit retries (default: 5 hours)"
        },
        "exponential_backoff": {
          "type": "boolean",
          "default": true,
          "description": "Use exponential backoff for retry delays"
        },
        "jitter": {
          "type": "boolean",
          "default": true,
          "description": "Add random jitter to retry delays"
        },
        "usage_limit_retry": {
          "type": "boolean",
          "default": true,
          "description": "Retry when usage limits are reached"
        },
        "rate_limit_retry": {
          "type": "boolean",
          "default": true,
          "description": "Retry when rate limits are reached"
        }
      },
      "additionalProperties": false
    },
    
    "security": {
      "type": "object",
      "description": "Security and safety settings",
      "properties": {
        "allowed_commands": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": [],
          "description": "Whitelist of allowed commands (empty = allow all)"
        },
        "blocked_patterns": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": [],
          "description": "Patterns to block in generated code"
        },
        "max_file_size": {
          "type": "integer",
          "minimum": 1,
          "default": 10485760,
          "description": "Maximum file size to process in bytes (default: 10MB)"
        },
        "sandbox_mode": {
          "type": "boolean",
          "default": false,
          "description": "Run in sandbox mode with restricted access"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}