{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/schemas/product-tree.schema.json",
  "title": "Product tree",
  "description": "The screen layer over the code graph, derived without a model by product-tree.mjs build: screens, routes, flows, localized strings, endpoints and tests, joined by navigation, string use, endpoint calls and test references. One file per project under ~/.claude/knowledge/<project>/product-tree.json, written 0600 and never shipped. Human-agreed additions live beside it in the append-only product-tree-overlay.jsonl.",
  "type": "object",
  "required": [
    "schemaVersion",
    "project",
    "stacks",
    "generatedAt",
    "coverage",
    "stats",
    "nodes",
    "edges"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "enum": ["1.0.0"] },
    "project": { "type": "string", "minLength": 1 },
    "stacks": {
      "type": "array",
      "items": { "enum": ["ios", "android", "web"] },
      "uniqueItems": true
    },
    "baseCommit": {
      "type": ["string", "null"],
      "description": "git HEAD the tree was built from; null outside a work tree."
    },
    "generatedAt": { "type": "string" },
    "coverage": {
      "type": "object",
      "description": "Screen-index coverage per stack. reachable counts screens with an inbound entry, route, navigation or presentation edge; programmatic counts navigation calls whose destination is computed in code, and how many of them resolved to a screen.",
      "propertyNames": { "enum": ["ios", "android", "web"] },
      "additionalProperties": {
        "type": "object",
        "required": ["screens", "reachable", "routes", "routesWithScreen", "programmatic"],
        "additionalProperties": false,
        "properties": {
          "screens": { "type": "integer", "minimum": 0 },
          "reachable": { "type": "integer", "minimum": 0 },
          "routes": { "type": "integer", "minimum": 0 },
          "routesWithScreen": { "type": "integer", "minimum": 0 },
          "programmatic": {
            "type": "object",
            "required": ["total", "resolved", "unresolved"],
            "additionalProperties": false,
            "properties": {
              "total": { "type": "integer", "minimum": 0 },
              "resolved": { "type": "integer", "minimum": 0 },
              "unresolved": {
                "type": "array",
                "maxItems": 50,
                "items": {
                  "type": "object",
                  "required": ["path", "line", "text"],
                  "additionalProperties": false,
                  "properties": {
                    "path": { "type": "string" },
                    "line": { "type": "integer", "minimum": 1 },
                    "text": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "stats": {
      "type": "object",
      "required": ["nodes", "edges", "screens", "strings"],
      "additionalProperties": false,
      "properties": {
        "nodes": { "type": "integer", "minimum": 0 },
        "edges": { "type": "integer", "minimum": 0 },
        "screens": { "type": "integer", "minimum": 0 },
        "strings": { "type": "integer", "minimum": 0 }
      }
    },
    "nodes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "kind", "name"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "kind": { "enum": ["app", "screen", "route", "flow", "string", "endpoint", "test"] },
          "name": { "type": "string" },
          "stack": { "enum": ["ios", "android", "web"] },
          "path": { "type": "string" },
          "line": { "type": "integer", "minimum": 0 },
          "values": {
            "type": "object",
            "description": "string nodes: locale -> value.",
            "additionalProperties": { "type": "string" }
          },
          "files": {
            "type": "array",
            "description": "screen nodes: the files the screen owns, its own first. string nodes: the files that reference the key.",
            "items": { "type": "string" }
          }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["from", "to", "kind"],
        "additionalProperties": false,
        "properties": {
          "from": { "type": "string" },
          "to": { "type": "string" },
          "kind": {
            "enum": ["entry", "shows", "navigates", "presents", "uses-string", "calls", "tests"]
          },
          "via": {
            "enum": [
              "link",
              "link-value",
              "destination",
              "sheet",
              "cover",
              "root",
              "tab",
              "hosting",
              "programmatic"
            ]
          }
        }
      }
    }
  }
}
