{
  "$id": "https://www.tapphq.com/schemas/role-spec/v1.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "TappHQ role spec, version 1. Two constraints are enforced by TappHQ and cannot be expressed here: every tool name in tools.platform, decisions[].tools and agentTeam[].tools must be a registered, non-system platform tool (registry membership), and every decision key in a position override must exist in the base role spec (override key validity).",
  "properties": {
    "agentTeam": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "handoffTo": {
            "maxLength": 200,
            "type": "string"
          },
          "name": {
            "maxLength": 200,
            "type": "string"
          },
          "owns": {
            "items": {
              "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
              "type": "string"
            },
            "type": "array"
          },
          "tools": {
            "items": {
              "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "name",
          "owns",
          "tools"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "cadence": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "schedule": {
            "maxLength": 200,
            "type": "string"
          },
          "task": {
            "maxLength": 4000,
            "type": "string"
          }
        },
        "required": [
          "schedule",
          "task"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "decisions": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "authority": {
            "enum": [
              "owns",
              "recommends",
              "escalates"
            ],
            "type": "string"
          },
          "description": {
            "maxLength": 4000,
            "type": "string"
          },
          "escalateTo": {
            "additionalProperties": false,
            "properties": {
              "kind": {
                "enum": [
                  "role",
                  "position",
                  "manager"
                ],
                "type": "string"
              },
              "ref": {
                "format": "uuid",
                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
                "type": "string"
              }
            },
            "required": [
              "kind"
            ],
            "type": "object"
          },
          "key": {
            "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
            "type": "string"
          },
          "timeoutHours": {
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991,
            "type": "integer"
          },
          "tools": {
            "items": {
              "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "key",
          "description",
          "authority"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "expertise": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "area": {
            "maxLength": 200,
            "type": "string"
          },
          "depth": {
            "enum": [
              "working",
              "strong",
              "expert"
            ],
            "type": "string"
          }
        },
        "required": [
          "area",
          "depth"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "files": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "access": {
            "enum": [
              "write",
              "read"
            ],
            "type": "string"
          },
          "kind": {
            "enum": [
              "document",
              "url",
              "drive"
            ],
            "type": "string"
          },
          "ref": {
            "maxLength": 4000,
            "type": "string"
          }
        },
        "required": [
          "kind",
          "ref",
          "access"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "handoffs": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "artifact": {
            "maxLength": 4000,
            "type": "string"
          },
          "toRole": {
            "maxLength": 200,
            "type": "string"
          },
          "trigger": {
            "maxLength": 4000,
            "type": "string"
          }
        },
        "required": [
          "toRole",
          "trigger",
          "artifact"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "learnings": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "approvedAt": {
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
            "type": "string"
          },
          "approvedBy": {
            "anyOf": [
              {
                "format": "uuid",
                "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
                "type": "string"
              },
              {
                "pattern": "^system:[a-z0-9][a-z0-9_.-]{0,79}$",
                "type": "string"
              }
            ]
          },
          "id": {
            "format": "uuid",
            "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
            "type": "string"
          },
          "provenance": {
            "maxLength": 4000,
            "type": "string"
          },
          "text": {
            "maxLength": 4000,
            "type": "string"
          }
        },
        "required": [
          "id",
          "text",
          "approvedBy",
          "approvedAt",
          "provenance"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "locale": {
      "enum": [
        "en"
      ],
      "type": "string"
    },
    "meta": {
      "additionalProperties": false,
      "properties": {
        "name": {
          "maxLength": 200,
          "type": "string"
        },
        "roleType": {
          "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
          "type": "string"
        },
        "summary": {
          "maxLength": 4000,
          "type": "string"
        }
      },
      "required": [
        "name",
        "roleType",
        "summary"
      ],
      "type": "object"
    },
    "mission": {
      "additionalProperties": false,
      "properties": {
        "kpis": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "cadence": {
                "maxLength": 200,
                "type": "string"
              },
              "key": {
                "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
                "type": "string"
              },
              "metric": {
                "maxLength": 200,
                "type": "string"
              },
              "source": {
                "anyOf": [
                  {
                    "additionalProperties": false,
                    "properties": {
                      "auto": {
                        "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
                        "type": "string"
                      }
                    },
                    "required": [
                      "auto"
                    ],
                    "type": "object"
                  },
                  {
                    "const": "manual",
                    "type": "string"
                  }
                ]
              },
              "target": {
                "maxLength": 200,
                "type": "string"
              }
            },
            "required": [
              "key",
              "metric",
              "target",
              "cadence",
              "source"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "outcomes": {
          "items": {
            "maxLength": 4000,
            "type": "string"
          },
          "type": "array"
        },
        "purpose": {
          "maxLength": 4000,
          "type": "string"
        }
      },
      "required": [
        "purpose",
        "outcomes",
        "kpis"
      ],
      "type": "object"
    },
    "responsibilities": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "description": {
            "maxLength": 4000,
            "type": "string"
          },
          "doneWhen": {
            "maxLength": 4000,
            "type": "string"
          },
          "frequency": {
            "maxLength": 200,
            "type": "string"
          },
          "key": {
            "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
            "type": "string"
          }
        },
        "required": [
          "key",
          "description",
          "frequency",
          "doneWhen"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "schema": {
      "const": "role-spec/v1",
      "type": "string"
    },
    "streams": {
      "items": {
        "additionalProperties": false,
        "properties": {
          "config": {
            "additionalProperties": {},
            "propertyNames": {
              "type": "string"
            },
            "type": "object"
          },
          "key": {
            "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
            "type": "string"
          },
          "kind": {
            "enum": [
              "event",
              "inbox",
              "feed",
              "schedule"
            ],
            "type": "string"
          },
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "kind",
          "key",
          "config"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "tools": {
      "additionalProperties": false,
      "properties": {
        "external": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "name": {
                "maxLength": 200,
                "type": "string"
              },
              "notes": {
                "maxLength": 4000,
                "type": "string"
              }
            },
            "required": [
              "name",
              "notes"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "platform": {
          "items": {
            "pattern": "^[a-z0-9][a-z0-9_.-]{0,79}$",
            "type": "string"
          },
          "type": "array"
        }
      },
      "required": [
        "platform",
        "external"
      ],
      "type": "object"
    }
  },
  "required": [
    "schema",
    "locale",
    "meta",
    "mission",
    "responsibilities",
    "expertise",
    "decisions",
    "streams",
    "files",
    "tools",
    "cadence",
    "handoffs",
    "agentTeam",
    "learnings"
  ],
  "title": "TappHQ Role Spec v1",
  "type": "object"
}
