{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/schemas/code-graph-infra.schema.json",
  "title": "Code graph infra sidecar",
  "description": "Infrastructure and configuration nodes (Dockerfile, Compose, Kubernetes, Helm, Terraform, CI, env files, application config, dependency manifests) and the edges from code to the variables and keys it reads, stored beside code-graph.json (code-graph.infra.json). Names only; no value is stored. Opt in with graph-build.mjs --infra or the per-repo settings file.",
  "type": "object",
  "required": [
    "sidecar",
    "schemaVersion",
    "parent",
    "generatedAt",
    "stats",
    "truncated",
    "nodes",
    "edges",
    "manifest"
  ],
  "additionalProperties": false,
  "properties": {
    "sidecar": {
      "const": "infra"
    },
    "schemaVersion": {
      "const": "1.0.0"
    },
    "parent": {
      "type": "object",
      "required": ["generatedAt"],
      "description": "The build of the main graph this sidecar was made against. A reader that finds a different generatedAt in the main graph does not join it.",
      "properties": {
        "generatedAt": {
          "type": "string"
        },
        "baseCommit": {
          "type": ["string", "null"]
        },
        "stack": {
          "type": "string"
        },
        "nodes": {
          "type": "integer",
          "minimum": 0
        },
        "edges": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "generatedAt": {
      "type": "string"
    },
    "stats": {
      "type": "object",
      "required": ["nodes", "edges"],
      "properties": {
        "nodes": {
          "type": "integer",
          "minimum": 0
        },
        "edges": {
          "type": "integer",
          "minimum": 0
        },
        "infra": {
          "type": "integer",
          "minimum": 0
        },
        "env": {
          "type": "integer",
          "minimum": 0
        },
        "config": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "truncated": {
      "description": "null when the layer is whole; otherwise how much a node or edge cap cut.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": ["edges", "nodes", "reason"],
          "properties": {
            "edges": {
              "type": "integer",
              "minimum": 0
            },
            "nodes": {
              "type": "integer",
              "minimum": 0
            },
            "reason": {
              "type": "string"
            }
          }
        }
      ]
    },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "kind", "name", "degree"],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "maxLength": 4096
          },
          "kind": {
            "type": "string",
            "enum": ["file", "infra", "env", "config", "module"]
          },
          "name": {
            "type": "string",
            "maxLength": 4096
          },
          "path": {
            "type": ["string", "null"]
          },
          "line": {
            "type": "integer",
            "minimum": 1
          },
          "startLine": {
            "type": "integer",
            "minimum": 1
          },
          "endLine": {
            "type": "integer",
            "minimum": 1
          },
          "symbolKind": {
            "type": "string"
          },
          "owner": {
            "type": "string",
            "description": "The type that declares a method."
          },
          "nested": {
            "type": "boolean"
          },
          "isTest": {
            "type": "boolean"
          },
          "degree": {
            "type": "integer",
            "minimum": 0,
            "description": "Always 0 in a sidecar: a layer never changes the structural degree of a node."
          }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["from", "to", "kind"],
        "additionalProperties": false,
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": ["defines", "sets", "uses", "builds", "runs", "reads"]
          },
          "via": {
            "type": "string",
            "description": "How the edge was derived."
          },
          "confidence": {
            "enum": ["certain", "high", "medium", "low"]
          }
        }
      }
    },
    "manifest": {
      "type": "object",
      "description": "relpath -> {size, mtimeMs} of every file this layer read. An edit to one of them, a removal, or a new file of the kind the layer reads marks the layer stale.",
      "additionalProperties": {
        "type": "object",
        "required": ["size", "mtimeMs"],
        "additionalProperties": false,
        "properties": {
          "size": {
            "type": "integer",
            "minimum": 0
          },
          "mtimeMs": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    },
    "coverage": {
      "type": "object",
      "properties": {
        "skipped": {
          "type": "array",
          "description": "Files left unread because the collection time budget ran out.",
          "items": {
            "type": "object",
            "required": ["path", "reason"],
            "properties": {
              "path": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
