{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "gno://schemas/audit-report@1.0",
  "title": "GNO Knowledge Integrity Audit Report",
  "description": "Deterministic read-only audit report for links, provenance, and freshness. Not egress-audit receipts.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "ruleSetVersion",
    "status",
    "scope",
    "capabilities",
    "fingerprints",
    "versions",
    "startedAt",
    "completedAt",
    "durationMs",
    "rules",
    "findings",
    "counts",
    "truncation",
    "timing"
  ],
  "properties": {
    "schemaVersion": { "const": "1.0" },
    "ruleSetVersion": { "const": "1.0" },
    "status": {
      "enum": ["complete", "partial", "changed_during_audit", "failed"]
    },
    "scope": { "$ref": "#/definitions/scope" },
    "capabilities": { "$ref": "#/definitions/capabilities" },
    "fingerprints": { "$ref": "#/definitions/fingerprints" },
    "versions": { "$ref": "#/definitions/versions" },
    "startedAt": { "type": "string", "format": "date-time" },
    "completedAt": { "type": "string", "format": "date-time" },
    "durationMs": { "type": "integer", "minimum": 0 },
    "rules": {
      "type": "array",
      "maxItems": 256,
      "items": { "$ref": "#/definitions/ruleResult" }
    },
    "findings": {
      "type": "array",
      "maxItems": 1000,
      "items": { "$ref": "#/definitions/finding" }
    },
    "counts": { "$ref": "#/definitions/counts" },
    "truncation": { "$ref": "#/definitions/truncation" },
    "timing": { "$ref": "#/definitions/timing" }
  },
  "definitions": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "category": {
      "enum": ["links", "provenance", "freshness"]
    },
    "ruleStatus": {
      "enum": ["pass", "fail", "skip", "unavailable", "inconclusive"]
    },
    "severity": {
      "enum": ["error", "warning", "info"]
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["categories", "collections", "paths", "tags", "indexName"],
      "properties": {
        "categories": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "items": { "$ref": "#/definitions/category" },
          "uniqueItems": true
        },
        "collections": {
          "type": "array",
          "maxItems": 256,
          "items": { "type": "string", "minLength": 1, "maxLength": 256 }
        },
        "paths": {
          "type": "array",
          "maxItems": 256,
          "items": { "type": "string", "minLength": 1, "maxLength": 2048 }
        },
        "tags": {
          "type": "array",
          "maxItems": 256,
          "items": { "type": "string", "minLength": 1, "maxLength": 256 }
        },
        "indexName": { "type": "string", "minLength": 1, "maxLength": 64 }
      }
    },
    "capabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "indexReadable",
        "sourcesReadable",
        "linksGraphAvailable",
        "provenanceSchemaAvailable",
        "offline",
        "llmDisabled"
      ],
      "properties": {
        "indexReadable": { "type": "boolean" },
        "sourcesReadable": { "type": "boolean" },
        "linksGraphAvailable": { "type": "boolean" },
        "provenanceSchemaAvailable": { "type": "boolean" },
        "offline": { "const": true },
        "llmDisabled": { "const": true }
      }
    },
    "fingerprints": {
      "type": "object",
      "additionalProperties": false,
      "required": ["config", "source", "index", "rules"],
      "properties": {
        "config": { "type": "string", "minLength": 0, "maxLength": 128 },
        "source": { "type": "string", "minLength": 0, "maxLength": 128 },
        "index": { "type": "string", "minLength": 0, "maxLength": 128 },
        "rules": { "type": "string", "minLength": 0, "maxLength": 128 }
      }
    },
    "versions": {
      "type": "object",
      "additionalProperties": false,
      "required": ["gno", "schema", "ruleSet"],
      "properties": {
        "gno": { "type": "string", "minLength": 1, "maxLength": 64 },
        "schema": { "const": "1.0" },
        "ruleSet": { "const": "1.0" }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "summary"],
      "properties": {
        "kind": { "type": "string", "minLength": 1, "maxLength": 128 },
        "summary": { "type": "string", "minLength": 1, "maxLength": 512 },
        "uri": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "path": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "detail": { "type": "string", "minLength": 1, "maxLength": 512 }
      }
    },
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "ruleId",
        "category",
        "severity",
        "subject",
        "location",
        "message",
        "evidence",
        "guidance",
        "evidenceFingerprint"
      ],
      "properties": {
        "id": { "$ref": "#/definitions/sha256" },
        "ruleId": { "type": "string", "minLength": 1, "maxLength": 128 },
        "category": { "$ref": "#/definitions/category" },
        "severity": { "$ref": "#/definitions/severity" },
        "subject": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "location": { "type": ["string", "null"], "maxLength": 2048 },
        "message": { "type": "string", "minLength": 1, "maxLength": 512 },
        "evidence": {
          "type": "array",
          "maxItems": 8,
          "items": { "$ref": "#/definitions/evidence" }
        },
        "guidance": {
          "type": "array",
          "maxItems": 4,
          "items": { "type": "string", "minLength": 1, "maxLength": 256 }
        },
        "evidenceFingerprint": { "$ref": "#/definitions/sha256" }
      }
    },
    "ruleResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "ruleId",
        "category",
        "status",
        "message",
        "findings",
        "findingCount",
        "examinedCount",
        "durationMs",
        "skipReason"
      ],
      "properties": {
        "ruleId": { "type": "string", "minLength": 1, "maxLength": 128 },
        "category": { "$ref": "#/definitions/category" },
        "status": { "$ref": "#/definitions/ruleStatus" },
        "message": { "type": "string", "minLength": 1, "maxLength": 512 },
        "findings": {
          "type": "array",
          "maxItems": 1000,
          "items": { "$ref": "#/definitions/finding" }
        },
        "findingCount": { "type": "integer", "minimum": 0 },
        "examinedCount": { "type": "integer", "minimum": 0 },
        "durationMs": { "type": "integer", "minimum": 0 },
        "skipReason": { "type": ["string", "null"], "maxLength": 512 }
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rules", "findings", "examined"],
      "properties": {
        "rules": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "pass",
            "fail",
            "skip",
            "unavailable",
            "inconclusive",
            "total"
          ],
          "properties": {
            "pass": { "type": "integer", "minimum": 0 },
            "fail": { "type": "integer", "minimum": 0 },
            "skip": { "type": "integer", "minimum": 0 },
            "unavailable": { "type": "integer", "minimum": 0 },
            "inconclusive": { "type": "integer", "minimum": 0 },
            "total": { "type": "integer", "minimum": 0 }
          }
        },
        "findings": {
          "type": "object",
          "additionalProperties": false,
          "required": ["total", "returned", "truncated"],
          "properties": {
            "total": { "type": "integer", "minimum": 0 },
            "returned": { "type": "integer", "minimum": 0, "maximum": 1000 },
            "truncated": { "type": "boolean" }
          }
        },
        "examined": {
          "type": "object",
          "additionalProperties": false,
          "required": ["documents"],
          "properties": {
            "documents": { "type": "integer", "minimum": 0 }
          }
        }
      }
    },
    "truncation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["findingsTruncated", "maxFindings"],
      "properties": {
        "findingsTruncated": { "type": "boolean" },
        "maxFindings": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000
        }
      }
    },
    "timing": {
      "type": "object",
      "additionalProperties": false,
      "required": ["snapshotMs", "rulesMs", "totalMs"],
      "properties": {
        "snapshotMs": { "type": "integer", "minimum": 0 },
        "rulesMs": { "type": "integer", "minimum": 0 },
        "totalMs": { "type": "integer", "minimum": 0 }
      }
    }
  }
}
