{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://itlackey.github.io/akm/schemas/akm-task.json",
  "title": "AKM Task source",
  "description": "A task file: version 4 (`version: 4`) or the experimental version 5 (`version: 5-beta.1`, read by src/tasks/v5/source.ts). A string `version` selects the version 5 shape; anything else is checked as version 4.",
  "x-akm-runtimeConstraints": {
    "authoritativeParser": "src/tasks/source/task-source-v4.ts",
    "maxSourceUtf8Bytes": 1048576,
    "maxStringUtf8Bytes": 262144,
    "maxJsonDepth": 64,
    "maxJsonNodes": 10000,
    "canonicalRefsRequireNfc": true,
    "authoritativeParserV5": "src/tasks/v5/source.ts"
  },
  "type": "object",
  "required": ["version"],
  "if": { "required": ["version"], "properties": { "version": { "type": "string" } } },
  "then": { "$ref": "#/definitions/taskSourceV5" },
  "else": { "$ref": "#/definitions/taskSourceV4" },
  "definitions": {
    "steps": {
      "description": "Experimental. 1 to 32 steps; step names are unique.",
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name"],
        "properties": {
          "name": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$" },
          "run": { "$ref": "#/definitions/nonemptyLiteral" },
          "prompt": { "$ref": "#/definitions/nonemptyLiteral" },
          "task": { "type": "string", "pattern": "^(?:[^\\s:.#/]+//)?tasks/[^\\s#\\\\]+$" },
          "env": {
            "type": "object",
            "maxProperties": 256,
            "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" }
          },
          "timeout": {
            "oneOf": [
              { "type": "integer", "minimum": 0 },
              { "type": "string", "pattern": "^\\d+[mMhd]$" },
              { "type": "null" }
            ]
          },
          "retries": { "type": "integer", "minimum": 0, "maximum": 5 },
          "harness": { "$ref": "#/definitions/nullableSelector" },
          "connection": { "$ref": "#/definitions/nullableSelector" },
          "model": { "$ref": "#/definitions/nullableSelector" },
          "expect": {
            "type": "array",
            "minItems": 1,
            "maxItems": 32,
            "uniqueItems": true,
            "items": { "type": "string", "minLength": 1 }
          }
        },
        "oneOf": [
          {
            "required": ["run"],
            "not": {
              "anyOf": [
                { "required": ["prompt"] },
                { "required": ["task"] },
                { "required": ["harness"] },
                { "required": ["connection"] },
                { "required": ["model"] },
                { "required": ["expect"] }
              ]
            }
          },
          { "required": ["prompt"], "not": { "anyOf": [{ "required": ["run"] }, { "required": ["task"] }] } },
          {
            "required": ["task"],
            "not": {
              "anyOf": [
                { "required": ["run"] },
                { "required": ["prompt"] },
                { "required": ["harness"] },
                { "required": ["connection"] },
                { "required": ["model"] },
                { "required": ["expect"] }
              ]
            }
          }
        ]
      }
    },
    "nonemptyLiteral": {
      "type": "string",
      "minLength": 1,
      "maxLength": 262144,
      "pattern": "^(?![\\s\\S]*\\$\\{\\{)[\\s\\S]*\\S[\\s\\S]*$"
    },
    "nullableSelector": {
      "oneOf": [
        { "type": "string", "minLength": 1, "maxLength": 262144, "pattern": ".*\\S.*" },
        { "type": "null" }
      ]
    },
    "akmExecutableRef": {
      "type": "string",
      "maxLength": 262144,
      "pattern": "^(?:[^\\s:.#/]+//)?(?:commands|workflows|scripts)/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
    },
    "akmCommandRef": {
      "description": "The commands/-only subset of akmExecutableRef — the executable-ref kind whose runtime actually consumes output: (the other consumer, uses: akm/command, is a const, not a ref). Same grammar, with the kind alternation narrowed to commands.",
      "type": "string",
      "maxLength": 262144,
      "pattern": "^(?:[^\\s:.#/]+//)?commands/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
    },
    "taskSourceV4ScheduleEntry": {
      "description": "One schedule: list entry. Activation is host-local scheduler configuration, never task source; inputs are validated against inputs: at parse time and delivered to the scheduled run's own invocation.",
      "type": "object",
      "required": ["cron"],
      "additionalProperties": false,
      "properties": {
        "cron": { "$ref": "#/definitions/nonemptyLiteral" },
        "inputs": { "$ref": "#/definitions/taskSourceV4ScheduleInputs" }
      }
    },
    "taskSourceV4ScheduleInputs": {
      "description": "schedule[i].inputs literals: keys are closed to the input-name pattern (the same pattern inputs: declarations use), not the free-form jsonObject shape — the runtime parser additionally rejects any key not present in the document's own inputs: declarations, which static JSON Schema cannot cross-reference here.",
      "type": "object",
      "maxProperties": 128,
      "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
      "additionalProperties": { "$ref": "#/definitions/jsonValue" }
    },
    "taskInputName": {
      "description": "One `inputs:` declaration key. Matches the identifier pattern AND excludes every name `akm task run` reserves for its own flags (src/tasks/task-run-reserved-flags.ts's TASK_RUN_RESERVED_FLAG_NAMES — the union of TASK_RUN_VALUE_FLAGS and TASK_RUN_BOOLEAN_FLAGS) — declaring an input under one of these names is rejected at parse time (TASK_SOURCE_INVALID, parseInputDeclarations) because the CLI would always treat the flag as its own, never as this input's. `no-quiet`/`no-verbose` are citty's negations of the `quiet`/`verbose` booleans and are listed for completeness even though the identifier pattern already excludes any hyphenated name.",
      "type": "string",
      "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
      "not": {
        "enum": [
          "bundle",
          "format",
          "detail",
          "shape",
          "output",
          "scheduled",
          "quiet",
          "verbose",
          "help",
          "no-quiet",
          "no-verbose"
        ]
      }
    },
    "inputDeclaration": {
      "description": "One inputs: declaration: a bounded JSON Schema. At the declaration ROOT, required is task source v4's own boolean flag, not JSON Schema's required array; default must itself satisfy the remaining schema; default + required:true together is invalid (D2-N3). Nested schemas (properties/items/allOf/anyOf/oneOf/not) keep ordinary JSON-Schema meaning via outputSchemaDefinition. Closed to exactly this key set — an unlisted keyword (e.g. pattern) is rejected here even though the runtime subset accepts it inside output:, because a task input declaration is intentionally narrower.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "oneOf": [
            { "$ref": "#/definitions/outputSchemaTypeName" },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 1024,
              "items": { "$ref": "#/definitions/outputSchemaTypeName" }
            }
          ]
        },
        "enum": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1024,
          "items": {
            "oneOf": [
              { "type": "string", "maxLength": 262144 },
              { "type": "number" },
              { "type": "boolean" },
              { "type": "null" }
            ]
          }
        },
        "properties": {
          "type": "object",
          "maxProperties": 256,
          "propertyNames": { "maxLength": 262144 },
          "additionalProperties": { "$ref": "#/definitions/outputSchemaDefinition" }
        },
        "required": {
          "description": "Declaration-ROOT required is task source v4's own boolean flag, not a JSON-Schema required array (D2-N3).",
          "type": "boolean"
        },
        "items": { "$ref": "#/definitions/outputSchemaDefinition" },
        "additionalProperties": { "type": "boolean" },
        "minItems": { "type": "integer", "minimum": 0 },
        "maxItems": { "type": "integer", "minimum": 0 },
        "minLength": { "type": "integer", "minimum": 0 },
        "maxLength": { "type": "integer", "minimum": 0 },
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "allOf": { "$ref": "#/definitions/outputSchemaArray" },
        "anyOf": { "$ref": "#/definitions/outputSchemaArray" },
        "oneOf": { "$ref": "#/definitions/outputSchemaArray" },
        "not": { "$ref": "#/definitions/outputSchemaDefinition" },
        "title": { "type": "string", "maxLength": 262144 },
        "description": { "type": "string", "maxLength": 262144 },
        "default": { "$ref": "#/definitions/jsonValue" }
      }
    },
    "outputSchemaDefinition": {
      "type": "object",
      "maxProperties": 256,
      "properties": {
        "type": {
          "oneOf": [
            { "$ref": "#/definitions/outputSchemaTypeName" },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 1024,
              "items": { "$ref": "#/definitions/outputSchemaTypeName" }
            }
          ]
        },
        "enum": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1024,
          "items": {
            "oneOf": [
              { "type": "string", "maxLength": 262144 },
              { "type": "number" },
              { "type": "boolean" },
              { "type": "null" }
            ]
          }
        },
        "properties": {
          "type": "object",
          "maxProperties": 256,
          "propertyNames": { "maxLength": 262144 },
          "additionalProperties": { "$ref": "#/definitions/outputSchemaDefinition" }
        },
        "required": { "type": "array", "maxItems": 1024, "items": { "type": "string", "maxLength": 262144 } },
        "items": { "$ref": "#/definitions/outputSchemaDefinition" },
        "additionalProperties": { "type": "boolean" },
        "minItems": { "type": "integer", "minimum": 0 },
        "maxItems": { "type": "integer", "minimum": 0 },
        "minLength": { "type": "integer", "minimum": 0 },
        "maxLength": { "type": "integer", "minimum": 0 },
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "allOf": { "$ref": "#/definitions/outputSchemaArray" },
        "anyOf": { "$ref": "#/definitions/outputSchemaArray" },
        "oneOf": { "$ref": "#/definitions/outputSchemaArray" },
        "not": { "$ref": "#/definitions/outputSchemaDefinition" },
        "$ref": false,
        "$defs": false,
        "definitions": false,
        "$anchor": false,
        "$dynamicRef": false,
        "$dynamicAnchor": false,
        "if": false,
        "then": false,
        "else": false,
        "const": false,
        "pattern": false,
        "format": false,
        "patternProperties": false,
        "propertyNames": false,
        "additionalItems": false,
        "prefixItems": false,
        "contains": false,
        "minContains": false,
        "maxContains": false,
        "uniqueItems": false,
        "multipleOf": false,
        "exclusiveMinimum": false,
        "exclusiveMaximum": false,
        "minProperties": false,
        "maxProperties": false,
        "dependencies": false,
        "dependentRequired": false,
        "dependentSchemas": false,
        "unevaluatedItems": false,
        "unevaluatedProperties": false,
        "contentEncoding": false,
        "contentMediaType": false,
        "contentSchema": false
      },
      "additionalProperties": { "$ref": "#/definitions/jsonValue" }
    },
    "outputSchemaArray": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1024,
      "items": { "$ref": "#/definitions/outputSchemaDefinition" }
    },
    "outputSchemaTypeName": { "enum": ["string", "number", "integer", "boolean", "object", "array", "null"] },
    "builtinCommandWith": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ref": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "content": { "type": "string", "maxLength": 262144 },
        "arguments": { "type": "string", "maxLength": 262144 }
      },
      "oneOf": [
        { "required": ["ref"], "not": { "required": ["content"] } },
        { "required": ["content"], "not": { "required": ["ref"] } }
      ]
    },
    "jsonValue": {
      "oneOf": [
        { "type": "string", "maxLength": 262144 },
        { "type": "number" },
        { "type": "boolean" },
        { "type": "null" },
        { "$ref": "#/definitions/jsonArray" },
        { "$ref": "#/definitions/jsonObject" }
      ]
    },
    "jsonArray": { "type": "array", "maxItems": 1024, "items": { "$ref": "#/definitions/jsonValue" } },
    "jsonObject": {
      "type": "object",
      "maxProperties": 256,
      "propertyNames": { "maxLength": 262144 },
      "additionalProperties": { "$ref": "#/definitions/jsonValue" }
    },
    "taskSourceV4": {
      "type": "object",
      "required": ["version"],
      "additionalProperties": false,
      "properties": {
        "version": { "const": 4 },
        "name": { "type": "string", "maxLength": 262144 },
        "description": { "type": "string", "maxLength": 262144 },
        "when_to_use": { "type": "string", "maxLength": 262144 },
        "tags": {
          "type": "array",
          "maxItems": 1024,
          "items": { "type": "string", "minLength": 1, "maxLength": 262144 }
        },
        "inputs": {
          "type": "object",
          "propertyNames": { "$ref": "#/definitions/taskInputName" },
          "additionalProperties": { "$ref": "#/definitions/inputDeclaration" }
        },
        "output": { "$ref": "#/definitions/outputSchemaDefinition" },
        "uses": { "oneOf": [{ "const": "akm/command" }, { "$ref": "#/definitions/akmExecutableRef" }] },
        "run": { "$ref": "#/definitions/nonemptyLiteral" },
        "steps": { "$ref": "#/definitions/steps" },
        "with": { "$ref": "#/definitions/builtinCommandWith" },
        "env": {
          "type": "object",
          "maxProperties": 256,
          "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
          "additionalProperties": {
            "oneOf": [{ "type": "string", "maxLength": 262144 }, { "type": "number" }, { "type": "boolean" }]
          }
        },
        "shell": { "enum": ["bash", "sh", "zsh", "pwsh", "powershell", "cmd"] },
        "working-directory": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "schedule": {
          "oneOf": [
            { "$ref": "#/definitions/nonemptyLiteral" },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 64,
              "items": { "$ref": "#/definitions/taskSourceV4ScheduleEntry" }
            }
          ]
        },
        "agent": { "$ref": "#/definitions/nullableSelector" },
        "connection": { "$ref": "#/definitions/nullableSelector" },
        "harness": { "$ref": "#/definitions/nullableSelector" },
        "engine": { "$ref": "#/definitions/nullableSelector" },
        "model": { "$ref": "#/definitions/nullableSelector" },
        "inference": { "oneOf": [{ "$ref": "#/definitions/jsonObject" }, { "type": "null" }] },
        "tools": {
          "oneOf": [
            { "type": "string", "maxLength": 262144 },
            { "type": "array", "maxItems": 1024, "items": { "type": "string", "maxLength": 262144 } },
            { "$ref": "#/definitions/jsonObject" },
            { "type": "null" }
          ]
        },
        "timeout": {
          "oneOf": [
            { "type": "integer", "minimum": 0, "maximum": 2147483647 },
            { "type": "string", "pattern": "^\\d+[mMhHdD]$" },
            { "type": "null" }
          ]
        },
        "redact": {
          "type": "array",
          "maxItems": 32,
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" }
        },
        "maxSteps": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
        "maxRetries": { "type": "integer", "minimum": 0 }
      },
      "oneOf": [
        {
          "description": "AKM's built-in anonymous/stored command action.",
          "required": ["uses", "with"],
          "properties": {
            "uses": { "const": "akm/command" },
            "with": { "$ref": "#/definitions/builtinCommandWith" }
          },
          "not": {
            "anyOf": [
              { "required": ["run"] },
              { "required": ["steps"] },
              { "required": ["shell"] },
              { "required": ["working-directory"] }
            ]
          }
        },
        {
          "description": "A canonical AKM executable ref (commands/, scripts/, or workflows/). No with: here — declare typed parameters with inputs: instead. output: is legal only on the commands/ arm: a scripts/ or workflows/ execution consumes no output schema, so an authored one would be a silently unenforced contract (src/tasks/source/task-source-v4.ts's targetConsumesOutputSchema).",
          "required": ["uses"],
          "properties": { "uses": { "$ref": "#/definitions/akmExecutableRef" } },
          "not": {
            "anyOf": [
              { "required": ["run"] },
              { "required": ["steps"] },
              { "required": ["with"] },
              { "required": ["shell"] },
              { "required": ["working-directory"] }
            ]
          },
          "if": { "required": ["uses"], "properties": { "uses": { "$ref": "#/definitions/akmCommandRef" } } },
          "else": { "not": { "required": ["output"] } }
        },
        {
          "description": "One exact host-shell string. No output: here — a run: execution decides status from its exit code alone and never enforces an output schema.",
          "required": ["run"],
          "not": {
            "anyOf": [
              { "required": ["uses"] },
              { "required": ["steps"] },
              { "required": ["with"] },
              { "required": ["output"] }
            ]
          }
        },
        {
          "description": "Experimental: ordered steps. Each step runs one shell line, one agent prompt or another task; a failed step stops the run. Not legal next to uses, run, with, output, maxSteps or maxRetries.",
          "required": ["steps"],
          "not": {
            "anyOf": [
              { "required": ["uses"] },
              { "required": ["run"] },
              { "required": ["with"] },
              { "required": ["output"] },
              { "required": ["maxSteps"] },
              { "required": ["maxRetries"] }
            ]
          }
        }
      ],
      "description": "Task source v4: typed inputs:, a single bounded output: schema, and OPTIONAL scheduling — a document with no schedule: is valid, runnable manually, composable, and is skipped (not rejected) by `akm task sync`. The akm: options bag and the on: trigger block from task v3 are gone (their members are top-level); there is no github-action uses: target; with: is legal only alongside uses: akm/command (use inputs: everywhere else for typed parameters), and output: is legal only on a command target (uses: commands/<ref> or uses: akm/command) — the only kinds whose runtime enforces it. task-v2 and task-v3 sources are converted to this schema by `akm migrate apply`."
    },
    "taskSourceV5": {
      "description": "Task source version 5 (experimental). Either one command (run:, exec: or prompt: at the top, no steps:) or an ordered steps: list. The options (env, secret, inherit, cwd, timeout, max-retries, harness, connection, model) at the top of a task are the default for every step. What needs other files (that a ref exists, that a secret is set, that an input is declared) is checked by `akm doctor explain` and `akm run`, not here.",
      "type": "object",
      "required": ["version"],
      "additionalProperties": false,
      "properties": {
        "version": { "const": "5-beta.1" },
        "name": { "type": "string", "maxLength": 262144 },
        "description": { "type": "string", "maxLength": 262144 },
        "when_to_use": { "type": "string", "maxLength": 262144 },
        "tags": {
          "type": "array",
          "maxItems": 1024,
          "items": { "type": "string", "minLength": 1, "maxLength": 262144 }
        },
        "inputs": {
          "type": "object",
          "propertyNames": { "$ref": "#/definitions/taskV5InputName" },
          "additionalProperties": { "$ref": "#/definitions/inputDeclaration" }
        },
        "lock": { "type": "boolean" },
        "schedule": {
          "oneOf": [
            { "$ref": "#/definitions/nonemptyLiteral" },
            {
              "type": "array",
              "minItems": 1,
              "maxItems": 64,
              "items": { "$ref": "#/definitions/taskV5ScheduleEntry" }
            }
          ]
        },
        "steps": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/taskV5Step" } },
        "env": { "$ref": "#/definitions/taskV5Env" },
        "secret": { "$ref": "#/definitions/taskV5Secret" },
        "inherit": { "type": "array", "items": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" } },
        "cwd": { "type": "string", "maxLength": 262144 },
        "timeout": { "$ref": "#/definitions/taskV5Timeout" },
        "max-retries": { "type": "integer", "minimum": 0 },
        "harness": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "connection": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "model": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "run": { "$ref": "#/definitions/taskV5Ref" },
        "exec": { "$ref": "#/definitions/nonemptyLiteral" },
        "prompt": { "type": "string", "maxLength": 262144 },
        "args": {
          "type": "array",
          "maxItems": 1024,
          "items": { "type": ["string", "number", "boolean"], "maxLength": 262144 }
        },
        "arguments": { "type": "string", "maxLength": 262144 },
        "expect": { "type": "array", "items": { "type": "string", "minLength": 1 } }
      },
      "if": { "required": ["steps"] },
      "then": {
        "not": {
          "anyOf": [
            { "required": ["run"] },
            { "required": ["exec"] },
            { "required": ["prompt"] },
            { "required": ["args"] },
            { "required": ["arguments"] },
            { "required": ["expect"] }
          ]
        }
      },
      "else": { "$ref": "#/definitions/taskV5Command" }
    },
    "taskV5Step": {
      "description": "One step: exactly one command. `name` is needed, unique among the steps and not the name of an input (the reader checks both).",
      "type": "object",
      "required": ["name"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "pattern": "^[A-Za-z0-9_-]+$" },
        "env": { "$ref": "#/definitions/taskV5Env" },
        "secret": { "$ref": "#/definitions/taskV5Secret" },
        "inherit": { "type": "array", "items": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" } },
        "cwd": { "type": "string", "maxLength": 262144 },
        "timeout": { "$ref": "#/definitions/taskV5Timeout" },
        "max-retries": { "type": "integer", "minimum": 0 },
        "harness": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "connection": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "model": { "type": "string", "minLength": 1, "maxLength": 262144 },
        "run": { "$ref": "#/definitions/taskV5Ref" },
        "exec": { "$ref": "#/definitions/nonemptyLiteral" },
        "prompt": { "type": "string", "maxLength": 262144 },
        "args": {
          "type": "array",
          "maxItems": 1024,
          "items": { "type": ["string", "number", "boolean"], "maxLength": 262144 }
        },
        "arguments": { "type": "string", "maxLength": 262144 },
        "expect": { "type": "array", "items": { "type": "string", "minLength": 1 } }
      },
      "allOf": [{ "$ref": "#/definitions/taskV5Command" }]
    },
    "taskV5Command": {
      "description": "Exactly one of exec:, prompt:, or run: naming an agent (which takes prompt:), a prompt asset under commands/ (arguments:), a script (args:) or a task (args:, as --<name> <value> pairs). expect: checks an agent's reply, so it is not for exec:, a script or a task.",
      "oneOf": [
        {
          "required": ["exec"],
          "not": {
            "anyOf": [
              { "required": ["run"] },
              { "required": ["prompt"] },
              { "required": ["args"] },
              { "required": ["arguments"] },
              { "required": ["expect"] }
            ]
          }
        },
        {
          "required": ["prompt"],
          "not": {
            "anyOf": [
              { "required": ["run"] },
              { "required": ["exec"] },
              { "required": ["args"] },
              { "required": ["arguments"] }
            ]
          }
        },
        {
          "required": ["run", "prompt"],
          "properties": {
            "run": {
              "type": "string",
              "pattern": "^(?:[^\\s:.#/]+//)?agents/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
            }
          },
          "not": {
            "anyOf": [{ "required": ["exec"] }, { "required": ["args"] }, { "required": ["arguments"] }]
          }
        },
        {
          "required": ["run"],
          "properties": {
            "run": {
              "type": "string",
              "pattern": "^(?:[^\\s:.#/]+//)?commands/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
            }
          },
          "not": { "anyOf": [{ "required": ["exec"] }, { "required": ["prompt"] }, { "required": ["args"] }] }
        },
        {
          "required": ["run"],
          "properties": {
            "run": {
              "type": "string",
              "pattern": "^(?:[^\\s:.#/]+//)?scripts/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
            }
          },
          "not": {
            "anyOf": [
              { "required": ["exec"] },
              { "required": ["prompt"] },
              { "required": ["arguments"] },
              { "required": ["expect"] }
            ]
          }
        },
        {
          "required": ["run"],
          "properties": {
            "run": {
              "type": "string",
              "pattern": "^(?:[^\\s:.#/]+//)?tasks/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
            }
          },
          "not": {
            "anyOf": [
              { "required": ["exec"] },
              { "required": ["prompt"] },
              { "required": ["arguments"] },
              { "required": ["expect"] }
            ]
          }
        }
      ]
    },
    "taskV5Ref": {
      "description": "A ref to a task, prompt asset (commands/), script or agent.",
      "type": "string",
      "maxLength": 262144,
      "pattern": "^(?:[^\\s:.#/]+//)?(?:tasks|commands|scripts|agents)/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+(?:/(?!\\.{1,2}(?:/|$))[^\\s#\\\\/\\u0000]+)*$"
    },
    "taskV5Env": {
      "description": "env: entries: an env asset's ref, as --env takes it, or NAME: value pairs. A secret ref does not go here; it goes under secret:.",
      "type": "array",
      "items": {
        "oneOf": [
          { "type": "string", "maxLength": 262144 },
          {
            "type": "object",
            "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
            "additionalProperties": { "type": ["string", "number", "boolean"] }
          }
        ]
      }
    },
    "taskV5Secret": {
      "description": "secret: entries, <secret ref>:<VAR>, as --secret takes them.",
      "type": "array",
      "items": { "type": "string", "pattern": "^.+:[A-Za-z_][A-Za-z0-9_]*$" }
    },
    "taskV5Timeout": {
      "description": "A positive duration: bare N is milliseconds, or N with ms, s, m, h or d.",
      "oneOf": [
        { "type": "integer", "minimum": 1 },
        { "type": "string", "pattern": "^\\s*0*[1-9][0-9]*(ms|s|m|h|d)?\\s*$" }
      ]
    },
    "taskV5InputName": {
      "description": "An inputs: key: an identifier that is neither a name akm run reserves for its own flags nor the name of a start flag (env, secret, cwd, timeout, resume, inherit).",
      "allOf": [
        { "$ref": "#/definitions/taskInputName" },
        { "not": { "enum": ["env", "secret", "cwd", "timeout", "resume", "inherit"] } }
      ]
    },
    "taskV5ScheduleEntry": {
      "description": "One schedule: entry. Its env: takes only env asset refs; secret: and timeout: are what --secret and --timeout are to a typed start.",
      "type": "object",
      "required": ["cron"],
      "additionalProperties": false,
      "properties": {
        "cron": { "$ref": "#/definitions/nonemptyLiteral" },
        "inputs": { "$ref": "#/definitions/taskSourceV4ScheduleInputs" },
        "env": { "type": "array", "items": { "type": "string", "maxLength": 262144 } },
        "secret": { "$ref": "#/definitions/taskV5Secret" },
        "timeout": { "$ref": "#/definitions/taskV5Timeout" }
      }
    }
  }
}
