{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/contracts/workspace-activity-event.v1.json",
  "title": "Workspai Workspace Activity Event",
  "description": "Local-first operational activity emitted by Workspai commands. Activity is observational and does not by itself establish evidence or decision authority.",
  "type": "object",
  "required": [
    "schemaVersion",
    "eventId",
    "sequence",
    "timestamp",
    "runId",
    "scope",
    "kind",
    "status",
    "component",
    "message"
  ],
  "properties": {
    "schemaVersion": { "const": "workspace-activity-event.v1" },
    "eventId": { "type": "string", "minLength": 8 },
    "sequence": { "type": "integer", "minimum": 1 },
    "timestamp": { "type": "string", "format": "date-time" },
    "runId": { "type": "string", "minLength": 8 },
    "parentRunId": { "type": "string", "minLength": 8 },
    "spanId": { "type": "string", "minLength": 1 },
    "parentSpanId": { "type": "string", "minLength": 1 },
    "causationId": { "type": "string", "minLength": 1 },
    "correlationId": { "type": "string", "minLength": 1 },
    "scope": {
      "type": "object",
      "required": ["kind", "id", "label", "portable"],
      "properties": {
        "kind": { "enum": ["ephemeral-project", "project", "workspace"] },
        "id": { "type": "string", "minLength": 8 },
        "label": { "type": "string", "minLength": 1 },
        "portable": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "kind": {
      "enum": [
        "run.started",
        "run.completed",
        "run.failed",
        "run.cancelled",
        "block.planned",
        "block.started",
        "block.progress",
        "block.completed",
        "block.failed",
        "block.blocked",
        "block.skipped",
        "edge.declared",
        "operation.started",
        "operation.completed",
        "operation.failed",
        "touch.planned",
        "touch.observed",
        "artifact.published",
        "artifact.rejected",
        "warning.detected"
      ]
    },
    "status": {
      "enum": [
        "planned",
        "running",
        "succeeded",
        "warned",
        "blocked",
        "failed",
        "cancelled",
        "skipped",
        "rolled-back"
      ]
    },
    "component": { "type": "string", "minLength": 1 },
    "message": { "type": "string", "minLength": 1 },
    "blockId": { "type": "string", "minLength": 1 },
    "attempt": { "type": "integer", "minimum": 1 },
    "origin": {
      "type": "object",
      "required": ["id", "kind", "label"],
      "properties": {
        "id": { "type": "string", "minLength": 8 },
        "kind": { "enum": ["project", "workspace-root"] },
        "label": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "projectId": { "type": "string", "minLength": 1 },
    "durationMs": { "type": "number", "minimum": 0 },
    "progress": {
      "type": "object",
      "properties": {
        "completed": { "type": "number", "minimum": 0 },
        "total": { "type": "number", "minimum": 0 },
        "percent": { "type": "number", "minimum": 0, "maximum": 100 },
        "iteration": { "type": "number", "minimum": 0 },
        "iterations": { "type": "number", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "target": {
      "type": "object",
      "required": ["kind"],
      "properties": {
        "kind": {
          "enum": ["file", "directory", "artifact", "process", "workspace", "project", "other"]
        },
        "locator": { "type": "string" },
        "operation": { "type": "string" },
        "provenance": { "enum": ["authoritative", "observed", "inferred"] }
      },
      "additionalProperties": false
    },
    "evidenceBindings": {
      "type": "array",
      "maxItems": 100,
      "items": { "$ref": "#/$defs/evidenceBinding" }
    },
    "edge": {
      "type": "object",
      "required": ["id", "fromBlockId", "toBlockId", "kind"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "fromBlockId": { "type": "string", "minLength": 1 },
        "toBlockId": { "type": "string", "minLength": 1 },
        "kind": { "enum": ["sequence", "parallel", "gate", "handoff"] }
      },
      "additionalProperties": false
    },
    "attributes": { "type": "object", "additionalProperties": true }
  },
  "additionalProperties": false,
  "$defs": {
    "evidenceBinding": {
      "type": "object",
      "required": ["kind", "ref", "role", "provenance"],
      "properties": {
        "kind": { "enum": ["artifact", "graph-entity", "graph-relation", "proof", "project"] },
        "ref": { "type": "string", "minLength": 1 },
        "role": { "enum": ["input", "output", "verification", "subject"] },
        "provenance": { "enum": ["authoritative", "observed"] },
        "graphSourceHash": { "type": "string", "minLength": 1 }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": { "enum": ["graph-entity", "graph-relation", "proof"] }
            },
            "required": ["kind"]
          },
          "then": { "required": ["graphSourceHash"] }
        }
      ],
      "additionalProperties": false
    }
  }
}
