{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Dave Schedule Definition",
  "description": "Defines a recurring scheduled task managed by the Dave scheduler",
  "type": "object",
  "required": ["id", "schedule", "command"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*[a-z0-9]$",
      "description": "Unique identifier for the schedule. Used in backend naming (com.{agent}.{id}, dave-{id}). Lowercase alphanumeric with hyphens."
    },
    "agent": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*[a-z0-9]$",
      "default": "dave",
      "description": "Agent that owns this schedule. Drives the launchd label prefix (com.{agent}.{id}); other backends are unaffected. Omit for the pre-existing default agent 'dave' — every schedule file without this field keeps producing exactly com.dave.{id}, unchanged."
    },
    "name": {
      "type": "string",
      "description": "Human-readable display name"
    },
    "schedule": {
      "type": "string",
      "pattern": "^[0-9*,/-]+ [0-9*,/-]+ [0-9*,/-]+ [0-9*,/-]+ [0-9*,/-]+$",
      "description": "Cron expression: minute hour day-of-month month day-of-week. This is the universal format -- install.mjs translates to the native backend format."
    },
    "command": {
      "type": "string",
      "description": "Shell command to execute. Runs via bash."
    },
    "workingDirectory": {
      "type": "string",
      "default": "${DAVE_ROOT}",
      "description": "Working directory for the command. Supports ${DAVE_ROOT} variable substitution."
    },
    "enabled": {
      "type": "boolean",
      "default": true,
      "description": "Whether the schedule is active. Disabled schedules are skipped by install.mjs."
    },
    "backend": {
      "type": ["string", "null"],
      "enum": ["cron", "launchd", "systemd", "schtasks", null],
      "default": null,
      "description": "Override the backend for this schedule. Null uses the deployment default from .dave/config.json."
    },
    "description": {
      "type": "string",
      "description": "Human-readable description of what this schedule does"
    },
    "host": {
      "type": "string",
      "description": "Device id or hostname this schedule is pinned to run on, matched against the current machine's hostname (exact, then short-name-before-first-dot) by `scheduler install` and `launch`. A mismatch refuses (exit 2) unless overridden (--force-host for install; DAVE_FORCE_HOST=1 for launch). Omit to skip host verification (data backfill onto existing schedule files is estate-side)."
    },
    "environment": {
      "type": "object",
      "description": "Environment variables to set for the scheduled process. Keys are variable names, values are strings supporting ${DAVE_ROOT}/${HOME}/${USER} substitution. On launchd, injected as EnvironmentVariables (merged over auto-injected PATH/HOME/DAVE_ROOT defaults; explicit keys win). On systemd, emitted as Environment= lines in [Service]. On cron, prepended as VAR='val' inline assignments before the command. On schtasks, emitted as `set VAR=val &&` pairs inside the cmd /c wrapper. WARNING: do NOT set PATH, HOME, or DAVE_ROOT here unless you genuinely need to override the installer's auto-injected values. On launchd in particular, an explicit PATH wins over withLaunchdDefaults() and almost always omits /opt/homebrew/bin, silently breaking brew-installed binaries on Apple Silicon. Use this block only for operator-meaningful keys (API_KEY, LOG_LEVEL, feature flags); leave PATH/HOME/DAVE_ROOT to the installer.",
      "additionalProperties": { "type": "string" }
    }
  },
  "additionalProperties": false
}
