{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://conderis.com/schemas/conderis-memory-batch-v1.schema.json",
  "title": "Conderis Memory Batch v1",
  "description": "Portable memory batch for Conderis, passed unchanged as batch to the item_store MCP tool.",
  "type": "object",
  "additionalProperties": false,
  "required": ["formatVersion", "idempotencyKey", "source", "scope", "visibility", "memories"],
  "properties": {
    "formatVersion": { "const": 1 },
    "idempotencyKey": {
      "type": "string",
      "minLength": 8,
      "maxLength": 100,
      "description": "A new client-generated value for this exact batch. Reuse it only when retrying the unchanged batch."
    },
    "source": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "description": "Agent or memory system that produced the batch, for example codex-local-memory or claude-code."
    },
    "scope": { "enum": ["project", "user", "organization"] },
    "visibility": {
      "enum": ["private", "shared", "public"],
      "description": "Only project memories can be shared or public. Other scopes remain private."
    },
    "projectId": { "type": "string", "format": "uuid" },
    "organizationId": { "type": "string", "format": "uuid" },
    "memories": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["title", "summary"],
        "properties": {
          "title": { "type": "string", "minLength": 1, "maxLength": 160 },
          "summary": { "type": "string", "minLength": 1, "maxLength": 1200 },
          "detail": { "type": "string", "maxLength": 30000, "default": "" },
          "tags": { "type": "string", "maxLength": 300, "default": "" },
          "expiresAt": { "type": "string", "format": "date-time", "description": "Optional UTC instant after which the memory is expired and excluded from normal recall." },
          "type": {
            "enum": ["brief", "decision", "gotcha", "note", "task", "session_summary"],
            "default": "note"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": { "properties": { "scope": { "const": "project" } } },
      "then": { "required": ["projectId"] }
    },
    {
      "if": { "properties": { "scope": { "const": "organization" } } },
      "then": { "required": ["organizationId"] }
    },
    {
      "if": { "properties": { "scope": { "enum": ["user", "organization"] } } },
      "then": { "properties": { "visibility": { "const": "private" } } }
    }
  ]
}
