{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/microsoft/hve-core/schemas/sssc-state.schema.json",
  "title": "SSSC Planner State Schema",
  "description": "Schema for SSSC Planner state.json files under .copilot-tracking/sssc-plans/{project-slug}/",
  "type": "object",
  "required": [
    "projectSlug",
    "ssscPlanFile",
    "currentPhase",
    "entryMode",
    "scopingComplete",
    "assessmentComplete",
    "standardsMapped",
    "gapAnalysisComplete",
    "backlogGenerated",
    "handoffGenerated",
    "context",
    "referencesProcessed",
    "nextActions",
    "userPreferences",
    "ssscEnabled",
    "signingRequested",
    "signingManifestPath",
    "disclaimerShownAt",
    "phaseGates"
  ],
  "properties": {
    "projectSlug": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
      "description": "Kebab-case project identifier used as the directory name"
    },
    "ssscPlanFile": {
      "type": "string",
      "description": "Relative path to the SSSC plan markdown file"
    },
    "currentPhase": {
      "type": "integer",
      "minimum": 1,
      "maximum": 6,
      "description": "Current assessment phase (1-6)"
    },
    "entryMode": {
      "type": "string",
      "enum": ["capture", "from-prd", "from-brd", "from-security-plan"],
      "description": "How the assessment was initiated"
    },
    "disclaimerShownAt": {
      "type": ["string", "null"],
      "format": "date-time",
      "description": "ISO 8601 timestamp when disclaimer was displayed, or null if not yet shown"
    },
    "scopingComplete": {
      "type": "boolean",
      "description": "Whether Phase 1 scoping is complete"
    },
    "assessmentComplete": {
      "type": "boolean",
      "description": "Whether Phase 2 supply chain assessment is complete"
    },
    "standardsMapped": {
      "type": "boolean",
      "description": "Whether Phase 3 standards mapping is complete"
    },
    "gapAnalysisComplete": {
      "type": "boolean",
      "description": "Whether Phase 4 gap analysis is complete"
    },
    "backlogGenerated": {
      "type": "boolean",
      "description": "Whether Phase 5 backlog generation is complete"
    },
    "handoffGenerated": {
      "type": "object",
      "required": ["ado", "github"],
      "properties": {
        "ado": {
          "type": "boolean",
          "description": "Whether ADO backlog handoff has been generated"
        },
        "github": {
          "type": "boolean",
          "description": "Whether GitHub Issues backlog handoff has been generated"
        }
      },
      "additionalProperties": false,
      "description": "Platform-specific handoff generation status"
    },
    "context": {
      "type": "object",
      "required": [
        "techStack",
        "packageManagers",
        "ciPlatform",
        "releaseStrategy",
        "complianceTargets"
      ],
      "properties": {
        "techStack": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Languages, runtimes, and frameworks in scope"
        },
        "packageManagers": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Package managers and dependency ecosystems in use"
        },
        "ciPlatform": {
          "type": "string",
          "description": "Primary CI/CD platform (e.g., github-actions, azure-pipelines)"
        },
        "releaseStrategy": {
          "type": "string",
          "description": "Release cadence and distribution strategy"
        },
        "complianceTargets": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Compliance frameworks or standards targeted (e.g., SLSA L3, OpenSSF Scorecard)"
        },
        "deploymentTargets": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Deployment surfaces (e.g., container registries, package indexes)"
        }
      },
      "additionalProperties": true,
      "description": "Project context discovered during scoping"
    },
    "referencesProcessed": {
      "type": "array",
      "items": { "$ref": "#/$defs/referenceEntry" },
      "description": "User-supplied reference content processed during the assessment"
    },
    "nextActions": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Pending actions for the current phase"
    },
    "userPreferences": { "$ref": "#/$defs/userPreferences" },
    "ssscEnabled": {
      "type": "boolean",
      "description": "Whether SSSC planning is enabled for this session"
    },
    "securityPlannerLink": {
      "type": ["string", "null"],
      "description": "Path to the source security plan when entryMode is from-security-plan"
    },
    "raiPlannerLink": {
      "type": ["string", "null"],
      "description": "Path to a related RAI plan when applicable"
    },
    "signingRequested": {
      "type": "boolean",
      "description": "Whether artifact signing was requested by the user"
    },
    "signingManifestPath": {
      "type": ["string", "null"],
      "description": "Path to the signing manifest file (sssc-manifest.json), or null if signing not requested"
    },
    "phaseGates": {
      "type": "object",
      "required": ["phase1", "phase2", "phase3", "phase4", "phase5", "phase6"],
      "properties": {
        "phase1": { "$ref": "#/$defs/hardGate" },
        "phase2": { "$ref": "#/$defs/summaryGate" },
        "phase3": { "$ref": "#/$defs/summaryGate" },
        "phase4": { "$ref": "#/$defs/hardGate" },
        "phase5": { "$ref": "#/$defs/summaryGate" },
        "phase6": { "$ref": "#/$defs/hardGate" }
      },
      "additionalProperties": false,
      "description": "Per-phase gate model: phases 1, 4, and 6 are hard gates requiring explicit user confirmation; phases 2, 3, and 5 are summary-and-advance gates"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "hardGate": {
      "type": "object",
      "required": ["gate", "confirmedAt"],
      "properties": {
        "gate": { "const": "hard" },
        "confirmedAt": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "ISO 8601 timestamp when the user confirmed the gate, or null before confirmation"
        }
      },
      "additionalProperties": false,
      "description": "Hard gate requiring explicit user confirmation before advancing"
    },
    "summaryGate": {
      "type": "object",
      "required": ["gate"],
      "properties": {
        "gate": { "const": "summary-and-advance" }
      },
      "additionalProperties": false,
      "description": "Summary-and-advance gate that presents a summary and continues unless the user objects"
    },
    "referenceEntry": {
      "type": "object",
      "required": ["filePath", "type", "sourceDescription", "processedInPhase", "status"],
      "properties": {
        "filePath": {
          "type": "string",
          "description": "Path to the processed reference file"
        },
        "type": {
          "type": "string",
          "enum": [
            "standard",
            "security-plan",
            "prd",
            "brd",
            "sbom",
            "scorecard-result",
            "output-format"
          ],
          "description": "Category of the reference content"
        },
        "sourceDescription": {
          "type": "string",
          "description": "Brief description of the reference source"
        },
        "processedInPhase": {
          "type": ["integer", "null"],
          "minimum": 1,
          "maximum": 6,
          "description": "Phase in which the reference was processed, or null if pending"
        },
        "status": {
          "type": "string",
          "enum": ["pending", "processed", "error"],
          "description": "Processing status of the reference"
        }
      },
      "additionalProperties": false
    },
    "userPreferences": {
      "type": "object",
      "required": [
        "autonomyTier",
        "outputDetailLevel",
        "targetSystem",
        "audienceProfile",
        "includeOptionalArtifacts"
      ],
      "properties": {
        "autonomyTier": {
          "type": "string",
          "enum": ["guided", "partial", "full"],
          "description": "How much autonomy the agent has in proceeding between phases"
        },
        "outputDetailLevel": {
          "type": "string",
          "enum": ["minimal", "standard", "detailed"],
          "description": "Level of detail in generated artifacts"
        },
        "targetSystem": {
          "type": "string",
          "enum": ["ado", "github", "both"],
          "description": "Target backlog system for handoff"
        },
        "audienceProfile": {
          "type": "string",
          "enum": ["technical", "executive", "mixed"],
          "description": "Primary audience for generated artifacts"
        },
        "includeOptionalArtifacts": {
          "type": "object",
          "required": ["sbom", "scorecardProjection", "artifactSigning"],
          "properties": {
            "sbom": {
              "type": "boolean",
              "description": "Whether to include SBOM generation guidance"
            },
            "scorecardProjection": {
              "type": "boolean",
              "description": "Whether to include OpenSSF Scorecard score projections"
            },
            "artifactSigning": {
              "type": "boolean",
              "description": "Whether to enable cosign artifact signing"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  }
}
