{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://codepremise.dev/kit/codepremise-node.schema.json",
  "title": "codepremise node",
  "description": "One business-logic claim in a repo's .codepremise/nodes/ folder. Every relation between claims is a typed entry in `links`. See SPEC.md.",
  "type": "object",
  "required": ["id", "type", "title", "what"],
  "additionalProperties": false,
  "properties": {
    "$schema": { "type": "string" },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*$",
      "description": "Kebab-case slug; must equal the filename without .json"
    },
    "type": { "enum": ["rule", "sequence", "corner-case"] },
    "title": { "type": "string", "minLength": 1, "description": "One-line behavior statement" },
    "what": { "type": "string", "minLength": 1, "description": "Plain-language description of the behavior" },
    "why": { "type": "string", "description": "The reason it exists: bug #, audit, decision. The part that cannot be reconstructed later." },
    "code": {
      "type": "array",
      "items": { "$ref": "#/$defs/codeRef" }
    },
    "tests": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["file", "name"],
        "additionalProperties": false,
        "properties": {
          "file": { "type": "string", "minLength": 1 },
          "name": { "type": "string", "minLength": 1 }
        }
      }
    },
    "links": {
      "type": "array",
      "description": "All edges of the claim graph. Open type vocabulary — consumers MUST treat unknown types as 'related'. Defined: 'refines' (target is this claim's parent; at most one per node, no cycles), 'step' (sequences only; array order of step links IS the step order), 'depends-on' (this claim's correctness rests on the target; changes to the target flag this claim for revisiting, transitively), 'related' (generic cross-reference).",
      "items": {
        "type": "object",
        "required": ["type", "node"],
        "additionalProperties": false,
        "properties": {
          "type": { "type": "string", "minLength": 1 },
          "node": { "type": "string", "minLength": 1 },
          "note": { "type": "string" }
        }
      }
    }
  },
  "$defs": {
    "codeRef": {
      "type": "object",
      "required": ["file", "start_line", "end_line", "hash"],
      "additionalProperties": false,
      "properties": {
        "file": { "type": "string", "minLength": 1, "description": "Repo-relative path" },
        "start_line": { "type": "integer", "minimum": 1 },
        "end_line": { "type": "integer", "minimum": 1 },
        "hash": {
          "type": "string",
          "pattern": "^[0-9a-f]{12}$",
          "description": "First 12 hex chars of SHA-256 of the exact text of the pointed lines (1-indexed inclusive, joined with \\n)"
        }
      }
    }
  }
}
