{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://yarrasys.dev/schema/yarramate-ask-result.schema.json",
  "title": "YarraMate ask result",
  "description": "One envelope for every consumed-now read: orientation, roster, slice, advice, verified locations, next, open questions, and state comparison, discriminated by mode.",
  "type": "object",
  "required": [
    "format",
    "workspace",
    "mode"
  ],
  "properties": {
    "format": {
      "const": "yarramate/ask-result/v1"
    },
    "workspace": {
      "type": "string",
      "minLength": 1
    },
    "mode": {
      "enum": [
        "orientation",
        "roster",
        "slice",
        "advice",
        "where",
        "next",
        "open",
        "compare",
        "kinds"
      ]
    }
  },
  "oneOf": [
    {
      "type": "object",
      "required": [
        "mode",
        "ok",
        "check",
        "backlog"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "orientation"
        },
        "ok": {
          "type": "boolean"
        },
        "check": {
          "type": "object",
          "required": [
            "ok",
            "diagnostics"
          ],
          "properties": {
            "ok": {
              "type": "boolean"
            },
            "diagnostics": {
              "type": "array"
            },
            "counted": {
              "type": "object",
              "required": [
                "documents",
                "concepts",
                "relationships",
                "states"
              ],
              "properties": {
                "documents": {
                  "type": "integer"
                },
                "concepts": {
                  "type": "integer"
                },
                "relationships": {
                  "type": "integer"
                },
                "states": {
                  "type": "integer"
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        },
        "reconciliation": {
          "$ref": "#/$defs/reconciliationSummary"
        },
        "design": {
          "type": "object",
          "required": [
            "catalogue",
            "open"
          ],
          "properties": {
            "catalogue": {
              "type": "string",
              "minLength": 1
            },
            "open": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        },
        "backlog": {
          "type": "object",
          "required": [
            "planned",
            "current",
            "retired"
          ],
          "properties": {
            "planned": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/nextSubject"
              }
            },
            "current": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/conceptEntry"
              }
            },
            "retired": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/conceptEntry"
              }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "total",
        "subjects"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "roster"
        },
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "subjects": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/conceptEntry"
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "addressing",
        "result"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "slice"
        },
        "rendered": {
          "type": "string",
          "description": "The text the CLI prints for the same call: the brief, or the budgeted context when a budget was given. Present when the slice was produced by the tools entry (ADR 0156); absent from the git-derived review slice."
        },
        "addressing": {
          "enum": [
            "free-text",
            "subjects",
            "projection",
            "changed"
          ]
        },
        "topic": {
          "type": "string",
          "minLength": 1
        },
        "seeds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "matched": {
          "type": "integer",
          "minimum": 0
        },
        "candidates": {
          "type": "array",
          "description": "Every concept a query term touched, ranked by how many distinct terms it contains, present on a free-text slice (#569). The seeds are the first few of these. A caller that can judge which candidate actually answers the question reorders the list and asks again with `subjects` addressing; the engine does not judge, so it hands the list over instead.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "terms"],
            "properties": {
              "id": { "type": "string", "minLength": 1 },
              "terms": { "type": "integer", "minimum": 1 }
            }
          }
        },
        "result": {
          "$ref": "#/$defs/projectionResult"
        },
        "changed": {
          "type": "object",
          "required": [
            "range",
            "concepts",
            "relationships"
          ],
          "properties": {
            "range": {
              "type": "string",
              "minLength": 1
            },
            "concepts": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "relationships": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "added": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "additionalProperties": false
        },
        "coverage": {
          "type": "object",
          "required": [
            "projections",
            "uncovered"
          ],
          "properties": {
            "projections": {
              "type": "integer",
              "minimum": 0
            },
            "uncovered": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "additionalProperties": false
        },
        "neighbourhood": {
          "$ref": "#/$defs/neighbourhoodOmission"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "topic",
        "seeds",
        "matched",
        "slice",
        "openQuestions"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "advice"
        },
        "topic": {
          "type": "string",
          "minLength": 1
        },
        "seeds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "matched": {
          "type": "integer",
          "minimum": 0
        },
        "slice": {
          "type": "string",
          "minLength": 1
        },
        "neighbourhood": {
          "$ref": "#/$defs/neighbourhoodOmission"
        },
        "openQuestions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "wave",
              "id",
              "authority",
              "question",
              "materiality"
            ],
            "properties": {
              "wave": {
                "type": "string",
                "minLength": 1
              },
              "id": {
                "type": "string",
                "minLength": 1
              },
              "authority": {
                "enum": [
                  "human",
                  "agent",
                  "either"
                ]
              },
              "question": {
                "type": "string",
                "minLength": 1
              },
              "materiality": {
                "type": "string",
                "minLength": 1
              },
              "subject": {
                "type": "string",
                "minLength": 1
              }
            },
            "additionalProperties": false
          }
        },
        "reconciliation": {
          "type": "object",
          "required": [
            "summary",
            "findings"
          ],
          "properties": {
            "summary": {
              "$ref": "#/$defs/reconciliationSummary"
            },
            "findings": {
              "type": "array"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "addressing",
        "topic",
        "seeds",
        "matched",
        "located",
        "coverage"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "where"
        },
        "addressing": {
          "enum": [
            "free-text",
            "subjects"
          ]
        },
        "topic": {
          "type": "string",
          "minLength": 1
        },
        "seeds": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "matched": {
          "type": "integer",
          "minimum": 0
        },
        "located": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "subject",
              "observations"
            ],
            "additionalProperties": false,
            "properties": {
              "subject": {
                "type": "string",
                "minLength": 1
              },
              "observations": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "required": [
                    "uri",
                    "result",
                    "provider"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "uri": {
                      "type": "string",
                      "minLength": 1
                    },
                    "result": {
                      "enum": [
                        "confirmed",
                        "contradicted",
                        "unknown",
                        "not-observed"
                      ]
                    },
                    "provider": {
                      "type": "string",
                      "minLength": 1
                    },
                    "message": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                }
              }
            }
          }
        },
        "coverage": {
          "type": "object",
          "required": [
            "unobserved",
            "note"
          ],
          "additionalProperties": false,
          "properties": {
            "unobserved": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "note": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    {
      "type": "object",
      "required": [
        "mode",
        "subjects"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "next"
        },
        "subjects": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/nextSubject"
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "report"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "open"
        },
        "report": {
          "description": "A shallow restatement of the interrogation report, kept in step with yarramate-interrogation-report.schema.json by a test rather than by memory: this copy silently rejected `catalogues` from the day composition shipped, because `additionalProperties` is false here and nobody updated both places.",
          "type": "object",
          "required": [
            "format",
            "workspace",
            "catalogue",
            "semantics",
            "inputs",
            "summary",
            "waves"
          ],
          "properties": {
            "format": {
              "const": "yarramate/interrogation-report/v1"
            },
            "workspace": {
              "type": "string"
            },
            "catalogue": {
              "type": "string"
            },
            "catalogues": {
              "type": "array"
            },
            "semantics": {
              "type": "string"
            },
            "inputs": {
              "type": "object"
            },
            "summary": {
              "type": "object"
            },
            "waves": {
              "type": "array"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "conceptKinds",
        "relationshipKinds",
        "extensions"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "kinds"
        },
        "conceptKinds": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "name",
              "layer",
              "aspect"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "layer": {
                "type": "string",
                "minLength": 1
              },
              "aspect": {
                "type": "string",
                "minLength": 1
              },
              "inspiredBy": {
                "type": "string"
              },
              "rigidity": {
                "enum": ["rigid", "anti-rigid"]
              }
            },
            "additionalProperties": false
          }
        },
        "relationshipKinds": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "intent"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "intent": {
                "type": "string",
                "minLength": 1
              },
              "sourceAspects": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "targetAspects": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": false
          }
        },
        "relationshipMatrix": {
          "description": "The ArchiMate 3.2 relationship table the core profile validates endpoints against (ADR 0097): one row per source kind, a space-separated letter group per target kind in `kinds` order, each letter naming a permitted relationship kind via `letters`.",
          "type": "object",
          "required": ["standard", "letters", "kinds", "rows"],
          "properties": {
            "standard": { "type": "string" },
            "letters": {
              "type": "object",
              "additionalProperties": { "type": "string" }
            },
            "kinds": {
              "type": "array",
              "items": { "type": "string" }
            },
            "rows": {
              "type": "object",
              "additionalProperties": { "type": "string" }
            }
          },
          "additionalProperties": false
        },
        "extensions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id",
              "type",
              "lineage"
            ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "type": {
                "enum": [
                  "concept",
                  "relationship"
                ]
              },
              "lineage": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "mode",
        "comparison"
      ],
      "properties": {
        "format": true,
        "workspace": true,
        "mode": {
          "const": "compare"
        },
        "comparison": {
          "type": "object",
          "required": [
            "format",
            "from",
            "to",
            "added",
            "removed",
            "retained"
          ],
          "properties": {
            "format": {
              "const": "yarramate/state-comparison/v1"
            },
            "from": {
              "type": "string"
            },
            "to": {
              "type": "string"
            },
            "added": {
              "type": "array"
            },
            "removed": {
              "type": "array"
            },
            "retained": {
              "type": "array"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  ],
  "$defs": {
    "neighbourhoodOmission": {
      "description": "Present only when the per-seed neighbour cap dropped part of the 1-hop expansion (ADR 0070): the cap in force, neighbours kept and omitted in total, and the per-seed omission counts. Absent means the slice is the complete connected neighbourhood.",
      "type": "object",
      "required": [
        "cap",
        "kept",
        "omitted",
        "omittedBySeed"
      ],
      "properties": {
        "cap": {
          "type": "integer",
          "minimum": 1
        },
        "kept": {
          "type": "integer",
          "minimum": 0
        },
        "omitted": {
          "type": "integer",
          "minimum": 1
        },
        "omittedBySeed": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "seed",
              "omitted"
            ],
            "properties": {
              "seed": {
                "type": "string",
                "minLength": 1
              },
              "omitted": {
                "type": "integer",
                "minimum": 1
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "conceptEntry": {
      "type": "object",
      "required": [
        "id",
        "kind"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string"
        },
        "status": {
          "enum": [
            "planned",
            "current",
            "retired"
          ]
        },
        "description": {
          "type": "string"
        },
        "aka": {
          "description": "Alternative labels this subject is also known by. Free-text seeding matches them at the same weight as the name; renderers show the preferred name only.",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "nextSubject": {
      "type": "object",
      "required": [
        "id",
        "kind",
        "dependsOn",
        "requiredBy",
        "evidence"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string"
        },
        "dependsOn": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "requiredBy": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "evidence": {
          "type": "object",
          "required": [
            "observations",
            "confirmed",
            "contradicted",
            "unknown",
            "notObserved"
          ],
          "properties": {
            "observations": {
              "type": "integer"
            },
            "confirmed": {
              "type": "integer"
            },
            "contradicted": {
              "type": "integer"
            },
            "unknown": {
              "type": "integer"
            },
            "notObserved": {
              "type": "integer"
            },
            "unsupportedAbsences": {
              "type": "integer",
              "minimum": 0
            }
          },
          "additionalProperties": false
        },
        "cycle": {
          "const": true
        }
      },
      "additionalProperties": false
    },
    "projectionResult": {
      "type": "object",
      "required": [
        "format",
        "projection",
        "documents",
        "subjects",
        "claims"
      ],
      "properties": {
        "format": {
          "const": "yarramate/projection-result/v1"
        },
        "projection": {
          "type": "string"
        },
        "presentation": {
          "type": "object"
        },
        "documents": {
          "type": "array"
        },
        "subjects": {
          "type": "array"
        },
        "claims": {
          "type": "array"
        }
      },
      "additionalProperties": false
    },
    "reconciliationSummary": {
      "type": "object",
      "required": [
        "evidenceDocuments",
        "observations",
        "confirmed",
        "findings",
        "contradicted",
        "unknown",
        "notObserved",
        "subjectsWithoutEvidence"
      ],
      "properties": {
        "evidenceDocuments": {
          "type": "integer"
        },
        "observations": {
          "type": "integer"
        },
        "confirmed": {
          "type": "integer"
        },
        "findings": {
          "type": "integer"
        },
        "contradicted": {
          "type": "integer"
        },
        "unknown": {
          "type": "integer"
        },
        "notObserved": {
          "type": "integer"
        },
        "unsupportedAbsences": {
          "type": "integer",
          "minimum": 0
        },
        "subjectsWithoutEvidence": {
          "type": "integer"
        },
        "unconfirmedAttestations": {
          "type": "integer",
          "minimum": 0
        },
        "expectationsCompared": {
          "type": "integer"
        },
        "expectationsWithoutObservation": {
          "type": "integer"
        }
      },
      "additionalProperties": false
    }
  }
}
