{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/workspace-intelligence/goal-index.v1.json",
  "title": "Workspai Goal Index",
  "type": "object",
  "required": ["schemaVersion", "generatedAt", "activeGoalId", "goals"],
  "properties": {
    "schemaVersion": { "const": "workspai.goal-index.v1" },
    "generatedAt": { "type": "string", "format": "date-time" },
    "activeGoalId": { "type": ["string", "null"] },
    "goals": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "fingerprint",
          "objective",
          "category",
          "state",
          "lifecycle",
          "scope",
          "createdAt",
          "updatedAt",
          "goalPack",
          "agentHandoff"
        ],
        "properties": {
          "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{7,95}$" },
          "fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "objective": { "type": "string", "minLength": 1, "maxLength": 2000 },
          "category": {
            "enum": [
              "release-readiness",
              "dependency-security",
              "test-coverage",
              "defect-repair",
              "feature-change",
              "refactor",
              "performance",
              "documentation",
              "system-understanding"
            ]
          },
          "state": { "enum": ["ready-to-plan", "needs-confirmation", "needs-evidence", "blocked"] },
          "lifecycle": {
            "enum": ["planned", "active", "cancelled", "verification-ready", "verified", "failed"]
          },
          "scope": {
            "type": "object",
            "required": ["kind", "projects", "selectionSource"],
            "properties": {
              "kind": { "enum": ["workspace", "project", "project-set"] },
              "projects": {
                "type": "array",
                "minItems": 1,
                "items": { "type": "string", "minLength": 1 },
                "uniqueItems": true
              },
              "selectionSource": {
                "enum": [
                  "workspace",
                  "single-project-workspace",
                  "invocation-project",
                  "explicit",
                  "interactive"
                ]
              },
              "resolution": { "enum": ["selected", "selection-required"] }
            },
            "allOf": [
              {
                "if": { "properties": { "kind": { "const": "project" } } },
                "then": {
                  "properties": { "projects": { "type": "array", "maxItems": 1 } }
                }
              },
              {
                "if": { "properties": { "kind": { "const": "project-set" } } },
                "then": {
                  "properties": { "projects": { "type": "array", "minItems": 2 } }
                }
              },
              {
                "if": {
                  "properties": { "resolution": { "const": "selection-required" } },
                  "required": ["resolution"]
                },
                "then": {
                  "properties": {
                    "kind": { "const": "workspace" },
                    "selectionSource": { "const": "workspace" }
                  }
                }
              }
            ],
            "additionalProperties": false
          },
          "createdAt": { "type": "string", "format": "date-time" },
          "updatedAt": { "type": "string", "format": "date-time" },
          "goalPack": { "type": "string", "pattern": "^\\.workspai/goals/[^/]+/goal-pack\\.json$" },
          "agentHandoff": {
            "type": "string",
            "pattern": "^\\.workspai/goals/[^/]+/agent-handoff\\.json$"
          },
          "verifiedGoalId": { "type": "string", "minLength": 1 },
          "repairTransactionId": { "type": "string", "minLength": 1 },
          "repairTransactionIds": {
            "type": "array",
            "maxItems": 25,
            "uniqueItems": true,
            "items": { "type": "string", "minLength": 1 }
          },
          "changeTransactionId": {
            "type": "string",
            "pattern": "^change-[a-z0-9][a-z0-9-]{7,95}$"
          },
          "changeTransactionIds": {
            "type": "array",
            "maxItems": 25,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "pattern": "^change-[a-z0-9][a-z0-9-]{7,95}$"
            }
          },
          "verificationReceipt": {
            "type": "object",
            "required": [
              "verifiedGoalId",
              "attempt",
              "statusHash",
              "modelHash",
              "graphFingerprint",
              "graphFingerprintSemantics",
              "recordedAt"
            ],
            "properties": {
              "verifiedGoalId": { "type": "string", "minLength": 1 },
              "attempt": { "type": "integer", "minimum": 1 },
              "statusHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
              "modelHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
              "graphFingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
              "graphFingerprintSemantics": {
                "enum": ["workspace-knowledge-graph-inputs-v1", "canonical-json-v1"]
              },
              "recordedAt": { "type": "string", "format": "date-time" }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false
}
