{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/paywithlocus-com/json-schema/paywithlocus-com-task-envelope-schema.json",
  "title": "TaskEnvelope",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/paywithlocus-com-openapi.json#/components/schemas/TaskEnvelope",
  "type": "object",
  "required": [
    "object",
    "version",
    "task_id",
    "status",
    "terminal",
    "cost"
  ],
  "properties": {
    "object": {
      "type": "string",
      "enum": [
        "task"
      ]
    },
    "version": {
      "type": "string",
      "enum": [
        "locus.task.v1"
      ]
    },
    "task_id": {
      "type": "string",
      "format": "uuid"
    },
    "status": {
      "type": "string",
      "enum": [
        "queued",
        "running",
        "needs_input",
        "completed",
        "partial",
        "unsupported",
        "failed",
        "canceled"
      ],
      "description": "completed = every mandatory requirement met by checks; partial = useful verified subset; needs_input = answer `question` with action respond; unsupported = no enabled capability can do it; failed = nothing usable; canceled = caller canceled."
    },
    "terminal": {
      "type": "boolean"
    },
    "stop_reason": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "completed",
        "count_shortfall",
        "requirements_unmet",
        "budget_exhausted",
        "insufficient_credits",
        "deadline",
        "canceled",
        "needs_input",
        "no_capability",
        "no_progress",
        "step_limit",
        "authorization_revoked",
        "execution_error",
        null
      ]
    },
    "goal": {
      "type": "string"
    },
    "question": {
      "type": "string",
      "description": "Present when status is needs_input."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "completed_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "deadline_at": {
      "type": "string",
      "format": "date-time"
    },
    "progress": {
      "type": "object",
      "properties": {
        "phase": {
          "type": "string"
        },
        "turns": {
          "type": "integer"
        },
        "paid_calls": {
          "type": "integer"
        },
        "last_event": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "type": {
              "type": "string"
            },
            "at": {
              "type": "string",
              "format": "date-time"
            }
          }
        }
      }
    },
    "result": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "summary": {
          "type": [
            "string",
            "null"
          ],
          "description": "States only what Locus's checks established (verified counts, unmet requirements, stop reason)."
        },
        "executor_summary": {
          "type": [
            "string",
            "null"
          ],
          "description": "The executor's own account of the work; not verified."
        },
        "data": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "columns": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "row_count": {
              "type": "integer"
            },
            "group_count": {
              "type": "integer"
            },
            "truncated": {
              "type": "boolean"
            }
          }
        },
        "answer": {
          "type": [
            "string",
            "null"
          ],
          "description": "Markdown answer for answer-type goals (every claim is cited), or, when the goal asks for a Markdown table, the delivered table as one Markdown table under the caller's column headers (first 200 rows; results.md has all)."
        },
        "unverified_rows": {
          "type": "array",
          "description": "Table rows the executor recorded as qualified that failed verification, with their recorded values and why each was withheld (up to 25). Not part of data and not counted as delivered.",
          "items": {
            "type": "object",
            "properties": {
              "values": {
                "type": "object",
                "additionalProperties": true
              },
              "reasons": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "artifacts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/TaskArtifact"
      }
    },
    "requirements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/TaskRequirement"
      }
    },
    "assumptions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "limitations": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "cost": {
      "type": "object",
      "required": [
        "unit",
        "max_credits",
        "charged_credits",
        "reserved_credits",
        "accounting_state"
      ],
      "properties": {
        "unit": {
          "type": "string",
          "enum": [
            "credits"
          ]
        },
        "max_credits": {
          "type": "string"
        },
        "charged_credits": {
          "type": "string",
          "description": "Settled charges so far, net of refunds. A task whose first outcome delivers nothing gets its model credits back above a 0.01 USD base charge, up to a monthly limit per account; limitations says what was refunded."
        },
        "reserved_credits": {
          "type": "string",
          "description": "Held for in-flight or unknown-outcome calls; released or captured on reconciliation."
        },
        "tool_credits": {
          "type": "string"
        },
        "model_credits": {
          "type": "string"
        },
        "paid_calls": {
          "type": "integer"
        },
        "accounting_state": {
          "type": "string",
          "enum": [
            "in_progress",
            "settled",
            "pending_reconciliation"
          ]
        }
      }
    },
    "error": {
      "type": "object",
      "description": "Present when the run recorded an execution error.",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "continuation": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "action": {
          "type": "string",
          "enum": [
            "wait",
            "respond",
            "resume"
          ]
        },
        "task_id": {
          "type": "string",
          "format": "uuid"
        },
        "hint": {
          "type": "string"
        }
      }
    }
  },
  "$defs": {
    "TaskArtifact": {
      "type": "object",
      "required": [
        "artifact_id",
        "name",
        "kind",
        "media_type",
        "sha256",
        "expires_at",
        "download_url",
        "link_expires_at"
      ],
      "properties": {
        "artifact_id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "result",
            "evidence"
          ]
        },
        "media_type": {
          "type": "string"
        },
        "size_bytes": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sha256": {
          "type": "string"
        },
        "expires_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the stored file is deleted (7 days)."
        },
        "download_url": {
          "type": "string",
          "format": "uri",
          "description": "Signed link bound to this tenant, account, task, and exact bytes; no Authorization header needed."
        },
        "link_expires_at": {
          "type": "string",
          "format": "date-time",
          "description": "Link lifetime (1 hour); call status again for a fresh link."
        }
      }
    },
    "TaskRequirement": {
      "type": "object",
      "required": [
        "id",
        "text",
        "status",
        "mandatory",
        "detail"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "text": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "met",
            "unmet",
            "not_checked"
          ]
        },
        "mandatory": {
          "type": "boolean"
        },
        "detail": {
          "type": "string"
        }
      }
    }
  }
}