{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/run-questions.schema.json",
  "title": "Run questions",
  "description": "Shape of run-questions.json: the Phase 0 pickers of a /multi-agent run as data. Every field is x-sensitivity none - the file ships with the package and describes questions, never a machine's answers.",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion", "questions"],
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "description": { "type": "string", "x-sensitivity": "none" },
    "questions": {
      "type": "array",
      "minItems": 1,
      "x-sensitivity": "none",
      "items": { "$ref": "#/$defs/question" }
    }
  },
  "$defs": {
    "question": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "asked-at", "answerable", "source"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*$",
          "x-sensitivity": "none",
          "description": "The key a launch request answers under."
        },
        "kind": {
          "enum": ["single-select", "multi-select", "dynamic"],
          "x-sensitivity": "none",
          "description": "dynamic: the questions themselves are produced during the run and cannot be answered in advance."
        },
        "asked-at": {
          "type": "string",
          "x-sensitivity": "none",
          "description": "Where in phase-0-init.md (or the file it names) the picker lives."
        },
        "answerable": {
          "type": "boolean",
          "x-sensitivity": "none",
          "description": "Whether a launch request may pre-fill it. false: the run always asks."
        },
        "options": {
          "type": "array",
          "minItems": 2,
          "x-sensitivity": "none",
          "description": "Static options. An answer is one option id. Absent when the options are enumerated at run time; then `answer` constrains the value.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "label"],
            "properties": {
              "id": { "type": "string", "minLength": 1 },
              "label": { "type": "string", "minLength": 1 }
            }
          }
        },
        "answer": {
          "type": "object",
          "additionalProperties": false,
          "required": ["pattern"],
          "x-sensitivity": "none",
          "description": "For options enumerated at run time: every answered value must match `pattern`. Phase 0 still checks the value is one of the options it enumerated, and asks when it is not.",
          "properties": {
            "pattern": { "type": "string" },
            "description": { "type": "string" },
            "example": { "type": "string", "description": "A neutral value the pattern admits." }
          }
        },
        "default": {
          "type": "string",
          "x-sensitivity": "none",
          "description": "The option id the picker marks recommended."
        },
        "stateField": {
          "type": "string",
          "x-sensitivity": "none",
          "description": "The agent-state.json field the answer ends up in."
        },
        "skippable-when": {
          "type": "array",
          "items": { "type": "string" },
          "x-sensitivity": "none",
          "description": "Conditions under which Phase 0 resolves the step without asking."
        },
        "disabled-when": {
          "type": "array",
          "x-sensitivity": "none",
          "description": "An option that may not be chosen under a condition. A launch request choosing it is rejected, not downgraded.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["option"],
            "minProperties": 2,
            "properties": {
              "option": { "type": "string" },
              "mode": { "enum": ["interactive", "autopilot", "background"] },
              "workingTree": { "enum": ["dirty"] }
            }
          }
        },
        "source": {
          "type": ["string", "null"],
          "x-sensitivity": "none",
          "description": "A command that prints the options as redacted JSON. null when none ships."
        },
        "sourceNote": { "type": "string", "x-sensitivity": "none" }
      }
    }
  }
}
