{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/version-report.schema.json",
  "title": "Version report",
  "description": "What `version-report.mjs --json` emits: the version of each separately published part of the ecosystem, how it compares with upstream, and the two dates that answer \"how fresh is this\". Every field is always present; null means not known or not applicable here. Added in contract 1.0.0.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contractVersion",
    "generatedAt",
    "network",
    "overall",
    "newestRelease",
    "pipeline",
    "toolkit",
    "plugins",
    "findings"
  ],
  "properties": {
    "contractVersion": { "$ref": "#/$defs/contractVersion" },
    "generatedAt": { "type": "string", "format": "date-time" },
    "network": {
      "type": "object",
      "description": "Whether upstream was read in this run. `current` is never reported without it.",
      "additionalProperties": false,
      "required": ["attempted", "reached", "reason"],
      "properties": {
        "attempted": { "type": "boolean" },
        "reached": { "type": "boolean" },
        "reason": { "$ref": "#/$defs/reason" }
      }
    },
    "overall": { "$ref": "#/$defs/verdict" },
    "newestRelease": {
      "type": "object",
      "description": "The most recently published release among the parts in use, over known dates only.",
      "additionalProperties": false,
      "required": ["part", "version", "releasedAt", "complete", "missing"],
      "properties": {
        "part": { "oneOf": [{ "$ref": "#/$defs/part" }, { "type": "null" }] },
        "version": { "type": ["string", "null"] },
        "releasedAt": { "$ref": "#/$defs/timestamp" },
        "complete": {
          "type": "boolean",
          "description": "True when every part contributed a date, so nothing newer can be hiding in a part that was not dated."
        },
        "missing": { "type": "array", "items": { "$ref": "#/$defs/part" } }
      }
    },
    "pipeline": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "hostId",
        "version",
        "releasedAt",
        "installedAt",
        "latest",
        "latestReleasedAt",
        "required",
        "verdict",
        "reason",
        "hosts"
      ],
      "properties": {
        "hostId": {
          "type": ["string", "null"],
          "description": "The host whose install the version, date and verdict describe: the invoking one when it carries a stamp, otherwise the first installed host in registry order."
        },
        "version": {
          "type": ["string", "null"],
          "description": "The version that host records."
        },
        "releasedAt": { "$ref": "#/$defs/timestamp" },
        "installedAt": { "$ref": "#/$defs/timestamp" },
        "latest": { "type": ["string", "null"] },
        "latestReleasedAt": { "$ref": "#/$defs/timestamp" },
        "required": {
          "type": ["string", "null"],
          "description": "The supported-version floor from the registry's `required` dist-tag, absent on most releases."
        },
        "verdict": { "$ref": "#/$defs/verdict" },
        "reason": { "$ref": "#/$defs/reason" },
        "hosts": {
          "type": "array",
          "description": "Every host in the registry, whether the pipeline is installed in it and at what version.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "name", "state", "version", "installedAt", "builtAgainstToolkit"],
            "properties": {
              "id": { "type": "string" },
              "name": { "type": "string" },
              "state": {
                "description": "installed (a readable version stamp), no-marker (a stamp that does not read as a version), absent (no stamp: the host CLI may be installed, the pipeline is not).",
                "enum": ["installed", "no-marker", "absent"]
              },
              "version": { "type": ["string", "null"] },
              "installedAt": { "$ref": "#/$defs/timestamp" },
              "builtAgainstToolkit": { "type": ["string", "null"] }
            }
          }
        }
      }
    },
    "toolkit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "registered",
        "spec",
        "resolvedVersion",
        "releasedAt",
        "installedAt",
        "builtAgainst",
        "latest",
        "latestReleasedAt",
        "required",
        "otherCopies",
        "verdict",
        "reason"
      ],
      "properties": {
        "registered": { "type": "boolean" },
        "spec": {
          "type": ["string", "null"],
          "description": "The package spec the registration asks for, e.g. `@scope/pkg@latest`. Null when it names a script instead."
        },
        "resolvedVersion": {
          "type": ["string", "null"],
          "description": "The version the host would run, never a claim about a server already running."
        },
        "releasedAt": { "$ref": "#/$defs/timestamp" },
        "installedAt": { "$ref": "#/$defs/timestamp" },
        "builtAgainst": {
          "type": ["string", "null"],
          "description": "The toolkit version this pipeline release was built against."
        },
        "latest": { "type": ["string", "null"] },
        "latestReleasedAt": { "$ref": "#/$defs/timestamp" },
        "required": { "type": ["string", "null"] },
        "otherCopies": {
          "type": "array",
          "description": "Further copies npm cached for the same spec, newest first after the one in use.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["version", "installedAt"],
            "properties": {
              "version": { "type": ["string", "null"] },
              "installedAt": { "$ref": "#/$defs/timestamp" }
            }
          }
        },
        "verdict": { "$ref": "#/$defs/verdict" },
        "reason": { "$ref": "#/$defs/reason" }
      }
    },
    "plugins": {
      "type": "object",
      "additionalProperties": false,
      "required": ["marketplace", "verdict", "reason", "items"],
      "properties": {
        "marketplace": {
          "type": "object",
          "additionalProperties": false,
          "required": ["present", "commit", "releasedAt", "installedAt", "remoteCommit"],
          "properties": {
            "present": { "type": "boolean" },
            "commit": { "$ref": "#/$defs/shortCommit" },
            "releasedAt": { "$ref": "#/$defs/timestamp" },
            "installedAt": { "$ref": "#/$defs/timestamp" },
            "remoteCommit": { "$ref": "#/$defs/shortCommit" }
          }
        },
        "verdict": { "$ref": "#/$defs/verdict" },
        "reason": { "$ref": "#/$defs/reason" },
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "catalogVersion",
              "installedVersion",
              "installedCommit",
              "installedAt",
              "enabledHere",
              "state"
            ],
            "properties": {
              "name": { "type": "string" },
              "catalogVersion": { "type": ["string", "null"] },
              "installedVersion": { "type": ["string", "null"] },
              "installedCommit": { "$ref": "#/$defs/shortCommit" },
              "installedAt": { "$ref": "#/$defs/timestamp" },
              "enabledHere": { "type": "boolean" },
              "state": { "enum": ["installed", "not-installed", "not-in-catalog"] }
            }
          }
        }
      }
    },
    "findings": {
      "type": "array",
      "description": "Local-against-local observations. A verdict only ever compares local with upstream, so drift is reported here instead of borrowing a verdict word.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["code", "subject"],
        "properties": {
          "code": {
            "enum": [
              "host-version-mismatch",
              "host-marker-unreadable",
              "toolkit-older-than-built-against",
              "toolkit-multiple-copies",
              "toolkit-spec-pinned",
              "plugin-enabled-not-installed",
              "plugin-enabled-not-in-catalog",
              "plugin-install-differs-from-catalog",
              "version-not-in-registry"
            ]
          },
          "subject": { "type": ["string", "null"] }
        }
      }
    }
  },
  "$defs": {
    "contractVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
    "timestamp": { "type": ["string", "null"], "format": "date-time" },
    "shortCommit": { "type": ["string", "null"], "pattern": "^[0-9a-f]{7}$" },
    "part": { "enum": ["pipeline", "toolkit", "plugins"] },
    "verdict": {
      "description": "Local against upstream, one meaning each: current (upstream read in this run and local equals latest), behind (local is lower), below-floor (behind, and under the required floor), ahead (local is higher), unknown (local exists, the comparison did not happen), absent (nothing local to compare).",
      "enum": ["current", "behind", "below-floor", "ahead", "unknown", "absent"]
    },
    "reason": {
      "type": ["string", "null"],
      "enum": [
        "offline-flag",
        "timeout",
        "dns",
        "http-error",
        "malformed",
        "not-installed",
        "not-registered",
        "unreadable",
        "remote-unreachable",
        null
      ]
    }
  }
}
