{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/workspace-intelligence/workspace-context.v1.json",
  "title": "Workspai Workspace Agent Context",
  "type": "object",
  "required": [
    "schemaVersion",
    "generatedAt",
    "agent",
    "workspaceSummary",
    "modelRef",
    "knowledgeGraph",
    "intelligenceChain",
    "workspace",
    "scope",
    "projects",
    "safeCommands",
    "validation"
  ],
  "properties": {
    "schemaVersion": {
      "const": "workspace-context.v1"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "agent": {
      "enum": [
        "generic",
        "codex",
        "claude",
        "cursor",
        "gemini",
        "qwen",
        "kimi",
        "grok",
        "copilot",
        "windsurf",
        "amazon-q",
        "orca"
      ]
    },
    "workspaceSummary": { "type": "string" },
    "modelRef": { "type": "string" },
    "knowledgeGraph": {
      "type": "object",
      "required": ["artifact", "schemaVersion", "available", "queryCommands"],
      "properties": {
        "artifact": { "const": ".workspai/reports/workspace-knowledge-graph.json" },
        "schemaVersion": { "const": "workspace-knowledge-graph.v1" },
        "available": { "type": "boolean" },
        "entityCount": { "type": "integer", "minimum": 0 },
        "relationCount": { "type": "integer", "minimum": 0 },
        "proofCount": { "type": "integer", "minimum": 0 },
        "queryCommands": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "minItems": 3,
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "intelligenceChain": {
      "type": "object",
      "required": ["schemaVersion", "contractPath", "currentStep", "canonicalReadOrder"],
      "properties": {
        "schemaVersion": { "const": "workspai-workspace-intelligence-chain-v1" },
        "contractPath": { "const": "contracts/workspace-intelligence-chain.v1.json" },
        "currentStep": { "const": "context" },
        "canonicalReadOrder": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "workspace": {
      "type": "object",
      "required": ["name", "root", "type"],
      "properties": {
        "name": { "type": "string" },
        "root": {
          "type": "string",
          "description": "Portable workspace identity (workspace:<name>), never a machine-local filesystem path."
        },
        "type": { "type": "string" },
        "profile": { "type": "string" }
      },
      "additionalProperties": false
    },
    "scope": { "type": "object", "additionalProperties": true },
    "projects": { "type": "array", "items": { "type": "object", "additionalProperties": true } },
    "safeCommands": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "factFreshness": { "$ref": "#/$defs/factFreshnessSummary" },
    "facts": {
      "type": "array",
      "items": { "$ref": "#/$defs/workspaceFact" }
    },
    "validation": {
      "type": "object",
      "required": ["status", "errors", "warnings"],
      "properties": {
        "status": {
          "enum": ["passed", "warning", "failed"]
        },
        "errors": { "type": "integer", "minimum": 0 },
        "warnings": { "type": "integer", "minimum": 0 }
      },
      "additionalProperties": true
    }
  },
  "$defs": {
    "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
}
