{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/workspace-intelligence/agent-bootstrap-receipt.v1.json",
  "title": "Workspai Agent Bootstrap Receipt",
  "description": "Portable per-session proof that an agent resolved canonical project evidence before broad source discovery.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "generatedAt",
    "receiptId",
    "status",
    "statusScope",
    "readiness",
    "requestedAgent",
    "resolvedHost",
    "project",
    "workspace",
    "entry",
    "canonicalEvidence",
    "activeGoal",
    "requiredReadOrder",
    "claims",
    "checks",
    "nextActions",
    "integrity"
  ],
  "properties": {
    "schemaVersion": { "const": "workspai.agent-bootstrap-receipt.v1" },
    "generatedAt": { "type": "string", "format": "date-time" },
    "receiptId": { "$ref": "#/$defs/hash" },
    "status": { "$ref": "#/$defs/status" },
    "statusScope": { "const": "agent-grounding" },
    "readiness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["agentGrounding", "architectureEvidence", "projectEnvironment", "release"],
      "properties": {
        "agentGrounding": { "$ref": "#/$defs/status" },
        "architectureEvidence": { "$ref": "#/$defs/status" },
        "projectEnvironment": { "enum": ["ready", "degraded", "blocked"] },
        "release": { "enum": ["not-verified", "degraded", "blocked"] }
      }
    },
    "requestedAgent": {
      "enum": [
        "generic",
        "codex",
        "claude",
        "gemini",
        "qwen",
        "kimi",
        "grok",
        "copilot",
        "cursor",
        "windsurf",
        "amazon-q",
        "all"
      ]
    },
    "resolvedHost": {
      "enum": [
        "generic",
        "codex",
        "claude",
        "gemini",
        "qwen",
        "kimi",
        "grok",
        "copilot",
        "cursor",
        "windsurf",
        "amazon-q",
        "all"
      ]
    },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "relativePath"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "relativePath": { "$ref": "#/$defs/portablePath" },
        "runtime": { "type": "string", "minLength": 1 },
        "framework": { "type": "string", "minLength": 1 }
      }
    },
    "workspace": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "relationship",
        "resolved",
        "identityIsFilesystemPath",
        "resolverCommand",
        "portableUriScheme",
        "resolvedPathPolicy"
      ],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "relationship": {
          "enum": ["managed", "adopted", "imported", "linked", "restored"]
        },
        "resolved": { "const": true },
        "identityIsFilesystemPath": { "const": false },
        "resolverCommand": { "const": "workspai project workspace status --json" },
        "portableUriScheme": { "const": "workspace:" },
        "resolvedPathPolicy": { "const": "runtime-private-never-persist" }
      }
    },
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["artifact", "schemaVersion", "hostStatus", "entryFiles"],
      "properties": {
        "artifact": { "const": ".workspai/agent-entry.v1.json" },
        "schemaVersion": { "const": "workspai.agent-entry.v1" },
        "hostStatus": { "$ref": "#/$defs/status" },
        "entryFiles": {
          "type": "array",
          "minItems": 1,
          "maxItems": 16,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/portablePath" }
        }
      }
    },
    "canonicalEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "projectContext",
        "workspaceIndex",
        "workspaceContext",
        "modelFreshness",
        "graphFreshness",
        "graphMatchesModel",
        "liveInputsValidated",
        "blockerCount"
      ],
      "properties": {
        "projectContext": { "const": ".workspai/reports/project-context-agent.json" },
        "projectKnowledgeGraph": {
          "const": ".workspai/reports/project-knowledge-graph-reference.json"
        },
        "workspaceIndex": { "const": "workspace:.workspai/reports/INDEX.json" },
        "workspaceContext": {
          "const": "workspace:.workspai/reports/workspace-context-agent.json"
        },
        "workspaceModel": { "const": "workspace:.workspai/reports/workspace-model.json" },
        "knowledgeGraph": {
          "const": "workspace:.workspai/reports/workspace-knowledge-graph.json"
        },
        "workspaceSkillsIndex": {
          "const": "workspace:.workspai/reports/workspace-skills-index.json"
        },
        "boundedGraphSearch": {
          "const": "command:workspai workspace graph search <task-query> --scope project:<project> --limit 12 --json"
        },
        "modelFreshness": { "enum": ["fresh", "stale", "unknown", "missing"] },
        "graphFreshness": { "enum": ["fresh", "stale", "unknown", "missing"] },
        "graphMatchesModel": { "type": "boolean" },
        "liveInputsValidated": { "type": "boolean" },
        "blockerCount": { "type": "integer", "minimum": 0 }
      },
      "anyOf": [
        {
          "properties": {
            "workspaceModel": {
              "const": "workspace:.workspai/reports/workspace-model.json"
            },
            "knowledgeGraph": {
              "const": "workspace:.workspai/reports/workspace-knowledge-graph.json"
            }
          },
          "required": ["workspaceModel", "knowledgeGraph"]
        },
        {
          "properties": {
            "workspaceSkillsIndex": {
              "const": "workspace:.workspai/reports/workspace-skills-index.json"
            },
            "boundedGraphSearch": {
              "const": "command:workspai workspace graph search <task-query> --scope project:<project> --limit 12 --json"
            }
          },
          "required": ["workspaceSkillsIndex", "boundedGraphSearch"]
        }
      ]
    },
    "activeGoal": {
      "type": "object",
      "additionalProperties": false,
      "required": ["present", "appliesToProject", "status"],
      "properties": {
        "present": { "type": "boolean" },
        "appliesToProject": { "type": "boolean" },
        "status": { "enum": ["none", "ready", "stale", "invalid"] },
        "id": { "type": "string", "minLength": 1 },
        "objective": { "type": "string", "minLength": 1 },
        "lifecycle": { "type": "string", "minLength": 1 },
        "goalPack": { "$ref": "#/$defs/workspaceArtifact" },
        "agentHandoff": { "$ref": "#/$defs/workspaceArtifact" }
      },
      "allOf": [
        {
          "if": { "properties": { "status": { "const": "none" } } },
          "then": { "properties": { "present": { "const": false } } }
        },
        {
          "if": {
            "properties": { "status": { "enum": ["ready", "stale", "invalid"] } }
          },
          "then": { "properties": { "present": { "const": true } } }
        }
      ]
    },
    "requiredReadOrder": {
      "type": "array",
      "minItems": 6,
      "maxItems": 16,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "claims": {
      "type": "object",
      "additionalProperties": false,
      "required": ["architecture", "sourceInspection", "sourceMutation", "verification"],
      "properties": {
        "architecture": { "enum": ["allowed-with-citations", "prohibited"] },
        "sourceInspection": { "const": "bounded-and-targeted" },
        "sourceMutation": { "const": "governed-cli-transaction-only" },
        "verification": { "const": "cli-evidence-only" }
      }
    },
    "checks": {
      "type": "array",
      "minItems": 6,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "status", "message"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "status": { "enum": ["passed", "warning", "failed"] },
          "message": { "type": "string", "minLength": 1 },
          "artifact": { "$ref": "#/$defs/portablePath" }
        }
      }
    },
    "nextActions": {
      "type": "array",
      "minItems": 1,
      "maxItems": 8,
      "items": { "type": "string", "minLength": 1 }
    },
    "integrity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "algorithm",
        "manifestHash",
        "projectContextHash",
        "payloadHash",
        "portable",
        "absolutePathsEmitted"
      ],
      "properties": {
        "algorithm": { "const": "sha256" },
        "manifestHash": { "$ref": "#/$defs/hash" },
        "projectContextHash": { "$ref": "#/$defs/hash" },
        "payloadHash": { "$ref": "#/$defs/hash" },
        "portable": { "const": true },
        "absolutePathsEmitted": { "const": false }
      }
    }
  },
  "$defs": {
    "hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "status": { "enum": ["ready", "degraded", "blocked"] },
    "portablePath": {
      "type": "string",
      "minLength": 1,
      "not": { "pattern": "^(?:/|[A-Za-z]:[\\\\/])" }
    },
    "workspaceArtifact": {
      "type": "string",
      "pattern": "^workspace:\\.workspai/"
    }
  }
}
