{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/boshu2/agentops/docs/contracts/rpi-phase-result.schema.json",
  "title": "RPI Phase Result",
  "description": "Schema for phase-{N}-result.json artifacts emitted by the ao rpi phased orchestrator after each phase completes or fails.",
  "type": "object",
  "required": [
    "schema_version",
    "run_id",
    "phase",
    "phase_name",
    "status",
    "started_at"
  ],
  "properties": {
    "schema_version": {
      "type": "integer",
      "description": "Schema version for forward compatibility. Current version: 1.",
      "const": 1
    },
    "run_id": {
      "type": "string",
      "description": "Unique identifier for this RPI run (hex string, matches worktree branch suffix).",
      "minLength": 1
    },
    "phase": {
      "type": "integer",
      "description": "Phase number (1-3).",
      "minimum": 1,
      "maximum": 3
    },
    "phase_name": {
      "type": "string",
      "description": "Human-readable phase name.",
      "enum": ["discovery", "implementation", "validation"]
    },
    "status": {
      "type": "string",
      "description": "Outcome of this phase.",
      "enum": ["started", "completed", "failed", "retrying", "time_boxed"]
    },
    "retries": {
      "type": "integer",
      "description": "Number of retry attempts for this phase.",
      "default": 0,
      "minimum": 0
    },
    "error": {
      "type": "string",
      "description": "Error message when status is 'failed'."
    },
    "backend": {
      "type": "string",
      "description": "Execution backend used for this phase.",
      "enum": ["direct", "stream", "tmux"]
    },
    "artifacts": {
      "type": "object",
      "description": "Map of artifact names to file paths produced by this phase.",
      "additionalProperties": {
        "type": "string"
      }
    },
    "verdicts": {
      "type": "object",
      "description": "Map of gate names to verdict strings (PASS/WARN/FAIL).",
      "additionalProperties": {
        "type": "string"
      }
    },
    "started_at": {
      "type": "string",
      "description": "ISO 8601 timestamp when the phase started.",
      "format": "date-time"
    },
    "completed_at": {
      "type": "string",
      "description": "ISO 8601 timestamp when the phase completed.",
      "format": "date-time"
    },
    "duration_seconds": {
      "type": "number",
      "description": "Wall-clock duration in seconds.",
      "minimum": 0
    }
  },
  "additionalProperties": false
}
