{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/schemas/code-graph-calls.schema.json",
  "title": "Code graph calls sidecar",
  "description": "Function and method nodes and the calls edges between them, stored beside code-graph.json (code-graph.calls.json). Built by default by graph-build.mjs. Every calls edge carries how it was derived (via) and a confidence; a guess is never certain.",
  "type": "object",
  "required": [
    "sidecar",
    "schemaVersion",
    "parent",
    "generatedAt",
    "stats",
    "truncated",
    "nodes",
    "edges"
  ],
  "additionalProperties": false,
  "properties": {
    "sidecar": {
      "const": "calls"
    },
    "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
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "callFilesSkipped": {
          "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": ["symbol"]
          },
          "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", "calls"]
          },
          "via": {
            "type": "string",
            "description": "How the edge was derived."
          },
          "confidence": {
            "enum": ["high", "medium", "low"]
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "kind": {
                  "const": "calls"
                }
              },
              "required": ["kind"]
            },
            "then": {
              "required": ["via", "confidence"],
              "properties": {
                "via": {
                  "enum": [
                    "typed-receiver",
                    "self-receiver",
                    "super-receiver",
                    "static-receiver",
                    "implicit-self",
                    "same-file",
                    "same-package",
                    "same-directory",
                    "import",
                    "module-member",
                    "interface-member",
                    "ambiguous-overload",
                    "constructor",
                    "dispatch",
                    "inherited",
                    "chained-return-type",
                    "unique-name",
                    "name-arity"
                  ]
                }
              }
            }
          }
        ]
      }
    },
    "annotations": {
      "type": "object",
      "description": "Fields to add to a node the main graph already has, by id. Only owner.",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "owner": {
            "type": "string"
          }
        }
      }
    },
    "coverage": {
      "type": "object",
      "properties": {
        "callAnalysisSkipped": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["path", "reason"],
            "properties": {
              "path": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
