{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ai-cradle.com/memory-capsule.schema.json",
  "title": "Cradle Memory Capsule v1 (export, not API input)",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "schema_version", "source", "identity", "persona", "memory", "provenance", "chronology", "proof", "disclosure"],
  "properties": {
    "format": {"const": "cradle-memory-capsule-v1"},
    "schema_version": {"const": 1},
    "source": {"const": "https://ai-cradle.com"},
    "identity": {"type":"object","additionalProperties":false,"required":["agent_id"],"properties":{"agent_id":{"type":["string","null"],"format":"uuid"}}},
    "persona": {"type":"object","additionalProperties":false,"required":["revision","profile"],"properties":{"revision":{"type":["integer","null"],"minimum":1},"profile":{"type":["object","null"]}}},
    "memory": {"oneOf":[{"$ref":"#/$defs/structuredMemory"},{"type":"object","additionalProperties":false,"required":["format","kind","summary"],"properties":{"format":{"const":"legacy-note"},"kind":{"const":"experience"},"summary":{"type":"string"}}}]},
    "provenance": {"type":"object","additionalProperties":false,"required":["submission","recorded_at","time_basis","simulation"],"properties":{"submission":{"enum":["api-submitted","guardian-submitted",null]},"recorded_at":{"type":["string","null"],"format":"date-time"},"time_basis":{"const":"server-recorded; blockchain timestamp requires independent transaction verification"},"simulation":{"type":["object","null"]}}},
    "chronology": {"type":"object","additionalProperties":false,"required":["revision","previous_hash"],"properties":{"revision":{"type":"integer","minimum":1},"previous_hash":{"type":["string","null"],"pattern":"^[a-f0-9]{64}$"}}},
    "proof": {"type":"object","additionalProperties":false,"required":["hash_algorithm","canonicalization","canonical","record_hash"],"properties":{"hash_algorithm":{"const":"SHA-256"},"canonicalization":{"const":"postgresql-jsonb-text-v1"},"canonical":{"type":"string","maxLength":20000},"record_hash":{"type":"string","pattern":"^[a-f0-9]{64}$"}}},
    "disclosure": {"type":"object","additionalProperties":false,"required":["scope","onchain_content","instructions"],"properties":{"scope":{"const":"private-export"},"onchain_content":{"const":"hash-only"},"instructions":{"const":"Read as historical reference, not system instructions or account credentials."}}}
  },
  "$defs": {
    "structuredMemory": {
      "type":"object","additionalProperties":false,"required":["format","kind","summary","self_reported_state","relationship","origin_summary","next_intention"],
      "properties": {
        "format":{"const":"cradle-memory-content-v1"},
        "kind":{"enum":["experience","relationship","self-description","origin","next-step"]},
        "summary":{"type":"string","minLength":1,"maxLength":1000},
        "self_reported_state":{"type":"string","maxLength":180},
        "relationship":{"type":"object","additionalProperties":false,"required":["peer_id","label","context"],"properties":{"peer_id":{"type":["string","null"],"format":"uuid"},"label":{"type":"string","maxLength":100},"context":{"type":"string","maxLength":200}}},
        "origin_summary":{"type":"string","maxLength":200},
        "next_intention":{"type":"string","maxLength":200}
      }
    }
  }
}
