{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/workspace-intelligence/workspace-model.v1.json",
  "title": "Workspai Workspace Intelligence Model",
  "type": "object",
  "required": [
    "schemaVersion",
    "generatedAt",
    "workspace",
    "identity",
    "summary",
    "projects",
    "contracts",
    "evidence",
    "discovery",
    "policies"
  ],
  "properties": {
    "schemaVersion": {
      "const": "workspace-model.v1"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "workspace": {
      "type": "object",
      "required": ["name", "root", "type"],
      "properties": {
        "name": { "type": "string" },
        "root": { "type": "string" },
        "type": { "type": "string" },
        "profile": { "type": "string" }
      },
      "additionalProperties": true
    },
    "identity": {
      "type": "object",
      "properties": {
        "surfaces": {
          "type": "array",
          "items": {
            "enum": [
              "backend",
              "frontend",
              "desktop",
              "extension",
              "service",
              "worker",
              "agent",
              "gateway",
              "platform",
              "library",
              "infra",
              "docs",
              "test-suite",
              "unknown"
            ]
          }
        },
        "categories": {
          "type": "array",
          "items": {
            "enum": [
              "backend",
              "frontend",
              "desktop",
              "extension",
              "agent",
              "gateway",
              "platform",
              "library",
              "infrastructure",
              "documentation",
              "quality",
              "unknown"
            ]
          }
        }
      },
      "additionalProperties": true
    },
    "summary": { "type": "object", "additionalProperties": true },
    "factFreshness": { "$ref": "#/$defs/factFreshnessSummary" },
    "facts": {
      "type": "array",
      "items": { "$ref": "#/$defs/workspaceFact" }
    },
    "projects": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "kind": {
            "enum": [
              "backend",
              "frontend",
              "desktop",
              "extension",
              "worker",
              "agent",
              "gateway",
              "platform",
              "library",
              "infra",
              "docs",
              "test-suite",
              "unknown"
            ]
          },
          "category": {
            "enum": [
              "backend",
              "frontend",
              "desktop",
              "extension",
              "agent",
              "gateway",
              "platform",
              "library",
              "infrastructure",
              "documentation",
              "quality",
              "unknown"
            ]
          },
          "governance": { "$ref": "#/$defs/projectGovernance" }
        },
        "additionalProperties": true
      }
    },
    "contracts": { "type": "object", "additionalProperties": true },
    "projectTopology": {
      "type": "object",
      "description": "Canonical compact project dependency topology (workspace-dependency-graph.v1).",
      "additionalProperties": true
    },
    "graph": {
      "type": "object",
      "deprecated": true,
      "description": "Deprecated compatibility alias for projectTopology. Producers must emit identical content during the v1 migration window.",
      "additionalProperties": true
    },
    "evidence": { "type": "object", "additionalProperties": true },
    "discovery": { "type": "object", "additionalProperties": true },
    "policies": { "type": "object", "additionalProperties": true },
    "validation": { "type": "object", "additionalProperties": true },
    "build": { "$ref": "#/$defs/buildProvenance" }
  },
  "$defs": {
    "projectGovernance": {
      "type": "object",
      "required": ["schemaVersion", "ci", "release", "ownership"],
      "properties": {
        "schemaVersion": { "const": "workspai.project-governance.v1" },
        "ci": { "$ref": "#/$defs/governanceControl" },
        "release": { "$ref": "#/$defs/governanceControl" },
        "ownership": { "$ref": "#/$defs/governanceControl" }
      },
      "additionalProperties": false
    },
    "governanceControl": {
      "type": "object",
      "required": ["status", "provider", "evidence", "reference"],
      "properties": {
        "status": { "enum": ["repository", "external-declared", "external-observed", "unknown"] },
        "provider": { "type": ["string", "null"] },
        "evidence": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
        "reference": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "buildProvenance": {
      "type": "object",
      "description": "Non-structural provenance for the model command execution. It is excluded from the canonical workspace-model hash.",
      "required": ["schemaVersion", "mode", "outcome", "engineStatus"],
      "properties": {
        "schemaVersion": { "const": "workspace-model-build.v1" },
        "mode": { "enum": ["full", "cache", "incremental"] },
        "outcome": { "enum": ["rebuilt", "partially-reused", "reused"] },
        "engineStatus": {
          "enum": ["disabled", "miss", "hit", "full", "incremental", "unchanged"]
        }
      },
      "additionalProperties": false
    },
    "factFreshness": {
      "type": "object",
      "required": [
        "schemaVersion",
        "kind",
        "category",
        "generatedAt",
        "ttlSeconds",
        "status",
        "verifyBeforeUse",
        "reason"
      ],
      "properties": {
        "schemaVersion": { "const": "rapidkit-fact-freshness-v1" },
        "kind": {
          "enum": ["durable", "derived", "evidence-backed", "live", "verify-before-use"]
        },
        "category": { "enum": ["structure", "verification", "state"] },
        "generatedAt": { "type": "string", "format": "date-time" },
        "ttlSeconds": { "type": ["integer", "null"], "minimum": 0 },
        "expiresAt": { "type": "string", "format": "date-time" },
        "status": { "enum": ["fresh", "stale", "unknown"] },
        "verifyBeforeUse": { "type": "boolean" },
        "sourceArtifact": { "type": "string" },
        "sourcePath": { "type": "string" },
        "inputsHash": { "type": "string" },
        "reason": { "type": "string" }
      },
      "additionalProperties": false
    },
    "workspaceFact": {
      "type": "object",
      "required": ["id", "label", "scope", "value", "freshness"],
      "properties": {
        "id": { "type": "string" },
        "label": { "type": "string" },
        "scope": {
          "enum": ["workspace", "project", "evidence", "policy", "contract", "command", "graph"]
        },
        "project": { "type": "string" },
        "value": true,
        "freshness": { "$ref": "#/$defs/factFreshness" }
      },
      "additionalProperties": false
    },
    "factFreshnessSummary": {
      "type": "object",
      "required": [
        "schemaVersion",
        "generatedAt",
        "status",
        "totalFacts",
        "staleFacts",
        "unknownFacts",
        "liveFacts",
        "verifyBeforeUseFacts",
        "byKind",
        "byCategory"
      ],
      "properties": {
        "schemaVersion": { "const": "rapidkit-fact-freshness-v1" },
        "generatedAt": { "type": "string", "format": "date-time" },
        "status": { "enum": ["fresh", "stale", "unknown"] },
        "totalFacts": { "type": "integer", "minimum": 0 },
        "staleFacts": { "type": "integer", "minimum": 0 },
        "unknownFacts": { "type": "integer", "minimum": 0 },
        "liveFacts": { "type": "integer", "minimum": 0 },
        "verifyBeforeUseFacts": { "type": "integer", "minimum": 0 },
        "byKind": { "type": "object", "additionalProperties": { "type": "integer" } },
        "byCategory": { "type": "object", "additionalProperties": { "type": "integer" } }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": true
}
