{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agiright.org/schemas/arhg.schema.json",
  "title": "ARHG v0.1 Agent-Readable Hyperlink Graph",
  "description": "Draft machine-readable graph schema for ARHG v0.1 — a typed, permissioned node/edge graph describing what a site or site group makes discoverable and traversable to a given role. Deliberately excludes pricing, usage quotas, and settlement fields, which belong to a separate economic/federation extension this site has not adopted.",
  "type": "object",
  "additionalProperties": false,
  "required": ["arhg_version", "site", "nodes", "edges"],
  "properties": {
    "arhg_version": {
      "const": "0.1"
    },
    "site": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "canonical_url", "version"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "canonical_url": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "registry_parent": { "type": "string" }
      }
    },
    "nodes": {
      "type": "array",
      "items": { "$ref": "#/$defs/node" }
    },
    "edges": {
      "type": "array",
      "items": { "$ref": "#/$defs/edge" }
    }
  },
  "$defs": {
    "visibility": {
      "enum": ["public", "preview", "internal", "private"]
    },
    "role": {
      "enum": ["public", "crawler", "agent", "editor", "admin", "owner"]
    },
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "title", "canonical_url", "visibility", "allowed_roles"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stable node identity, independent of canonical_url — a URL may change without changing this id."
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "description": "e.g. website, page, project, paper, document, repository, dataset, api, agent, service, protocol"
        },
        "title": { "type": "string", "minLength": 1 },
        "canonical_url": { "type": "string", "minLength": 1 },
        "visibility": { "$ref": "#/$defs/visibility" },
        "discoverable": {
          "type": "boolean",
          "description": "Whether this node may appear in a crawler's or anonymous agent's listing, independent of whether it is readable once found."
        },
        "status": { "type": "string" },
        "summary": { "type": "string" },
        "languages": {
          "type": "array",
          "items": { "type": "string" }
        },
        "updated_at": { "type": "string" },
        "allowed_roles": {
          "type": "array",
          "items": { "$ref": "#/$defs/role" },
          "minItems": 1
        }
      }
    },
    "edge": {
      "type": "object",
      "additionalProperties": false,
      "required": ["from", "to", "relation"],
      "properties": {
        "from": { "type": "string", "minLength": 1 },
        "to": { "type": "string", "minLength": 1 },
        "relation": {
          "type": "string",
          "minLength": 1,
          "description": "e.g. parent, child, related, depends_on, implements, extends, replaces, replaced_by, source, canonical, mirror, document, repository, dataset, api, agent, tool, next, previous, external, archive, admin"
        },
        "visibility": { "$ref": "#/$defs/visibility" },
        "traversable": { "type": "boolean" }
      }
    }
  }
}
