{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://seregonwar.github.io/FastCi/schema/fastci.schema.json",
  "title": "FastCi Pipeline Manifest (fastci.json)",
  "description": "Strict schema for FastCi v0.3.0 DAG pipeline manifests. Verified against src/pipeline/manifest.c and include/fastci/types.h.",
  "type": "object",
  "required": ["jobs"],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Optional JSON Schema reference for editor and AI tooling validation."
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable pipeline name displayed in logs, reports, and GitHub Step Summaries."
    },
    "version": {
      "type": "string",
      "description": "Pipeline schema/project version string (e.g. \"1\" or \"0.3.0\")."
    },
    "cache_dir": {
      "type": "string",
      "description": "Local Content-Addressable Storage (CAS) and statcache directory. Supports ${workspace}, ${os}, ${arch}, ${cpus}, ${env.NAME}."
    },
    "verify_inputs": {
      "type": "string",
      "enum": ["fast", "sample", "strict"],
      "default": "sample",
      "description": "Default Statcache v4 verification mode. 'fast' trusts metadata + USN; 'sample' adds 12 KiB CRC32C edge sampling; 'strict' hashes full inputs with BLAKE3-256."
    },
    "remote_cache": {
      "type": "string",
      "description": "Optional Remote CAS URL (http://, https://, or file://). Avoid putting credentials directly in the manifest; pass tokens via FASTCI_REMOTE_TOKEN."
    },
    "remote_read_only": {
      "type": "boolean",
      "default": false,
      "description": "When true, fetches from Remote CAS without uploading. Recommended for untrusted pull requests."
    },
    "workers": {
      "type": "integer",
      "minimum": 1,
      "maximum": 256,
      "description": "Default scheduler concurrency (CPU slots). Overridden by -j / --jobs."
    },
    "max_ram_mb": {
      "type": "integer",
      "minimum": 1,
      "description": "Total RAM budget in MiB for the memory-aware scheduler. Overridden by --ram."
    },
    "env": {
      "type": "object",
      "maxProperties": 128,
      "description": "Global environment variables inherited by all jobs and included in job cache keys (except internal FASTCI_* controls).",
      "additionalProperties": {
        "type": "string"
      }
    },
    "jobs": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1024,
      "description": "List of DAG job definitions. Matrix jobs expand into up to 256 combinations per entry (1024 total jobs max).",
      "items": {
        "$ref": "#/$defs/job"
      }
    }
  },
  "$defs": {
    "job": {
      "type": "object",
      "required": ["id"],
      "additionalProperties": false,
      "oneOf": [
        { "required": ["cmd"] },
        { "required": ["shell"] }
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Unique job identifier. Supports ${matrix.key} expansion when matrix is defined."
        },
        "name": {
          "type": "string",
          "description": "Optional display label for logs and summaries."
        },
        "cwd": {
          "type": "string",
          "description": "Working directory relative to workspace root (or absolute within workspace). Supports variable expansion."
        },
        "cmd": {
          "type": "array",
          "minItems": 1,
          "maxItems": 512,
          "items": { "type": "string" },
          "description": "PREFERRED. Direct argv array spawned without a shell (CreateProcessA on Windows, posix_spawn on Unix). Eliminates shell startup overhead and quoting bugs."
        },
        "shell": {
          "type": "string",
          "minLength": 1,
          "description": "Shell command string (mutually exclusive with cmd). Avoid when cmd can express the invocation directly, especially on Windows."
        },
        "toolchain_cmd": {
          "type": "array",
          "minItems": 1,
          "maxItems": 512,
          "items": { "type": "string" },
          "description": "Command whose stdout fingerprints the compiler/runtime version into the cache key (e.g. [\"rustc\", \"-vV\"] or [\"cc\", \"--version\"])."
        },
        "needs": {
          "type": "array",
          "maxItems": 64,
          "items": { "type": "string" },
          "description": "Upstream job IDs that must succeed before this job starts. Must form an acyclic DAG."
        },
        "inputs": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Relative file paths or globs hashed into the cache key. Supports *, ?, ** (zero or more path segments), and !pattern exclusions."
        },
        "critical_inputs": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Inputs that ALWAYS bypass statcache sampling and undergo full strict BLAKE3-256 verification (e.g. lockfiles, CMakeLists.txt, build scripts, linker scripts)."
        },
        "outputs": {
          "type": "array",
          "maxItems": 64,
          "items": { "type": "string" },
          "description": "Relative file or directory paths captured into CAS on success and restored via hardlink/copy on cache hit."
        },
        "scan_deps": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Entry-point source files or globs for the SIMD transitive dependency scanner (10 languages). Discovered dependencies are automatically hashed into the cache key."
        },
        "scan_c_deps": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Legacy alias for scan_deps."
        },
        "lang": {
          "type": "string",
          "enum": ["auto", "c", "asm", "rust", "go", "zig", "python", "js", "java", "csharp", "swift"],
          "default": "auto",
          "description": "Language hint for scan_deps. Defaults to auto-detection by file extension."
        },
        "include_dirs": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Additional search directories for scan_deps include/import resolution."
        },
        "search_dirs": {
          "type": "array",
          "maxItems": 128,
          "items": { "type": "string" },
          "description": "Alias for include_dirs."
        },
        "verify_inputs": {
          "type": "string",
          "enum": ["fast", "sample", "strict"],
          "description": "Per-job override of pipeline verify_inputs mode."
        },
        "env": {
          "type": "object",
          "maxProperties": 128,
          "description": "Job-specific environment variables merged on top of pipeline env.",
          "additionalProperties": { "type": "string" }
        },
        "cpu_slots": {
          "type": "integer",
          "minimum": 1,
          "maximum": 256,
          "default": 1,
          "description": "CPU worker slots reserved by this job while running."
        },
        "mem_mb": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1048576,
          "default": 256,
          "description": "Estimated peak RAM in MiB for the memory-aware scheduler (prevents OOM thrashing on heavy LTO/link/rustc steps)."
        },
        "ram_mb": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1048576,
          "description": "Alias for mem_mb."
        },
        "retries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10,
          "default": 0,
          "description": "Automatic retry count for flaky external/network steps."
        },
        "timeout_ms": {
          "type": "integer",
          "minimum": 0,
          "default": 0,
          "description": "Hard job timeout in milliseconds (0 = unlimited)."
        },
        "weight": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000,
          "default": 10,
          "description": "Estimated relative cost used to compute critical-path priority. Give long-pole jobs higher weights so they start first."
        },
        "cache": {
          "type": "boolean",
          "description": "Enable/disable CAS caching for this job. Defaults to true if inputs, critical_inputs, outputs, or scan_deps are specified."
        },
        "allow_failure": {
          "type": "boolean",
          "default": false,
          "description": "If true, failure is recorded without aborting the overall pipeline exit code."
        },
        "matrix": {
          "type": "object",
          "description": "Key-to-array map expanded into Cartesian product jobs (max 256 combinations). Reference values with ${matrix.key} in id, cmd, inputs, outputs, env, etc.",
          "additionalProperties": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string" }
          }
        }
      }
    }
  }
}
