{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://behavioralstate.io/v1/schemas/agents/commands.json",
  "title": "BEST Commands",
  "description": "Schema for the command ingestion and discovery capability (io.best.agents.commands).",
  "$defs": {
    "command": {
      "allOf": [
        { "$ref": "../cloudEvent.json#/$defs/cloudEvent" },
        { "required": ["dataschema"] }
      ],
      "description": "A command sent to a BEST-compliant service. CloudEvent 1.0 envelope — the type field must match a type in the command catalogue, and the data property is validated against the JSON Schema at the dataschema URI before the command is queued. dataschema is required for commands."
    },
    "commandCatalogueEntry": {
      "type": "object",
      "description": "An entry in the command catalogue — one available command type with its schema name, version, and dataschema URI.",
      "required": ["schema", "version", "dataschema"],
      "properties": {
        "schema": {
          "type": "string",
          "description": "Command schema name in kebab-case (e.g. propose-counter, submit-order). Used as the {schema} path segment in GET /commands/{schema}/{version}. Distinct from the CloudEvent 'type' field, which commandType states."
        },
        "version": {
          "type": "string",
          "description": "Schema version string (e.g. 1.0, 2.1). Used as the {version} path segment in GET /commands/{schema}/{version}. First-class field — callers do not need to parse the dataschema URI to determine the version."
        },
        "commandType": {
          "type": "string",
          "pattern": "^[A-Z][a-zA-Z0-9]*$",
          "description": "The exact CloudEvent 'type' to send for this command, in PascalCase (e.g. ProposeCounter). When absent, consumers derive it as the PascalCase form of 'schema'; servers SHOULD state it, because a derivation is a guess. Stamped both here and as a top-level member of the command's schema document, with the same value."
        },
        "dataschema": {
          "type": "string",
          "format": "uri",
          "description": "Resolvable URI to the JSON Schema for this command's data payload. Canonical value for the dataschema field of a CloudEvent command. Kept for CloudEvent compatibility."
        },
        "description": {
          "type": "string",
          "description": "Human-readable description of what this command does."
        },
        "workflows": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Ids of published workflows (io.best.agents.workflows) this command participates in — the protocol's single workflow-discoverability mechanism, stamped both here and as a top-level member of the command's schema document. Servers SHOULD populate it for every operation that appears in a recipe; consumers SHOULD read the recipe before composing a multi-step sequence themselves."
        },
        "impact": { "$ref": "#/$defs/impact" }
      },
      "additionalProperties": false
    },
    "impact": {
      "type": "object",
      "description": "High-impact annotation — declares that this command is high-impact in the sense of the Security Requirements (destructive, irreversible, financial, compliance-relevant, committing the person, or granting access to what is theirs) and that a consumer acting on behalf of a human must warn that human and obtain explicit confirmation before submitting it. Stamped both on the catalogue entry and as a top-level member of the command's schema document; both surfaces MUST carry the same value. Descriptive only: it never replaces the server-side controls the Security Requirements demand for high-impact commands.",
      "required": ["categories", "confirmation"],
      "properties": {
        "categories": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string" },
          "description": "What kind of impact the command has. Named values: 'financial' (moves money or puts capital at risk), 'destructive' (removes data or state), 'irreversible' (cannot be undone by a compensating command), 'compliance' (bypasses or alters a compliance control), 'commitment' (binds the person: opens an account, accepts terms, starts a subscription, creates personal data in their name), 'access' (grants a principal access to what belongs to the person: issues a credential, shares a resource, invites a member). The vocabulary is open — implementers MAY add their own values; consumers treat unknown values as high-impact."
        },
        "confirmation": {
          "type": "string",
          "enum": ["recommended", "required"],
          "description": "'required': a consumer acting on behalf of a human MUST NOT submit this command without explicit, per-submission confirmation from that human. 'recommended': the consumer SHOULD confirm but MAY proceed when the human has durably authorized this class of operation. Service-to-service automation with no human principal is governed by the server-side High-impact controls instead."
        },
        "warning": {
          "type": "string",
          "description": "Human-readable warning the consumer SHOULD surface to the human, substantially intact, before asking for confirmation (e.g. 'Places a real order on your broker account. Capital at risk.')."
        }
      },
      "additionalProperties": false
    },
    "commandCatalogue": {
      "type": "object",
      "description": "Response body for GET /commands. Lists all command types this service accepts, with their schema URIs. This is the discovery surface for callers (Process Managers, AI agents, UIs) to learn what they can send.",
      "required": ["commands"],
      "properties": {
        "commands": {
          "type": "array",
          "items": { "$ref": "#/$defs/commandCatalogueEntry" }
        }
      },
      "additionalProperties": false
    },
    "schemaEntry": {
      "type": "object",
      "description": "An entry describing one available command schema with its version. Returned in the command catalogue entry's dataschema URI path.",
      "required": ["schema", "version"],
      "properties": {
        "schema": {
          "type": "string",
          "description": "Schema name (e.g. ProposeCounter, SubmitOrder). Matches the command type name."
        },
        "version": {
          "type": "string",
          "description": "Schema version string (e.g. 1.0, 2.1). Used as the second path segment in GET /commands/{schema}/{version}."
        },
        "description": {
          "type": "string",
          "description": "Human-readable description of what this schema validates."
        }
      },
      "additionalProperties": false
    }
  }
}
