{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/consultation.schema.json",
  "title": "Consultation",
  "description": "What a HEART sends a brain about a problem its reflexes cannot handle (Core Standard, Section 7.2). Features, never raw samples. It passes the Valve, each feature at its signal's privacy level, and travels as untrusted context in a Reason request with task 'propose' and output limited to the Proposal schema.",
  "type": "object",
  "required": [
    "id",
    "problem",
    "features",
    "candidates"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "problem": {
      "type": "object",
      "required": [
        "code",
        "since"
      ],
      "additionalProperties": false,
      "properties": {
        "code": {
          "description": "Fault code (Part 3).",
          "type": "string"
        },
        "since": {
          "$ref": "common.schema.json#/$defs/timestamp"
        },
        "arrhythmiaId": {
          "$ref": "common.schema.json#/$defs/uuid"
        },
        "summary": {
          "type": "string",
          "maxLength": 500
        }
      }
    },
    "features": {
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "$ref": "common.schema.json#/$defs/feature"
      }
    },
    "candidates": {
      "description": "What a Proposal may change: at most 8 targets (Section 5), with their current values, ranges, envelopes and guards.",
      "type": "array",
      "minItems": 1,
      "maxItems": 8,
      "items": {
        "type": "object",
        "required": [
          "target",
          "current"
        ],
        "additionalProperties": false,
        "properties": {
          "target": {
            "description": "A capability in the System Map.",
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "current": {
            "description": "The current value of every argument a Proposal could change, read by the Core.",
            "type": "object"
          },
          "range": {
            "description": "The declared range of the target's numeric arguments, per argument.",
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "min": {
                  "type": "number"
                },
                "max": {
                  "type": "number"
                }
              }
            }
          },
          "envelope": {
            "description": "The allowlist envelope for AI, if any (Section 7.4).",
            "$ref": "common.schema.json#/$defs/changeEnvelope"
          },
          "guards": {
            "description": "The target's guards (Part 6, Section 9.1), so the brain does not propose what will be refused.",
            "type": "object"
          },
          "physical": {
            "type": "boolean"
          }
        }
      }
    },
    "history": {
      "description": "Earlier Trials for this problem on this system.",
      "type": "array",
      "maxItems": 16,
      "items": {
        "type": "object",
        "required": [
          "trialId",
          "result"
        ],
        "additionalProperties": false,
        "properties": {
          "trialId": {
            "$ref": "common.schema.json#/$defs/uuid"
          },
          "target": {
            "type": "string"
          },
          "arguments": {
            "type": "object"
          },
          "result": {
            "$ref": "trial.schema.json#/$defs/finalState"
          }
        }
      }
    }
  }
}
