{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://verifiableplanformat.org/schema/vpf-1.schema.json",
  "title": "Verifiable Plan Format, version 1",
  "description": "The shape of a plan. A plan that matches it may still have problems that only a checker finds; see section 6 of the specification.",
  "type": "object",
  "required": ["$schema", "wish", "steps"],
  "additionalProperties": false,
  "properties": {
    "$schema": { "const": "vpf/1" },
    "wish": { "type": "string", "description": "What the person wants, in their words." },
    "start": { "$ref": "#/$defs/start" },
    "limits": { "$ref": "#/$defs/limits" },
    "steps": { "type": "array", "items": { "$ref": "#/$defs/step" }, "description": "1 to 200 steps, done in the order written." }
  },
  "$defs": {
    "count": { "type": "integer", "minimum": 0 },
    "start": {
      "description": "When a run starts.",
      "oneOf": [
        {
          "type": "object",
          "required": ["on"],
          "additionalProperties": false,
          "properties": { "on": { "const": "asked" } }
        },
        {
          "type": "object",
          "required": ["on", "days", "time"],
          "additionalProperties": false,
          "properties": {
            "on": { "const": "schedule" },
            "days": { "type": "array", "items": { "enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] } },
            "time": { "type": "string", "description": "HH:MM, from 00:00 to 23:59." }
          }
        },
        {
          "type": "object",
          "required": ["on", "minutes"],
          "additionalProperties": false,
          "properties": { "on": { "const": "every" }, "minutes": { "$ref": "#/$defs/count" } }
        },
        {
          "type": "object",
          "required": ["on", "paths"],
          "additionalProperties": false,
          "properties": { "on": { "const": "files" }, "paths": { "type": "array", "items": { "type": "string" } } }
        },
        {
          "type": "object",
          "required": ["on"],
          "additionalProperties": false,
          "properties": { "on": { "const": "request" } }
        }
      ]
    },
    "limits": {
      "description": "How far one run may go.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "repeats": { "$ref": "#/$defs/count", "default": 3 },
        "minutes": { "$ref": "#/$defs/count", "default": 60 },
        "cost": { "type": "number" },
        "month": { "type": "number" }
      }
    },
    "step": {
      "type": "object",
      "required": ["id", "do", "by"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "do": { "type": "string" },
        "by": { "enum": ["agent", "algorithm", "person", "plan"] },
        "proof": {
          "oneOf": [
            { "$ref": "#/$defs/proof" },
            { "type": "array", "items": { "$ref": "#/$defs/proof" } }
          ]
        },
        "run": { "type": "string" },
        "on_fail": { "const": "agent" },
        "agent": { "type": "string" },
        "model": { "type": "string" },
        "tools": { "type": "array", "items": { "enum": ["read", "write", "commands", "internet", "screen"] } },
        "plan": { "type": "string" }
      }
    },
    "proof": {
      "type": "object",
      "required": ["by"],
      "additionalProperties": false,
      "properties": {
        "by": { "enum": ["algorithm", "agent", "person"] },
        "run": { "type": "string" },
        "needs": { "type": "array", "items": { "$ref": "#/$defs/need" } },
        "check": { "type": "string" },
        "agent": { "type": "string" },
        "model": { "type": "string" },
        "ask": { "type": "string" }
      }
    },
    "need": {
      "description": "One thing the work must leave in the folder.",
      "oneOf": [
        {
          "type": "object",
          "required": ["need", "path"],
          "additionalProperties": false,
          "properties": {
            "need": { "const": "files" },
            "path": { "type": "string" },
            "at_least": { "$ref": "#/$defs/count", "default": 1 }
          }
        },
        {
          "type": "object",
          "required": ["need", "path"],
          "additionalProperties": false,
          "properties": { "need": { "const": "folder" }, "path": { "type": "string" } }
        },
        {
          "type": "object",
          "required": ["need", "path", "files"],
          "additionalProperties": false,
          "properties": { "need": { "const": "names" }, "path": { "type": "string" }, "files": { "type": "string" } }
        },
        {
          "type": "object",
          "required": ["need", "path", "headings"],
          "additionalProperties": false,
          "properties": {
            "need": { "const": "headings" },
            "path": { "type": "string" },
            "headings": { "type": "array", "items": { "type": "string" } }
          }
        },
        {
          "type": "object",
          "required": ["need", "path"],
          "additionalProperties": false,
          "properties": {
            "need": { "const": "repository" },
            "path": { "type": "string" },
            "branch": { "type": "string" }
          }
        }
      ]
    }
  }
}
