{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "/marketplace-schemas/local-library.schema.json",
  "title": "SecurityRecipes local marketplace library",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "exported_at",
    "browser_model",
    "workflow_templates",
    "input_channels",
    "output_channels"
  ],
  "properties": {
    "schema_version": {
      "const": "securityrecipes.marketplace.local-library.v1"
    },
    "exported_at": {
      "type": "string",
      "format": "date-time"
    },
    "browser_model": {
      "const": "client_side_byo_token"
    },
    "workflow_templates": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/localWorkflowTemplate"
      }
    },
    "input_channels": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/localInputChannel"
      }
    },
    "output_channels": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/localOutputChannel"
      }
    },
    "report_profiles": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/localReportProfile"
      }
    }
  },
  "$defs": {
    "runtimeSupport": {
      "type": "string",
      "enum": ["live", "live_or_copy", "copy_only", "config_only", "planned", "contract"]
    },
    "localId": {
      "type": "string",
      "pattern": "^local-[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "marketplaceId": {
      "type": "string",
      "pattern": "^(?:local-)?[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "configObject": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "pattern": "^[a-z0-9_:-]+$"
        }
      },
      "additionalProperties": true
    },
    "governanceObject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pack_version", "owner", "reviewed_at", "review_cadence_days"],
      "properties": {
        "pack_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 40,
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
        },
        "owner": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "reviewed_at": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "review_cadence_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 365
        },
        "docs_href": {
          "type": "string",
          "minLength": 1,
          "maxLength": 240
        },
        "required_pack_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/marketplaceId"
          }
        },
        "optional_pack_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/marketplaceId"
          }
        },
        "capability_tags": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]*$"
          }
        }
      }
    },
    "localInputChannel": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "source",
        "category",
        "description",
        "auth_modes",
        "runtime_support",
        "config",
        "status",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/localId"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "source": {
          "const": "local"
        },
        "category": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 320
        },
        "auth_modes": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9_-]+$"
          }
        },
        "runtime_support": {
          "$ref": "#/$defs/runtimeSupport"
        },
        "config": {
          "$ref": "#/$defs/configObject"
        },
        "status": {
          "const": "local"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "governance": {
          "$ref": "#/$defs/governanceObject"
        }
      }
    },
    "localOutputChannel": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "source",
        "category",
        "driver",
        "value",
        "requirement",
        "description",
        "runtime_support",
        "browser_delivery",
        "config",
        "status",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/localId"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "source": {
          "const": "local"
        },
        "category": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "driver": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "value": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "requirement": {
          "type": "string",
          "minLength": 1,
          "maxLength": 260
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 320
        },
        "runtime_support": {
          "$ref": "#/$defs/runtimeSupport"
        },
        "browser_delivery": {
          "type": "boolean"
        },
        "config": {
          "$ref": "#/$defs/configObject"
        },
        "status": {
          "const": "local"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "governance": {
          "$ref": "#/$defs/governanceObject"
        }
      }
    },
    "localReportProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "source",
        "status",
        "category",
        "format",
        "description",
        "sections",
        "example_output",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/localId"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "source": {
          "const": "local"
        },
        "status": {
          "const": "local"
        },
        "category": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "format": {
          "type": "string",
          "enum": ["json", "markdown", "markdown+json"]
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 320
        },
        "sections": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "example_output": {
          "type": "object",
          "additionalProperties": true
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "governance": {
          "$ref": "#/$defs/governanceObject"
        }
      }
    },
    "localWorkflowTemplate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "source",
        "status",
        "workflow_value",
        "description",
        "default_recipe_query",
        "default_context_pack",
        "default_report_profile_id",
        "default_output_channel_id",
        "default_input_channel_ids",
        "default_approval_gate",
        "default_cadence",
        "target_hint",
        "created_at",
        "updated_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/localId"
        },
        "label": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "source": {
          "const": "local"
        },
        "status": {
          "const": "local"
        },
        "workflow_value": {
          "type": "string",
          "enum": [
            "dependency",
            "sast",
            "sensitive-data",
            "mcp-guardrail",
            "base-image",
            "recipe-runbook"
          ]
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 320
        },
        "default_recipe_query": {
          "type": "string",
          "minLength": 1
        },
        "default_context_pack": {
          "type": "string",
          "minLength": 1
        },
        "default_report_profile_id": {
          "$ref": "#/$defs/marketplaceId"
        },
        "default_output_channel_id": {
          "$ref": "#/$defs/marketplaceId"
        },
        "default_input_channel_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/marketplaceId"
          }
        },
        "default_approval_gate": {
          "type": "string",
          "minLength": 1
        },
        "default_cadence": {
          "type": "string",
          "minLength": 1
        },
        "target_hint": {
          "type": "string",
          "maxLength": 160
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "governance": {
          "$ref": "#/$defs/governanceObject"
        }
      }
    }
  }
}
