{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/schemas/product-tree-overlay.schema.json",
  "title": "Product tree overlay row",
  "description": "One line of ~/.claude/knowledge/<project>/product-tree-overlay.jsonl, the append-only record of nodes a model proposed and a person agreed to or rejected. A proposal always carries evidence that points into the repository; only a person at a terminal, in an attended run, writes agree or reject. A proposal without a later agree row is never used as fact.",
  "type": "object",
  "required": ["id", "ts", "op", "by"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string", "pattern": "^[PAR]:[0-9a-f]{8}$" },
    "ts": { "type": "string" },
    "op": { "enum": ["propose", "agree", "reject"] },
    "by": { "enum": ["model", "human"] },
    "node": {
      "type": "object",
      "required": ["kind", "name"],
      "additionalProperties": false,
      "properties": {
        "kind": { "enum": ["journey", "flow", "screen", "feature", "rule", "scenario", "event"] },
        "name": { "type": "string", "minLength": 1 },
        "parent": { "type": "string" }
      }
    },
    "ref": {
      "type": "string",
      "pattern": "^P:[0-9a-f]{8}$",
      "description": "agree / reject: the proposal this row decides."
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["path", "line"],
        "additionalProperties": false,
        "properties": {
          "path": { "type": "string", "minLength": 1 },
          "line": { "type": "integer", "minimum": 1 },
          "text": { "type": "string" }
        }
      }
    },
    "note": { "type": "string" }
  },
  "allOf": [
    {
      "if": { "properties": { "op": { "const": "propose" } } },
      "then": {
        "required": ["node", "evidence"],
        "properties": { "by": { "const": "model" }, "evidence": { "minItems": 1 } }
      }
    },
    {
      "if": { "properties": { "op": { "enum": ["agree", "reject"] } } },
      "then": { "required": ["ref"], "properties": { "by": { "const": "human" } } }
    }
  ]
}
