{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Cortex Agent Run",
  "type": "object",
  "required": ["run_id", "kind", "status", "started_at"],
  "properties": {
    "run_id": { "type": "string" },
    "task_id": { "type": ["string", "null"] },
    "mission_id": { "type": ["string", "null"] },
    "agent_id": { "type": ["string", "null"] },
    "role": { "type": ["string", "null"] },
    "kind": { "type": "string", "enum": ["plan", "implement", "validate", "merge", "handoff", "dashboard", "publish"] },
    "status": { "type": "string", "enum": ["queued", "running", "completed", "failed", "canceled"] },
    "phase": {
      "type": ["string", "null"],
      "enum": [
        null,
        "initializing",
        "briefing",
        "decomposing",
        "planning",
        "queueing",
        "creating_worktree",
        "acquiring_lock",
        "invoking_agent",
        "reading",
        "editing",
        "running_command",
        "validating",
        "handoff",
        "merging",
        "publishing",
        "waiting",
        "blocked",
        "completed"
      ]
    },
    "activity": { "type": ["string", "null"] },
    "last_event": { "type": ["object", "null"] },
    "events": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["type", "at"],
        "properties": {
          "type": {
            "type": "string",
            "description": "Stable event type. Recognized values include: state_changed, task_decomposed, worktree_created, lock_acquired, agent_invoked, file_read, file_edited, command_started, command_finished, validation_started, validation_passed, validation_failed, handoff_created, merge_started, merge_completed, publish_started, publish_completed, blocked, failed, canceled, completed, human_observation, tool_failure, investigation_step, handoff_auto_generated, transcript_linked, vcs_pr_opened, vcs_pr_merged, vcs_pr_closed, subagent_spawned, subagent_progress, subagent_completed, subagent_cancelled."
          },
          "phase": { "type": ["string", "null"] },
          "status": { "type": ["string", "null"] },
          "activity": { "type": ["string", "null"] },
          "message": { "type": ["string", "null"] },
          "at": { "type": "string" }
        },
        "additionalProperties": true
      }
    },
    "worktree_path": { "type": ["string", "null"] },
    "branch": { "type": ["string", "null"] },
    "base_commit": { "type": ["string", "null"] },
    "head_commit": { "type": ["string", "null"] },
    "started_at": { "type": "string" },
    "finished_at": { "type": ["string", "null"] },
    "commands": { "type": "array" },
    "artifacts": { "type": "array" },
    "validation": { "type": "object" },
    "next_action": { "type": ["string", "null"] }
  },
  "additionalProperties": true
}
