types:
  Person:
    required: [name]
    properties:
      name: string
      email: string?
      phone: string?
      organization: ref(Organization)?
      notes: string?
      tags: string[]?
      pronouns: string?
      timezone: string?

  Organization:
    required: [name]
    properties:
      name: string
      type: enum(company, team, community, government, other)?
      website: url?
      members: ref(Person)[]?

  Agent:
    required: [id, name]
    properties:
      id: string
      name: string
      type: enum[dev, legal, planner, assistant]
      workspace: string?
      model: string?
      status: enum[active, inactive, planned]

  Project:
    required: [name]
    properties:
      name: string
      description: string?
      status: enum(planning, active, paused, completed, archived)
      owner: ref(Person)?
      team: ref(Person)[]?
      goals: ref(Goal)[]?
      start_date: date?
      end_date: date?
      folder: string?
      doc_path: string?
      tags: string[]?

  Task:
    required: [title, status]
    properties:
      title: string
      description: string?
      status: enum(open, in_progress, blocked, done, cancelled)
      priority: enum(low, medium, high, urgent)?
      assignee: ref(Person)?
      project: ref(Project)?
      due: datetime?
      estimate_hours: number?
      folder: string?
      doc_path: string?
      blockers: ref(Task)[]?
      tags: string[]?

  Goal:
    required: [description]
    properties:
      description: string
      target_date: date?
      status: enum(active, achieved, abandoned)?
      metrics: object[]?
      key_results: string[]?

  Event:
    required: [title, start]
    properties:
      title: string
      description: string?
      start: datetime
      end: datetime?
      location: ref(Location)?
      attendees: ref(Person)[]?
      recurrence: object?
      status: enum(confirmed, tentative, cancelled)?
      reminders: object[]?

  Location:
    required: [name]
    properties:
      name: string
      address: string?
      city: string?
      country: string?
      coordinates: object?
      timezone: string?

  Document:
    required: [title]
    properties:
      title: string
      path: string?
      url: url?
      mime_type: string?
      summary: string?
      content_hash: string?
      tags: string[]?

  Message:
    required: [content, sender]
    properties:
      content: string
      sender: ref(Person)
      recipients: ref(Person)[]
      thread: ref(Thread)?
      timestamp: datetime
      platform: string?
      external_id: string?

  Thread:
    required: [subject]
    properties:
      subject: string
      participants: ref(Person)[]
      messages: ref(Message)[]
      status: enum(active, archived)?
      last_activity: datetime?

  Note:
    required: [content]
    properties:
      content: string
      title: string?
      tags: string[]?
      refs: ref(Entity)[]?
      created: datetime

  Account:
    required: [service, username]
    properties:
      service: string
      username: string
      url: url?
      credential_ref: ref(Credential)?

  Device:
    required: [name, type]
    properties:
      name: string
      type: enum(computer, phone, tablet, server, iot, other)
      os: string?
      identifiers: object?
      owner: ref(Person)?

  Credential:
    required: [service, secret_ref]
    forbidden_properties: [password, secret, token, key, api_key]
    properties:
      service: string
      secret_ref: string
      expires: datetime?
      scope: string[]?

  Action:
    required: [type, target, timestamp]
    properties:
      type: string
      target: ref(Entity)
      timestamp: datetime
      actor: ref(Person|Agent)?
      outcome: enum(success, failure, pending)?
      details: object?

  Policy:
    required: [scope, rule]
    properties:
      scope: string
      rule: string
      enforcement: enum(block, warn, log)
      enabled: boolean

relations:
  owns:
    from_types: [Person, Organization]
    to_types: [Account, Device, Document, Project]
    cardinality: one_to_many

  has_owner:
    from_types: [Project, Task, Document]
    to_types: [Person]
    cardinality: many_to_one

  assigned_to:
    from_types: [Task]
    to_types: [Person]
    cardinality: many_to_one

  has_task:
    from_types: [Project]
    to_types: [Task]
    cardinality: one_to_many

  depends_on:
    from_types: [Task]
    to_types: [Task]
    cardinality: many_to_many
    acyclic: true

  has_agent:
    from_types: [Project, Task, Person]
    to_types: [Agent]
    cardinality: many_to_many

  uses_service:
    from_types: [Project, Agent]
    to_types: [Service]
    cardinality: many_to_many

  has_skill:
    from_types: [Agent, Project]
    to_types: [Skill]
    cardinality: many_to_many

  knows_rule:
    from_types: [Agent]
    to_types: [Rule]
    cardinality: many_to_many
