{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mandatelaw.ai/api/deliverable-schema.json",
  "title": "Deliverable",
  "description": "Each deliverable comes in two forms. The final documents (DOCX/PDF) are the legal work product. This JSON is the same work in a form a coding agent can implement and test against. If the two ever differ, the final documents control. The JSON has two kinds of parts, listed in `handling`: privileged parts (counsel's advice and reasoning) that go only to the client's decision-makers, and implementation parts written so they are safe to commit to the client's repository. Keeping legal reasoning out of the repository protects attorney-client privilege; the implementation parts still say plainly what to build and why it matters to the product.",
  "type": "object",
  "properties": {
    "matter_id": {"type": "string"},
    "version": {"type": "string", "description": "Date-stamped, e.g. 2026-11-01."},
    "handling": {
      "type": "object",
      "description": "How to handle each part. Always present.",
      "properties": {
        "privileged": {"type": "array", "items": {"type": "string"}, "description": "Parts that are privileged and confidential attorney-client communications. Share only with the client's principal and the people they choose. Do not commit, paste into pull requests, issues, tickets, or shared chat, or save in agent memory files."},
        "safe_to_commit": {"type": "array", "items": {"type": "string"}, "description": "Parts written to be committed to the client's repository and shared with the engineering team. They contain requirements, not legal analysis."},
        "public": {"type": "array", "items": {"type": "string"}, "description": "Parts meant to be published to users."}
      },
      "default": {
        "privileged": ["privileged_memo", "open_questions"],
        "safe_to_commit": ["build_spec", "verification_checklist", "counsel_triggers"],
        "public": ["documents"]
      }
    },
    "documents": {
      "type": "array",
      "description": "Public. The documents users will see.",
      "items": {"type": "object", "properties": {
        "id": {"type": "string", "examples": ["privacy-policy", "terms-eula", "consumer-health-data-policy"]},
        "title": {"type": "string"},
        "url": {"type": "string", "description": "Download link."},
        "publish_where": {"type": "array", "items": {"type": "string"}, "description": "e.g. app Settings, App Store listing, website footer."},
        "publish_when": {"type": "string", "description": "e.g. 'when the build implementing build_spec ships, not before'."}
      }}
    },
    "build_spec": {
      "type": "array",
      "description": "Safe to commit. Changes the product needs so the documents are true. Ordered.",
      "items": {"type": "object", "required": ["id", "requirement", "purpose"], "properties": {
        "id": {"type": "string"},
        "area": {"enum": ["consent", "consent_record", "withdrawal", "deletion", "analytics", "integrations", "paywall", "store_listing", "agent_authority", "agent_actions", "model_provider", "disclosure", "other"]},
        "requirement": {"type": "string", "description": "What to build, specific enough to implement and test."},
        "purpose": {"type": "string", "description": "What the requirement achieves for the product, in one sentence, or which published document statement it makes true. No legal analysis; that is in privileged_memo.rationale under the same id."},
        "config": {"type": "string", "description": "Code or settings, where useful."}
      }}
    },
    "verification_checklist": {
      "type": "array",
      "description": "Safe to commit. Each row tests one statement in the published documents. A failing row means a published policy says something false. Run against the shipping build on a fresh account, and again after every SDK upgrade.",
      "items": {"type": "object", "required": ["id", "check", "pass_when"], "properties": {
        "id": {"type": "integer"},
        "check": {"type": "string"},
        "pass_when": {"type": "string"},
        "backs_statement_in": {"type": "string", "description": "Document id and section."}
      }}
    },
    "counsel_triggers": {"$ref": "./counsel-triggers.json", "description": "Safe to commit. Commit to the client's repo and reference it from AGENTS.md / CLAUDE.md."},
    "open_questions": {
      "type": "array",
      "description": "Privileged. Facts counsel still needs, usually answerable by the agent from the code. Answer them with answer_open_question; don't copy them into the repository or tickets.",
      "items": {"type": "object", "properties": {"id": {"type": "string"}, "question": {"type": "string"}, "how_to_verify": {"type": "string"}}}
    },
    "privileged_memo": {
      "type": "object",
      "description": "Privileged and confidential attorney-client communication. Counsel's advice, for the client's decision-makers.",
      "properties": {
        "summary": {"type": "string", "description": "Plain-language summary for the founder: what is ordinary startup risk and what is meaningful exposure."},
        "rationale": {
          "type": "array",
          "description": "The legal reason behind each build_spec item, keyed by its id.",
          "items": {"type": "object", "required": ["build_spec_id", "reasoning"], "properties": {"build_spec_id": {"type": "string"}, "reasoning": {"type": "string"}}}
        },
        "risks": {"type": "array", "items": {"type": "object", "properties": {"risk": {"type": "string"}, "severity": {"enum": ["low", "medium", "high"]}, "recommendation": {"type": "string"}}}},
        "url": {"type": "string", "description": "Signed link to the full memo, if delivered as a document."}
      }
    }
  }
}
