{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.dharma-ai.io/task-action/v1",
  "title": "Canonical Task-Level Action",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "organizationId", "actionId", "taskId", "targetEndpointId", "workspaceId", "taskType", "instructions", "skillBundle", "requiredSkills", "authority", "execution", "acceptance", "budget", "expiresAt"],
  "properties": {
    "schema": { "const": "dharma.task-action/v1" },
    "organizationId": { "type": "string", "minLength": 1 },
    "actionId": { "type": "string", "format": "uuid" },
    "taskId": { "type": "string", "format": "uuid" },
    "targetEndpointId": { "type": "string", "format": "uuid" },
    "workspaceId": { "type": "string", "minLength": 1 },
    "taskType": { "type": "string", "enum": ["external_request", "a2a_handoff", "evaluation_retest", "remediation_smoke"] },
    "instructions": { "type": "string", "minLength": 1, "maxLength": 20000 },
    "source": { "type": "object", "additionalProperties": false, "required": ["taskId", "endpointId"], "properties": { "taskId": { "type": "string", "format": "uuid" }, "endpointId": { "type": "string", "format": "uuid" } } },
    "stateEnvelope": { "type": "object", "additionalProperties": false, "required": ["intent", "evidence_used", "known_state", "unknown_or_missing_state", "allowed_next_actions", "blocked_actions", "decision_authority", "tool_results"], "properties": { "intent": { "type": "string", "minLength": 1, "maxLength": 1000 }, "evidence_used": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 500 } }, "known_state": { "type": "object", "maxProperties": 100 }, "unknown_or_missing_state": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 1000 } }, "allowed_next_actions": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 500 } }, "blocked_actions": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 500 } }, "decision_authority": { "type": "string", "minLength": 1, "maxLength": 1000 }, "tool_results": { "type": "array", "maxItems": 50 } } },
    "evidenceReferences": { "type": "array", "maxItems": 20, "items": { "type": "object", "additionalProperties": false, "required": ["trajectoryId", "revision", "capsuleHash"], "properties": { "trajectoryId": { "type": "string", "format": "uuid" }, "revision": { "type": "integer", "minimum": 1 }, "capsuleHash": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" } } } },
    "skillBundle": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["bundleId", "bundleHash"],
          "properties": {
            "bundleId": { "type": "string", "format": "uuid" },
            "bundleHash": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
          }
        },
        { "type": "null" }
      ]
    },
    "requiredSkills": { "type": "array", "maxItems": 50, "items": { "type": "object", "additionalProperties": false, "required": ["skillId", "version", "commit", "contentHash"], "properties": { "skillId": { "type": "string", "minLength": 1, "maxLength": 200 }, "version": { "type": "string", "minLength": 1, "maxLength": 100 }, "commit": { "type": "string", "pattern": "^[A-Fa-f0-9]{40,64}$" }, "contentHash": { "type": "string", "pattern": "^(sha256|blake3):[A-Fa-f0-9]{32,128}$" } } } },
    "authority": { "type": "object", "additionalProperties": false, "required": ["readPaths", "writePaths", "commands", "network", "git"], "properties": { "readPaths": { "type": "array", "items": { "type": "string" } }, "writePaths": { "type": "array", "items": { "type": "string" } }, "commands": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": ["commandId"], "properties": { "commandId": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" } } } }, "network": { "type": "string", "enum": ["deny", "package_registry_only", "allowlisted_domains", "inherit_local_provider"] }, "git": { "type": "string", "enum": ["read_only", "task_branch", "merge_allowed", "deploy_allowed"] }, "allowlistedDomains": { "type": "array", "items": { "type": "string" }, "default": [] } } },
    "execution": { "type": "object", "additionalProperties": false, "required": ["isolation", "timeoutSeconds", "leaseSeconds", "maximumConcurrentAgents"], "properties": { "isolation": { "const": "git_worktree" }, "timeoutSeconds": { "type": "integer", "minimum": 1 }, "leaseSeconds": { "type": "integer", "minimum": 1 }, "maximumConcurrentAgents": { "type": "integer", "minimum": 1 } } },
    "acceptance": { "type": "object", "additionalProperties": false, "required": ["commands", "requiredArtifacts"], "properties": { "commands": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": ["commandId"], "properties": { "commandId": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" } } } }, "requiredArtifacts": { "type": "array", "items": { "type": "string" } }, "externalEffectReceiptCommandId": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" } } },
    "budget": { "type": "object", "additionalProperties": false, "required": ["mode", "maximumDharmaCostCents"], "properties": { "mode": { "type": "string", "enum": ["byok_local", "byok_cloud", "dharma_managed"] }, "maximumDharmaCostCents": { "type": "integer", "minimum": 0 }, "maximumProviderCostCents": { "type": ["integer", "null"], "minimum": 0 } } },
    "expiresAt": { "type": "string", "format": "date-time" }
  },
  "allOf": [{ "if": { "properties": { "taskType": { "const": "a2a_handoff" } }, "required": ["taskType"] }, "then": { "required": ["source", "stateEnvelope", "evidenceReferences"] }, "else": { "not": { "anyOf": [{ "required": ["source"] }, { "required": ["stateEnvelope"] }, { "required": ["evidenceReferences"] }] } } }]
}
