{
  "$id": "https://comitiva.dev/schema/PortableBundle.json",
  "title": "PortableBundle",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "const": "comitiva.bundle"
    },
    "version": {
      "type": "number",
      "const": 1
    },
    "exportedAt": {
      "type": "string",
      "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|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "app": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "version"
      ]
    },
    "connections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "provider": {
            "type": "string",
            "enum": [
              "anthropic",
              "openai-compatible",
              "google",
              "ollama",
              "claude-code",
              "codex",
              "gemini-cli"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "api",
              "cli"
            ]
          },
          "enabled": {
            "type": "boolean"
          },
          "config": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          },
          "hadKey": {
            "type": "boolean"
          }
        },
        "required": [
          "ref",
          "name",
          "provider",
          "kind",
          "enabled",
          "config",
          "hadKey"
        ]
      }
    },
    "toolServers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "transport": {
            "type": "string",
            "enum": [
              "stdio",
              "http"
            ]
          },
          "command": {
            "type": [
              "string",
              "null"
            ]
          },
          "args": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "env": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "value"
                  ]
                },
                {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "secret"
                  ]
                }
              ]
            }
          },
          "url": {
            "type": [
              "string",
              "null"
            ]
          },
          "headers": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "value"
                  ]
                },
                {
                  "type": "object",
                  "properties": {
                    "secret": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "secret"
                  ]
                }
              ]
            }
          },
          "enabled": {
            "type": "boolean"
          }
        },
        "required": [
          "ref",
          "name",
          "transport",
          "command",
          "args",
          "env",
          "url",
          "headers",
          "enabled"
        ]
      }
    },
    "agents": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "avatar": {
            "type": "object",
            "properties": {
              "color": {
                "type": "string",
                "enum": [
                  "indigo",
                  "violet",
                  "pink",
                  "rose",
                  "orange",
                  "amber",
                  "emerald",
                  "teal",
                  "sky",
                  "slate"
                ]
              },
              "emoji": {
                "type": "string",
                "minLength": 1,
                "maxLength": 16
              }
            },
            "required": [
              "color"
            ]
          },
          "connectionRef": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": "string"
          },
          "params": {
            "type": "object",
            "properties": {
              "temperature": {
                "type": "number",
                "minimum": 0,
                "maximum": 2
              },
              "maxTokens": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991
              },
              "topP": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "maxToolIterations": {
                "type": "integer",
                "minimum": 1,
                "maximum": 200
              }
            }
          },
          "tags": {
            "maxItems": 20,
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 32
            }
          },
          "toolServerRefs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            }
          },
          "roots": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "minLength": 1
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "read",
                    "readwrite"
                  ]
                }
              },
              "required": [
                "path",
                "mode"
              ]
            }
          },
          "permissionPolicy": {
            "type": "string",
            "enum": [
              "ask",
              "allow-writes",
              "read-only"
            ]
          }
        },
        "required": [
          "name",
          "avatar",
          "connectionRef",
          "model",
          "role",
          "params",
          "tags",
          "toolServerRefs",
          "roots",
          "permissionPolicy"
        ]
      }
    }
  },
  "required": [
    "format",
    "version",
    "exportedAt",
    "app",
    "connections",
    "toolServers",
    "agents"
  ]
}
