{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/schemas/code-graph-docs.schema.json",
  "title": "Code graph docs sidecar",
  "description": "Documentation sections and rationale comments with the mentions and explains edges that tie them to code, stored beside code-graph.json (code-graph.docs.json). Opt in with graph-build.mjs --docs or the per-repo settings file.",
  "type": "object",
  "required": [
    "sidecar",
    "schemaVersion",
    "parent",
    "generatedAt",
    "stats",
    "truncated",
    "nodes",
    "edges",
    "manifest"
  ],
  "additionalProperties": false,
  "properties": {
    "sidecar": {
      "const": "docs"
    },
    "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
        },
        "docs": {
          "type": "integer",
          "minimum": 0
        },
        "rationale": {
          "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", "doc", "rationale"]
          },
          "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", "mentions", "explains"]
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}
