{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://quinelings.local/design/intent.schema.json",
  "title": "Quineling bounded typed intent",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "name",
    "thought",
    "inputs",
    "steps",
    "outputs"
  ],
  "properties": {
    "format": {
      "const": "quineling-intent"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "thought": {
      "type": "string",
      "maxLength": 16384
    },
    "assumptions": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "type": "string",
        "maxLength": 512
      }
    },
    "inputs": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "value",
          "type"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "value": {},
          "type": {
            "$ref": "#/$defs/valueType"
          }
        }
      }
    },
    "steps": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "$ref": "#/$defs/step"
      }
    },
    "outputs": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/id"
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$"
    },
    "valueType": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "unit"
          ],
          "properties": {
            "kind": {
              "const": "number"
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind"
          ],
          "properties": {
            "kind": {
              "enum": [
                "boolean",
                "string",
                "null"
              ]
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "element"
          ],
          "properties": {
            "kind": {
              "enum": [
                "array",
                "optional"
              ]
            },
            "element": {
              "$ref": "#/$defs/valueType"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "fields"
          ],
          "properties": {
            "kind": {
              "const": "record"
            },
            "fields": {
              "type": "object",
              "maxProperties": 512,
              "additionalProperties": {
                "$ref": "#/$defs/valueType"
              }
            }
          }
        }
      ]
    },
    "step": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "op",
        "inputs",
        "params"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "op": {
          "enum": [
            "sum",
            "mean",
            "min",
            "max",
            "weightedMean",
            "length",
            "map",
            "sort",
            "dedupe",
            "filter",
            "compare",
            "choose",
            "get",
            "clamp",
            "budget",
            "action",
            "report",
            "bfs",
            "allocate",
            "schedule",
            "consensus",
            "retry",
            "evidence"
          ]
        },
        "inputs": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "params": {
          "type": "object"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "op": {
                "const": "sum"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "mean"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "min"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "max"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "weightedMean"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "length"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "map"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "enum": [
                      "square",
                      "multiply"
                    ]
                  },
                  "factor": {
                    "type": "number"
                  }
                },
                "required": [
                  "kind"
                ],
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "kind": {
                          "const": "multiply"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "factor"
                      ]
                    },
                    "else": {
                      "not": {
                        "required": [
                          "factor"
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "sort"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "key": {
                    "type": "string"
                  },
                  "descending": {
                    "type": "boolean"
                  }
                },
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "dedupe"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "key": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "filter"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "key": {
                    "type": "string"
                  },
                  "operator": {
                    "type": "string",
                    "enum": [
                      "eq",
                      "ne",
                      "gt",
                      "gte",
                      "lt",
                      "lte"
                    ]
                  },
                  "value": {}
                },
                "required": [
                  "operator",
                  "value"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "compare"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "operator": {
                    "type": "string",
                    "enum": [
                      "eq",
                      "ne",
                      "gt",
                      "gte",
                      "lt",
                      "lte"
                    ]
                  },
                  "value": {}
                },
                "required": [
                  "operator",
                  "value"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "choose"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "get"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "path": {
                    "type": "string"
                  }
                },
                "required": [
                  "path"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "clamp"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "min": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  }
                },
                "required": [
                  "min",
                  "max"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "budget"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "action"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "allowed": {
                    "type": "boolean"
                  },
                  "action": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  }
                },
                "required": [
                  "allowed",
                  "action"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "report"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "labels": {
                    "type": "array",
                    "maxItems": 16,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "labels"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "bfs"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "start": {
                    "type": "string"
                  },
                  "goal": {
                    "type": "string"
                  }
                },
                "required": [
                  "start",
                  "goal"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "allocate"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "schedule"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {},
                "required": []
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "consensus"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "required": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 9007199254740991
                  }
                },
                "required": [
                  "required"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "retry"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "maxAttempts": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8
                  }
                },
                "required": [
                  "maxAttempts"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "op": {
                "const": "evidence"
              }
            }
          },
          "then": {
            "properties": {
              "params": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "claim": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        }
      ]
    }
  },
  "description": "Experimental bounded literal-input task proposal. Compiler additionally enforces finite JSON, closed safe keys, typed ports, unit consistency, concrete refinements, eager effect guards and full constructor source budget. No arbitrary host code or external authority."
}
