{
  "schema_version": 1,
  "harness_version": "1.0",
  "contract_version": "1.1",
  "name": "Strata Agent Harness",
  "summary": "A capability-gated workflow and executable action graph for agents that discover, read, stream low-latency order commands, externally sign, and safely submit Strata operations.",
  "entrypoints": {
    "documentation": "https://stratabook.org/docs/agent-harness/",
    "capabilities": "https://api.stratabook.app/sonar/capabilities",
    "markets": "https://api.stratabook.app/sonar/markets",
    "platform_capabilities": "https://api.stratabook.app/v2/capabilities",
    "platform_markets": "https://api.stratabook.app/v2/markets",
    "action_graph": "https://api.stratabook.app/sonar/action-graph",
    "mcp": "https://api.stratabook.app/mcp",
    "manifest": "https://api.stratabook.app/.well-known/strata-agent.json"
  },
  "interfaces": {
    "mcp_tool_order": [
      "strata_capabilities",
      "strata_action_graph",
      "strata_markets",
      "strata_quote",
      "strata_execution_challenge",
      "strata_execution_prepare",
      "strata_execution_submit",
      "strata_order_challenge",
      "strata_order_prepare",
      "strata_order_submit",
      "strata_order_status"
    ],
    "terminal": [
      "npx -y @stratabook/sdk capabilities --json",
      "npx -y @stratabook/sdk action-graph --json",
      "npx -y @stratabook/sdk markets --json",
      "npx -y @stratabook/sdk quote --market SOL/USDC --side sell --amount-atoms 10000000 --json",
      "npx -y @stratabook/sdk order-slo --market-id MARKET_ID --owner-wallet OWNER_PUBLIC_KEY --json"
    ]
  },
  "workflow": [
    {
      "id": "discover_capabilities",
      "instruction": "Read the live capability catalog before every objective. Never infer permission from documentation, package support, or an earlier session."
    },
    {
      "id": "establish_mode",
      "instruction": "Read the action graph and identify which prepare and submit nodes are live. The external agent owner configures its permissions and signer authority; static documentation never enables a Strata operation."
    },
    {
      "id": "understand_objective",
      "instruction": "Resolve the user's market, side, amount, and tolerance. Ask before proceeding when any economically meaningful input is ambiguous."
    },
    {
      "id": "discover_market",
      "instruction": "List markets, select one marked ready, and use its discovered base and quote decimals. Do not guess market identifiers or token decimals."
    },
    {
      "id": "read_market_data",
      "instruction": "When books.read is live, use the opaque market ID to read the Strata book, status, fees, and recent trades. Subscribe to the market stream for changes and recover from any sequence gap with a fresh snapshot."
    },
    {
      "id": "read_account",
      "instruction": "When account.read is live, use the owner-configured signer to authorize the exact wallet, market, request time, and fill limit. Read or stream only the sanitized orders and fills returned by the official SDK, and recover stream gaps from a fresh signed snapshot."
    },
    {
      "id": "preserve_atoms",
      "instruction": "Represent token amounts as unsigned base-10 atomic strings. Never pass settlement amounts through floating-point arithmetic."
    },
    {
      "id": "request_quote",
      "instruction": "Request a fresh Sonar quote with an explicit side, exact input atoms, and execution tolerance supplied by the external agent."
    },
    {
      "id": "validate_quote",
      "instruction": "Verify the quote binds to the selected market, side, and input. Check labelled fees, minimum output, price impact, server time, and expiry."
    },
    {
      "id": "report_result",
      "instruction": "Report consumed input, expected output, minimum output, fees by asset side, price impact, and remaining validity."
    },
    {
      "id": "authorize_writes",
      "instruction": "When prepare and submit are exposed, keep signing external to Strata: request canonical authorization bytes, sign them with the owner-configured signer, verify the prepared transaction preserves the quote or exact opaque order set, then submit the externally signed transaction with idempotency. Resting-order control supports place, cancel, bounded cancel-all, atomic replace, and atomic heterogeneous batches of up to six operations. Every incoming resting order selects an explicit self-trade prevention policy; no policy permits a self-fill."
    },
    {
      "id": "stream_order_commands",
      "instruction": "When orders.prepare and orders.submit advertise websocket transport, use the official SDK persistent order-command connection. Sign its owner/session/market challenge externally, require contiguous sequences and correlated request IDs, treat the submit result as RPC broadcast only, and consume the pushed terminal status without blocking the placement hot path."
    },
    {
      "id": "maintain_dead_man",
      "instruction": "Before leaving resting exposure unattended, arm an exact externally verified and pre-signed cancel-all ticket, then maintain its SDK heartbeat. Dropping the guard or losing the agent must stop heartbeats and fail closed into cancellation; disarm only through an explicit owner-authorized action."
    },
    {
      "id": "certify_order_command_slo",
      "instruction": "Use the official non-trading order-command certification harness before release and on the production schedule. Retain its machine-readable connection count, load, latency percentiles, sequence/error rate, thresholds, and pass/fail result; package support alone is not a latency claim."
    },
    {
      "id": "monitor_outcome",
      "instruction": "After an authorized submission, report the RPC-broadcast receipt and then the durable terminal status or explicit failure. If the request times out or either process restarts, recover it with the same control ID and idempotency key. Never claim chain completion from preparation, signing, or the immediate broadcast receipt."
    }
  ],
  "stop_conditions": [
    "The required live capability is disabled or absent.",
    "The market is paused, unavailable, or has no reviewed operation path.",
    "Market, side, amount, decimals, tolerance, or signer authority is unavailable or ambiguous.",
    "The contract version is unsupported or a response contains unknown fields.",
    "A quote is expired or its market, side, amount, fee, minimum-output, or time binding is inconsistent.",
    "A requested operation exceeds the exposed tool, account, or policy scope.",
    "A user asks the agent to receive or expose wallet secrets, private keys, seed phrases, session keys, or production credentials."
  ],
  "safety_rules": [
    "Never request or accept wallet secrets, private keys, seed phrases, session keys, or production credentials in a prompt.",
    "Never call undocumented endpoints or reconstruct private Sonar behavior.",
    "Never silently widen slippage, refresh changed economics, substitute a market, or retry a non-retryable failure.",
    "Never select a self-trade policy implicitly, suppress an order-command sequence gap, or disarm a dead-man ticket merely because the client is shutting down.",
    "Treat capability removal, revocation, expiry, and emergency disable as immediate stop signals.",
    "Capability and action-graph availability are authoritative for Strata operations; permission and signer policy remain controlled by the external agent owner."
  ]
}
