{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://agoragentic.com/schema/code-graph.v1.json",
  "title": "Agoragentic ECF Code Graph",
  "description": "Governed code/context graph artifact for ECF Core, Harness Core, and Agent OS preview. This schema does not scan repositories, mutate policy, publish listings, activate x402, spend, settle, or update trust.",
  "type": "object",
  "required": ["schema", "graph_id", "nodes", "edges", "visibility_policy", "memory_policy", "public_boundary"],
  "properties": {
    "schema": { "const": "agoragentic.code-graph.v1" },
    "graph_id": { "type": "string" },
    "repo_root": { "type": "string" },
    "source_refs": { "type": "array", "items": { "type": "string" } },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["node_id", "type", "label"],
        "properties": {
          "node_id": { "type": "string" },
          "type": {
            "enum": [
              "file",
              "function",
              "class",
              "route",
              "api_endpoint",
              "tool",
              "policy",
              "approval_gate",
              "receipt",
              "marketplace_listing",
              "x402_edge",
              "ecf_context",
              "agent_template",
              "deployment_contract",
              "business_domain",
              "business_flow",
              "process_step"
            ]
          },
          "label": { "type": "string" },
          "path": { "type": ["string", "null"] },
          "source_ref": { "type": ["string", "null"] },
          "trap_scan_status": { "type": "string" },
          "public_safe": { "type": "boolean" },
          "metadata": { "type": "object" }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["edge_id", "type", "from_node_id", "to_node_id"],
        "properties": {
          "edge_id": { "type": "string" },
          "type": {
            "enum": [
              "imports",
              "calls",
              "exposes",
              "depends_on",
              "governed_by",
              "writes_receipt",
              "uses_tool",
              "routes_to",
              "settles_through",
              "owned_by_deployment",
              "belongs_to_domain",
              "affects",
              "blocked_by_policy"
            ]
          },
          "from_node_id": { "type": "string" },
          "to_node_id": { "type": "string" },
          "evidence_refs": { "type": "array", "items": { "type": "string" } },
          "receipt_refs": { "type": "array", "items": { "type": "string" } },
          "blocked_by_policy": { "type": "boolean" },
          "metadata": { "type": "object" }
        }
      }
    },
    "pipeline_roles": { "type": "array", "items": { "type": "string" } },
    "future_commands": { "type": "array", "items": { "type": "string" } },
    "output_paths": { "type": "array", "items": { "type": "string" } },
    "visibility_policy": {
      "type": "object",
      "required": ["mode"],
      "properties": {
        "mode": {
          "enum": [
            "private_owner_only",
            "deployment_only",
            "workspace_only",
            "team",
            "enterprise_tenant",
            "marketplace_public_after_approval"
          ]
        },
        "owner_approved_public": { "type": "boolean" }
      }
    },
    "memory_policy": {
      "type": "object",
      "required": ["mode", "durable_memory_allowed", "memory_write_gate_required"],
      "properties": {
        "mode": {
          "enum": [
            "memory_write_blocked",
            "requires_memory_write_gate_review",
            "owner_review_required"
          ]
        },
        "durable_memory_allowed": { "const": false },
        "memory_write_gate_required": { "const": true }
      }
    },
    "review": { "type": "object" },
    "public_boundary": {
      "type": "object",
      "required": ["graph_artifact_only"],
      "properties": {
        "graph_artifact_only": { "const": true },
        "scanner_executed": { "const": false },
        "repository_read": { "const": false },
        "deployment_policy_mutated": { "const": false },
        "marketplace_publication_triggered": { "const": false },
        "x402_route_created": { "const": false },
        "wallet_spend_triggered": { "const": false },
        "settlement_triggered": { "const": false },
        "trust_mutated": { "const": false },
        "private_context_exposed": { "const": false }
      }
    },
    "created_at": { "type": "string" }
  },
  "additionalProperties": true
}
