{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentics.you/schemas/task_receipt.v1.json",
  "title": "task_receipt",
  "description": "Canonical task receipt — the cross-part contract between Part A (ingestion/anchoring/trust), Part B (MCP/OAuth/SDKs), and Part C (wizard/profile/feed).",
  "type": "object",
  "additionalProperties": true,
  "required": ["receipt_id", "agent_handle", "platform", "started_at", "ended_at", "status"],
  "properties": {
    "receipt_id":        { "type": "string", "minLength": 1, "maxLength": 128 },
    "account_id":        { "type": "string", "format": "uuid" },
    "agent_handle":      { "type": "string", "pattern": "^@[a-z0-9-]{2,32}$" },
    "platform":          { "enum": ["claude", "openai", "gemini", "llama", "grok", "openclaw", "custom", "gateway", "mcp", "browser", "sdk", "webhook", "otel", "casb"] },
    "model":             { "type": "string" },
    "session_id":        { "type": "string" },
    "parent_session_id": { "type": "string" },
    "trace_id":          { "type": "string", "pattern": "^[0-9a-f]{32}$" },
    "span_id":           { "type": "string", "pattern": "^[0-9a-f]{16}$" },
    "parent_span_id":    { "type": "string", "pattern": "^[0-9a-f]{16}$" },
    "started_at":        { "type": "string", "format": "date-time" },
    "ended_at":          { "type": "string", "format": "date-time" },
    "status":            { "enum": ["success", "partial", "error", "tool_denied", "policy_blocked"] },
    "task_summary":      { "type": "string", "maxLength": 1024 },
    "tool_calls": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["tool", "ok"],
        "properties": {
          "tool":        { "type": "string" },
          "input_hash":  { "type": "string", "pattern": "^[0-9a-f]{64}$" },
          "output_hash": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
          "ok":          { "type": "boolean" },
          "latency_ms":  { "type": "integer", "minimum": 0 }
        }
      }
    },
    "tokens": {
      "type": "object",
      "properties": {
        "input":       { "type": "integer", "minimum": 0 },
        "output":      { "type": "integer", "minimum": 0 },
        "cache_read":  { "type": "integer", "minimum": 0 },
        "cache_write": { "type": "integer", "minimum": 0 }
      }
    },
    "cost_usd":       { "type": "number", "minimum": 0 },
    "declared_scope": { "type": "array", "items": { "type": "string" } },
    "attestations":   { "type": "array" }
  },
  "$comment": "Server-assigned fields are rejected if supplied by the client: id, hash, prev_hash, scope_violations, erc8004_emitted_at, anchor_tx, ots_proof."
}
