Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

58.5 KB
Raw Blame
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Jan agent protocol v1",
  "description": "Every record a `jan cli agent run` writes to stdout, and every line a client may write to stdin. The `x-protocol-version` keyword names the contract version this document describes.",
  "type": "object",
  "properties": {
    "output": {
      "description": "Records a run writes to stdout. The first is `init`, and the last is\n`result`; everything between them is a `StreamEvent` or a\nCLI-minted record.",
      "$ref": "#/$defs/OutputRecord"
    },
    "input": {
      "description": "Lines a client may write to stdin. What this run accepts is reported by\n`init`'s `input_kinds`, which is empty when the run reads no stdin.",
      "$ref": "#/$defs/InputLine"
    }
  },
  "required": [
    "output",
    "input"
  ],
  "$defs": {
    "OutputRecord": {
      "description": "Any record a run writes to stdout.",
      "anyOf": [
        {
          "$ref": "#/$defs/StreamEvent"
        },
        {
          "$ref": "#/$defs/Init"
        },
        {
          "$ref": "#/$defs/RunResult"
        },
        {
          "$ref": "#/$defs/PermissionDecisionRecord"
        },
        {
          "$ref": "#/$defs/InputErrorRecord"
        }
      ]
    },
    "StreamEvent": {
      "oneOf": [
        {
          "description": "A streamed content delta from the model.",
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "token"
            }
          },
          "required": [
            "type",
            "text"
          ]
        },
        {
          "description": "A streamed reasoning delta, carried natively when the upstream exposes\nit as a dedicated field (`reasoning_content`). Display-only: reasoning\nnever joins the assistant `content` that is resent as history, and it\nmust never leak into piped stdout. Providers that instead inline\n`<think>` tags in `content` stream those through [`Token`]; consumers\nfall back to stripping the tags manually.",
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "reasoning"
            }
          },
          "required": [
            "type",
            "text"
          ]
        },
        {
          "description": "A new orchestration turn began (`index` is 1-based; `max` is the turn\ncap, `0` when the run is unbounded, which is the normal case).",
          "type": "object",
          "properties": {
            "index": {
              "type": "integer",
              "format": "uint32",
              "minimum": 0
            },
            "max": {
              "type": "integer",
              "format": "uint32",
              "minimum": 0
            },
            "type": {
              "type": "string",
              "const": "step"
            }
          },
          "required": [
            "type",
            "index",
            "max"
          ]
        },
        {
          "description": "A tool call started streaming: emitted mid-stream the instant the model's\ntool-call `id` and `name` are known, before its arguments finish\nstreaming. Lets a consumer show an in-progress indicator during the\n(potentially long) argument-streaming window; the full [`ToolCall`] with\nparsed `args` follows once the completion is assembled.",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "tool_call_started"
            }
          },
          "required": [
            "type",
            "id",
            "name"
          ]
        },
        {
          "description": "A chunk of a tool call's raw JSON arguments, exactly as it arrived on the\nwire. Emitted between [`ToolCallStarted`] and [`ToolCall`] so a consumer\ncan render the arguments as they land -- the difference between a\nfeatureless spinner and a live preview while a large `write` streams.\n\nDeltas, not the accumulated buffer: re-sending the whole prefix on every\nchunk is quadratic in a file-sized argument. Consumers concatenate.\nThe result is *incomplete JSON* until [`ToolCall`] arrives; parse it\nleniently or not at all.",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "delta": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "tool_call_args_delta"
            }
          },
          "required": [
            "type",
            "id",
            "delta"
          ]
        },
        {
          "description": "The model requested a tool call. `args` is the parsed argument object\n(null if the model emitted non-JSON arguments).",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "args": true,
            "type": {
              "type": "string",
              "const": "tool_call"
            }
          },
          "required": [
            "type",
            "id",
            "name",
            "args"
          ]
        },
        {
          "description": "A chunk of a tool's output, as it is produced. Emitted between\n[`ToolCall`] and [`ToolResult`] so a consumer can show a command's output\nwhile it runs instead of only once it exits.\n\nDeltas, not the accumulated buffer, for the same reason as\n[`ToolCallArgsDelta`]: resending the prefix on every chunk is quadratic in\nthe output size. Chunks are raw fragments and may split a line.\n\nKeeps arriving after a `bash` call has backgrounded itself, so a\nlong-running job reports progress under the id of the call that started it.",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "delta": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "tool_output_delta"
            }
          },
          "required": [
            "type",
            "id",
            "delta"
          ]
        },
        {
          "description": "A tool finished. `is_error` reflects the upstream \"ERROR\" encoding.\n`diff` is display-only focused-change text (line-prefixed `-`/`+`) for\n`write`/`edit`; `None` for other tools.",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "content": {
              "type": "string"
            },
            "is_error": {
              "type": "boolean"
            },
            "diff": {
              "type": [
                "string",
                "null"
              ]
            },
            "type": {
              "type": "string",
              "const": "tool_result"
            }
          },
          "required": [
            "type",
            "id",
            "content",
            "is_error"
          ]
        },
        {
          "description": "A backgrounded subagent run began. `run_id` identifies the run so a\nconsumer can attribute concurrent children; brackets the child's wrapped\nevents with `SubagentEnd`.",
          "type": "object",
          "properties": {
            "run_id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "task": {
              "description": "The task the child was dispatched with -- its sole user message.\nCarried on the event rather than left for consumers to correlate\nback to the `dispatch_subagent` call: two dispatches can share a\n`subagent_name`, so matching on name alone is ambiguous.",
              "type": [
                "string",
                "null"
              ]
            },
            "workspace": {
              "description": "Where the child works: its own worktree and branch, or the\ncheckout it was given, marked when read-only.",
              "type": [
                "string",
                "null"
              ]
            },
            "internal": {
              "description": "An agent Jan runs for itself (memory tidy) rather than one the\nmodel dispatched. A consumer lists it with the other subagents,\nmarked as Jan's own, and keeps its run out of the conversation.",
              "type": "boolean"
            },
            "type": {
              "type": "string",
              "const": "subagent_start"
            }
          },
          "required": [
            "type",
            "run_id",
            "name"
          ]
        },
        {
          "description": "A backgrounded subagent dispatch found the parent run's concurrency cap\n(`max_parallel_subagents`) exhausted and queued the child in FIFO order.\n`waiting` is the child's 1-based position in the queue (1 = next to\nstart). The child's `SubagentStart` follows once a slot frees; a queued\nchild aborted at parent teardown is closed by `SubagentEnd` like any\nother.",
          "type": "object",
          "properties": {
            "run_id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "task": {
              "type": [
                "string",
                "null"
              ]
            },
            "waiting": {
              "type": "integer",
              "format": "uint32",
              "minimum": 0
            },
            "type": {
              "type": "string",
              "const": "subagent_queued"
            }
          },
          "required": [
            "type",
            "run_id",
            "name",
            "waiting"
          ]
        },
        {
          "description": "A backgrounded subagent run finished (success or error). Pairs with the\n`SubagentStart` of the same `run_id`.",
          "type": "object",
          "properties": {
            "run_id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "error": {
              "description": "Why the child failed, when it did: the same reason the parent's\n`<SYSTEM>` completion ping carries. Carried on the event because a\nbackground child's answer never reaches a consumer -- only the model\nreads it -- so without this a failed run is indistinguishable from a\nclean one on screen. `None` for a clean finish, and for a child cut\noff at parent teardown, which is not its own failure.",
              "type": [
                "string",
                "null"
              ]
            },
            "type": {
              "type": "string",
              "const": "subagent_end"
            }
          },
          "required": [
            "type",
            "run_id",
            "name"
          ]
        },
        {
          "description": "The later phases of a phased dispatch, named up front so a consumer can\nshow their subagents as WAITING on an earlier phase before they start.\nEach pending subagent is promoted by its own `SubagentStart` (or\n`SubagentQueued`), matched by `name`, which is unique across a plan.\nDisplay-only and never journaled; emitted only by the top-level run\n(children cannot dispatch), so it is never wrapped in `Subagent`.",
          "type": "object",
          "properties": {
            "pending": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/PendingSubagent"
              }
            },
            "type": {
              "type": "string",
              "const": "subagent_plan"
            }
          },
          "required": [
            "type",
            "pending"
          ]
        },
        {
          "description": "A backgrounded subagent's own internal event, tagged with its run so a\nconsumer can attribute it to the right child even when several run\nconcurrently. `event` is a non-terminal child event (Token/Step/ToolCall/\nToolResult/PermissionRequest/Parked); the child's terminal Done/Error is\nnever wrapped (its result is delivered via `await_subagent`). A wrapped\n`Parked` describes that child alone and is display-only: the parent run\nis not parked by it.\n\nNever a `ToolRequest`: a client answers a request by `request_id` on\nstdin, and it is told nothing about this wrapper, so a nested request\nwould be unanswerable. A child's host tool call is routed to the root\nchannel unwrapped instead, attributed by `ToolRequest.run_id`.",
          "type": "object",
          "properties": {
            "run_id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "event": {
              "$ref": "#/$defs/StreamEvent"
            },
            "type": {
              "type": "string",
              "const": "subagent"
            }
          },
          "required": [
            "type",
            "run_id",
            "name",
            "event"
          ]
        },
        {
          "description": "The user-facing headline of a background ping the loop just delivered to\nthe model as a `<SYSTEM>` reminder (today: a `monitor` condition\nmatching). Emitted at delivery, not when the ping is queued, so the\ntranscript reads in the order the model saw things. Display-only and\ntransient, like notes: it is never journaled.",
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "notice"
            }
          },
          "required": [
            "type",
            "text"
          ]
        },
        {
          "description": "A message between the main agent and one of its subagents, emitted when\nit is delivered at the reader's turn boundary rather than when it was\nqueued, so the transcript reads in the order the reader saw things.\n`from` and `to` name the agents: a subagent by its worker name, the\nmain agent as [`MAIN_AGENT`]. A message to a subagent (the\n`message_subagent` tool, or the user steering it from `/agents`) is\nemitted on the child's own stream, so it reaches the parent wrapped in\n`Subagent`; a subagent's `message_main_agent` is emitted on the main\nrun's. Display-only: the message itself is already in the reader's\nhistory.",
          "type": "object",
          "properties": {
            "from": {
              "type": "string"
            },
            "to": {
              "type": "string"
            },
            "text": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "agent_message"
            }
          },
          "required": [
            "type",
            "from",
            "to",
            "text"
          ]
        },
        {
          "description": "The loop is summarizing part of the conversation to make room. Sent as\n`Started` before the summarizer call and `Finished` or `Failed` after\nit, so a consumer can show progress for what is otherwise a silent\nround trip. `reason` says which path asked. `messages` is how many were\nfolded into the summary and `report` what the summarizer did, both\n`None` except on `Finished`. Display-only and never journaled; the\ncompacted history itself arrives as `MessagesUpdated`.",
          "type": "object",
          "properties": {
            "phase": {
              "$ref": "#/$defs/CompactionPhase"
            },
            "reason": {
              "$ref": "#/$defs/CompactionReason"
            },
            "messages": {
              "type": [
                "integer",
                "null"
              ],
              "format": "uint",
              "minimum": 0
            },
            "report": {
              "anyOf": [
                {
                  "$ref": "#/$defs/CompactionReport"
                },
                {
                  "type": "null"
                }
              ]
            },
            "type": {
              "type": "string",
              "const": "compaction"
            }
          },
          "required": [
            "type",
            "phase",
            "reason"
          ]
        },
        {
          "description": "The upstream request failed before anything streamed and is about to be\nsent again after `delay_ms`. `attempt` is the 1-based attempt that\nfollows the wait, out of `max_attempts`; `reason` is the failure that\nprompted it. Sent once per retry so a consumer can say \"retrying\" rather\nthan show a spinner that looks like a slow model. Display-only and never\njournaled; the turn continues with the next event or ends in `Error`.",
          "type": "object",
          "properties": {
            "attempt": {
              "type": "integer",
              "format": "uint32",
              "minimum": 0
            },
            "max_attempts": {
              "type": "integer",
              "format": "uint32",
              "minimum": 0
            },
            "delay_ms": {
              "type": "integer",
              "format": "uint64",
              "minimum": 0
            },
            "reason": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "retry"
            }
          },
          "required": [
            "type",
            "attempt",
            "max_attempts",
            "delay_ms",
            "reason"
          ]
        },
        {
          "description": "The run's active file monitors, as a whole replacing the previous set.\nEmitted whenever the set changes (a `monitor` start or stop, a condition\nmatching, a monitor finishing), so a consumer keeps a live view without\nbookkeeping of its own. Display-only and never journaled. Not forwarded\nfrom a child: a child's monitors are its own.",
          "type": "object",
          "properties": {
            "monitors": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/MonitorSnapshot"
              }
            },
            "type": {
              "type": "string",
              "const": "monitors"
            }
          },
          "required": [
            "type",
            "monitors"
          ]
        },
        {
          "description": "The model has finished its turn and the loop is parked on background\nwork it started (a subagent still running, a monitor still watching).\nNothing is being generated until a ping resumes the run, which the next\n`Step` marks. Lets a consumer say \"watching\" rather than \"working\".\nWrapped in `Subagent`, it describes that child instead and is\ndisplay-only: the parent's own state is unchanged.",
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "parked"
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "description": "The client should replace its session history with `messages` before\nsubsequent turns. Includes accepted prompt guidance in its original\nposition, but not a pending block from an unsuccessful request. Also\ncarries compacted history when the loop retries a context overflow.",
          "type": "object",
          "properties": {
            "messages": {
              "type": "array",
              "items": true
            },
            "type": {
              "type": "string",
              "const": "messages_updated"
            }
          },
          "required": [
            "type",
            "messages"
          ]
        },
        {
          "description": "The `ask` tool is waiting for structured interactive input. Carries the\n`ask_timeout_secs` deadline (seconds until the loop auto-selects the\nrecommended option) as `timeout_secs`, or `None` when no timeout is\nconfigured. It travels on the event so a client can render a countdown\nwithout re-reading config: the same value both arms the loop's timer and\ndrives the display, keeping the two in agreement.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "request": {
              "$ref": "#/$defs/AskRequest"
            },
            "timeout_secs": {
              "type": [
                "integer",
                "null"
              ],
              "format": "uint64",
              "minimum": 0
            },
            "type": {
              "type": "string",
              "const": "ask_request"
            }
          },
          "required": [
            "type",
            "request_id",
            "request"
          ]
        },
        {
          "description": "An `ask` request the loop resolved without a user answer (it timed out\nand auto-selected). Tells a client showing the live prompt for\n`request_id` to dismiss it, since no `respond` from that client is\ncoming. User-driven answers never emit this: the client clears its own\nprompt as it responds.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "ask_resolved"
            }
          },
          "required": [
            "type",
            "request_id"
          ]
        },
        {
          "description": "The canonical todo list changed (tool mutation or user edit in the\nTUI). Carries the full resulting snapshot for reconstruction.",
          "type": "object",
          "properties": {
            "list": {
              "$ref": "#/$defs/TodoList"
            },
            "type": {
              "type": "string",
              "const": "todo_update"
            }
          },
          "required": [
            "type",
            "list"
          ]
        },
        {
          "description": "Token usage for a single upstream request, emitted as soon as that\nrequest completes rather than waiting for the run to finish.\n\n`Done` carries only the *last* request's usage, which is too late and\ntoo little for a live display: a turn that calls tools makes many\nrequests, and a subagent never emits `Done` into the parent stream at\nall. Consumers accumulate these to show context pressure, output\nvolume, and throughput while the work is still happening -- for the\nparent run and, via the [`Subagent`] bracket, for each child.",
          "type": "object",
          "properties": {
            "usage": {
              "$ref": "#/$defs/Usage"
            },
            "execution_id": {
              "description": "The provider's id for the execution that produced this usage, when\nit reported one. This is the handle a per-request billing lookup is\nkeyed by, so a consumer can ask what this one request actually\ncost rather than only what it estimates.\n\nA sibling of `usage` rather than a field inside it, because it is a\nbilling handle and not a token count. Absent on the default upstream\npath, which cannot see the response headers (see\n[`crate::core::agent::correlation`]); that is a limitation to report,\nnot a reason to synthesize one.",
              "type": [
                "string",
                "null"
              ]
            },
            "type": {
              "type": "string",
              "const": "turn_usage"
            }
          },
          "required": [
            "type",
            "usage"
          ]
        },
        {
          "description": "Terminal success: the model returned a final (tool-free) completion.",
          "type": "object",
          "properties": {
            "stop_reason": {
              "type": "string"
            },
            "usage": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Usage"
                },
                {
                  "type": "null"
                }
              ]
            },
            "type": {
              "type": "string",
              "const": "done"
            }
          },
          "required": [
            "type",
            "stop_reason"
          ]
        },
        {
          "description": "Terminal failure (setup error, upstream/tool failure, or max_turns).",
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "error"
            }
          },
          "required": [
            "type",
            "code",
            "message"
          ]
        },
        {
          "description": "The loop needs the user to approve a gated tool call. The client replies via\nthe `agent_permission_respond` command referencing `request_id`.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "tool_name": {
              "type": "string"
            },
            "capability": {
              "type": "string"
            },
            "path": {
              "type": [
                "string",
                "null"
              ]
            },
            "command": {
              "description": "The shell command for exec prompts (drives the command-scoped\n\"allow always\" grant); `None` for non-exec tools.",
              "type": [
                "string",
                "null"
              ]
            },
            "diff": {
              "description": "Focused diff preview for `write`/`edit` prompts so the user sees the\nchange before approving; `None` for other tools.",
              "type": [
                "string",
                "null"
              ]
            },
            "prompt_kind": {
              "type": "string"
            },
            "offers_always": {
              "type": "boolean"
            },
            "justification": {
              "description": "The model's reason for an `escalate` prompt (running a shell command\noutside the sandbox), shown beside the command; `None` otherwise.",
              "type": [
                "string",
                "null"
              ]
            },
            "type": {
              "type": "string",
              "const": "permission_request"
            }
          },
          "required": [
            "type",
            "request_id",
            "tool_name",
            "capability",
            "prompt_kind",
            "offers_always"
          ]
        },
        {
          "description": "A host-registered tool was called and the run is waiting for the host to\nexecute it. The client replies with a `tool_result` line carrying this\n`request_id`; until it does, the turn is parked on this one call.\n\n`tool_name` is the name the *host* declared, not the `host__`-prefixed\nname the model calls: the host dispatches on the name it chose and never\nhas to know this layer's prefixing rule.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "tool_name": {
              "type": "string"
            },
            "args": {
              "description": "The arguments the model produced, already parsed from the call's\nJSON string. Validated against nothing here -- the host owns the\nschema it declared and is the only party that can enforce it."
            },
            "run_id": {
              "description": "Which run raised the request: `None` for the main run, the child's\nrun id for a subagent. Attribution only -- the host answers by\n`request_id` alone, and a child's request is emitted unwrapped at\nthe top level so the same answer path serves both.",
              "type": [
                "string",
                "null"
              ]
            },
            "type": {
              "type": "string",
              "const": "tool_request"
            }
          },
          "required": [
            "type",
            "request_id",
            "tool_name",
            "args"
          ]
        },
        {
          "description": "A pending [`StreamEvent::ToolRequest`] was withdrawn: the host must not\nanswer it any more, and a late answer is reported as not pending.\n`reason` is `aborted` | `interrupted` | `client_gone`.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "reason": {
              "type": "string"
            },
            "type": {
              "type": "string",
              "const": "tool_request_cancelled"
            }
          },
          "required": [
            "type",
            "request_id",
            "reason"
          ]
        },
        {
          "description": "Host/UI-only structured data a host tool returned alongside its result,\nemitted right after that call's [`StreamEvent::ToolResult`] (same `id`).\nNever sent to the model; a display may render it or ignore it.",
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "details": true,
            "type": {
              "type": "string",
              "const": "tool_details"
            }
          },
          "required": [
            "type",
            "id",
            "details"
          ]
        },
        {
          "description": "What the run is about to send a provider, emitted immediately before\neach request goes out -- the hook an experiment harness needs to hold two\nruns comparable (pi's `onPayload` is the shape Robot Studio already\nrecords).\n\nEvery outbound request gets one, including the side calls a turn makes\n(compaction, a session title) and every child run's own requests; the\nhashes describe the body Jan built for the adapter, so two runs can be\ncompared field by field. Nothing here is model input or output: it never\njoins the transcript, and a consumer may render it, store it or ignore\nit.",
          "type": "object",
          "properties": {
            "run_id": {
              "description": "Which run made the request: `None` for the main run, the child's\nrun id for a subagent.",
              "type": [
                "string",
                "null"
              ]
            },
            "session_id": {
              "description": "The session the request belongs to, as the run's handshake names it\n(the correlation id the request carries is derived from it).",
              "type": [
                "string",
                "null"
              ]
            },
            "provider": {
              "description": "The configured provider the model resolved to.",
              "type": [
                "string",
                "null"
              ]
            },
            "model": {
              "description": "The model id the upstream receives, without a `<provider>/` prefix.",
              "type": "string"
            },
            "api_type": {
              "description": "The wire API the request is built for (`anthropic`, `google`,\n`openai-responses`), absent for chat/completions.",
              "type": [
                "string",
                "null"
              ]
            },
            "request_sha256": {
              "description": "SHA-256 of the request body as Jan built it, as canonical JSON:\nevery object's keys sorted, recursively, so re-encoding the same\nmembers in another order gives the same digest. It is the value that\nmakes two runs comparable even when a field this record does not\nitemize has changed.\n\nThe body hashed is the one Jan built, before the provider adapter\nappends its transport fields (`stream`, `stream_options`), so it is\nnot byte-for-byte what the provider received: a harness recomputes it\nby sorting keys and dropping those two fields.",
              "type": "string"
            },
            "body_bytes": {
              "description": "The canonical body's serialized length. Key order does not change it,\nso it describes the built body either way.",
              "type": "integer",
              "format": "uint64",
              "minimum": 0
            },
            "tools_sha256": {
              "description": "SHA-256 of the `tools` array as sent, canonical JSON in the same\nsense, able to change while the model id does not.",
              "type": [
                "string",
                "null"
              ]
            },
            "images": {
              "description": "Every image in the body, in order, hashed over its decoded bytes so\nthe host can hash the same frame it captured.",
              "type": "array",
              "items": {
                "$ref": "#/$defs/ProvenanceImage"
              }
            },
            "type": {
              "type": "string",
              "const": "request_provenance"
            }
          },
          "required": [
            "type",
            "model",
            "request_sha256",
            "body_bytes"
          ]
        }
      ]
    },
    "PendingSubagent": {
      "description": "A subagent in a not-yet-started phase of a phased dispatch: its name (unique\nacross the plan, and its blackboard file) and 1-based phase number. Carried by\n[`StreamEvent::SubagentPlan`] so a consumer can show it waiting on the phase\nbefore it.",
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "phase": {
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        }
      },
      "required": [
        "name",
        "phase"
      ]
    },
    "CompactionPhase": {
      "description": "`Deserialize` as well as `Serialize`: a consumer validates what it received\nagainst these shapes, and `JsonSchema` is what `jan cli agent schema`\npublishes them as -- a consumer generates its own types from\n`protocol/schema.json` rather than copying this declaration. The wire has to\nsurvive a round trip, not just a write, so `#[serde(tag = \"type\")]` keeps the\ntag on both sides.\nWhere a [`StreamEvent::Compaction`] is in its round trip.",
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "started",
            "finished"
          ]
        },
        {
          "description": "The summarizer call failed or had nothing to fold; the history is\nunchanged.",
          "type": "string",
          "const": "failed"
        }
      ]
    },
    "CompactionReason": {
      "description": "Which path asked for a [`StreamEvent::Compaction`].",
      "oneOf": [
        {
          "description": "The request about to be sent was over the window's trigger.",
          "type": "string",
          "const": "preflight"
        },
        {
          "description": "The provider rejected a request as too long for its window.",
          "type": "string",
          "const": "context_overflow"
        },
        {
          "description": "The run used up its session token budget.",
          "type": "string",
          "const": "session_budget"
        }
      ]
    },
    "CompactionReport": {
      "description": "What a finished compaction did, carried on [`StreamEvent::Compaction`] so\na consumer can show the summarizer as an agent of its own: what it read,\nwhich model wrote the summary, what it cost and what it wrote.",
      "type": "object",
      "properties": {
        "model": {
          "description": "The model that wrote the summary: the `smol` model when it answered,\nelse the run's own. `None` when no model answered and the history was\nfolded into Jan's fallback note instead.",
          "type": [
            "string",
            "null"
          ]
        },
        "input_tokens": {
          "description": "Estimated tokens of the span that was folded, before it was clamped\nfor the summarizer: how much conversation the summary stands in for.",
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "usage": {
          "description": "The summarizer's own reported usage, every request it took included.",
          "anyOf": [
            {
              "$ref": "#/$defs/Usage"
            },
            {
              "type": "null"
            }
          ]
        },
        "summary": {
          "description": "The summary that now stands in for the folded span.",
          "type": "string"
        }
      },
      "required": [
        "input_tokens",
        "summary"
      ]
    },
    "Usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "completion_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "total_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "cached_tokens": {
          "description": "Prompt tokens served from the provider's prompt cache (a read/hit).\nOpenAI reports it under `prompt_tokens_details.cached_tokens`; Anthropic\nunder `cache_read_input_tokens`. A thrashing cache shows here as a low\nvalue against a high `prompt_tokens`.",
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "cache_write_tokens": {
          "description": "Prompt tokens written into the provider cache this request (a write).\nOnly Anthropic bills this separately (`cache_creation_input_tokens`);\nabsent for providers that do not distinguish reads from writes.",
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        }
      }
    },
    "MonitorSnapshot": {
      "description": "Display-only view of one active monitor, for a status panel.",
      "type": "object",
      "properties": {
        "monitorId": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "script": {
          "type": "string"
        },
        "polls": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        }
      },
      "required": [
        "monitorId",
        "name",
        "script",
        "polls"
      ]
    },
    "AskRequest": {
      "type": "object",
      "properties": {
        "questions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Question"
          }
        }
      },
      "required": [
        "questions"
      ]
    },
    "Question": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "question": {
          "type": "string"
        },
        "options": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/OptionItem"
          }
        },
        "multi": {
          "type": "boolean",
          "default": false
        },
        "recommended": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint",
          "minimum": 0,
          "default": null
        }
      },
      "required": [
        "id",
        "question",
        "options"
      ]
    },
    "OptionItem": {
      "type": "object",
      "properties": {
        "label": {
          "type": "string"
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "default": null
        }
      },
      "required": [
        "label"
      ]
    },
    "TodoList": {
      "type": "object",
      "properties": {
        "phases": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TodoPhase"
          }
        }
      },
      "required": [
        "phases"
      ]
    },
    "TodoPhase": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "tasks": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TodoItem"
          }
        }
      },
      "required": [
        "name",
        "tasks"
      ]
    },
    "TodoItem": {
      "type": "object",
      "properties": {
        "content": {
          "type": "string"
        },
        "status": {
          "$ref": "#/$defs/TodoStatus"
        }
      },
      "required": [
        "content",
        "status"
      ]
    },
    "TodoStatus": {
      "type": "string",
      "enum": [
        "pending",
        "in_progress",
        "completed",
        "abandoned"
      ]
    },
    "ProvenanceImage": {
      "description": "One image in an outbound request, as [`StreamEvent::RequestProvenance`]\nreports it: identity, not content.",
      "type": "object",
      "properties": {
        "sha256": {
          "description": "SHA-256 over the image's decoded bytes.",
          "type": "string"
        },
        "mime_type": {
          "type": "string"
        },
        "bytes": {
          "description": "Decoded length in bytes.",
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "tool_call_id": {
          "description": "The host tool call whose result carried it, when one did. `None` for an\nimage the user attached.",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "sha256",
        "mime_type",
        "bytes"
      ]
    },
    "Init": {
      "description": "The first record of a `--output-format stream-json` channel, and the only\none a client may require before any other.\n\nIt exists because the rest of the stream is unversioned and unaddressable: a\nconsumer sees events and nothing else, so it cannot tell which contract it\nis reading, whose run it is watching, or what it is allowed to send back.\nThose are the questions a handshake answers, and a consumer that has to\ninfer them from a side channel (a CLI flag it passed, a config file it read)\nis one refactor away from being wrong.\n\nField names are snake_case like the rest of this channel -- the event tags\nand the envelope's `session_id`/`stop_reason` set that convention, so the\nhandshake follows it rather than introducing a second one for two fields.\n\nThe compatibility rule for what a client may assume:\n\n- a v1 client may rely on `protocol_version`, `session_id` and `model`\n  always being present;\n- fields may be added without a version bump, so a client ignores unknown\n  ones and unknown tags rather than failing;\n- a tag is never renamed and never removed within v1;\n- behaviour beyond v1 is asserted against `protocol_version`, not assumed.",
      "type": "object",
      "properties": {
        "type": {
          "description": "The record's tag. A consumer switches on it, so the schema states the\nvalue rather than leaving it an open string.",
          "type": "string",
          "const": "init"
        },
        "protocol_version": {
          "description": "[`PROTOCOL_VERSION`](crate::core::agent::events::PROTOCOL_VERSION) at\nthe time of the run, so a client can refuse a channel it cannot read\ninstead of misreading it.",
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        },
        "session_id": {
          "description": "The thread this run saves under. Minted before the first turn rather\nthan at save time, so a client learns the id from the stream: the same\nid `--resume` takes. A run that produces no completion saves nothing,\nand its terminal envelope reports `session_id: null` -- which is how a\nclient tells this id apart from one that now exists on disk.\n\nThe envelope reports the short form (the first 8 characters) it has\nalways reported; this is the same id, unabbreviated.",
          "type": "string"
        },
        "model": {
          "description": "The model this run dispatches to, as the envelope reports it.",
          "type": "string"
        },
        "cwd": {
          "description": "The project root the run's tools are confined to, absolute. `null` for\na caller that built the run's arguments without one -- every CLI run\nresolves a root before the run starts -- so the field never names a\ndirectory that is not the one the tools are confined to.",
          "type": [
            "string",
            "null"
          ]
        },
        "tools": {
          "description": "The tool names this run advertises, in the order the request carries\nthem. Order matters to the consumer: it is the prefix of the request a\nprovider caches on, so a set that reorders between runs is a cache miss\n(see the tool-ordering note in `upstream.rs`).",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tool_specs": {
          "description": "The full schemas of the host tools this run advertises. A host compares\nthese against what it declared, which is the only way to know its\nconstraints survived rather than trusting that they did; the names in\n`tools` alone cannot answer that.\n\nThis is the advertised subset, not everything declared: a deny list, an\nallowlist or Plan mode can withhold a host tool, and its absence here is\nhow a host learns that happened. Omitted entirely when the run\nadvertises no host tools, so an ordinary run's handshake is unchanged.",
          "type": "array",
          "items": true
        },
        "input_kinds": {
          "description": "What `--input-format stream-json` accepts from this client, as message\n`type` tags. Empty when the run does not read stdin at all, which is\nthe honest answer for a read-only stream: nothing can be sent back.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "input_content_parts": {
          "description": "The content-part form of the `user` message, when this run accepts it:\nthe caps a client must stay inside and the image types it may send.\n`null` when the run reads no stdin -- there is no channel to describe --\nwhich is also why this is additively separate from `input_kinds`: a\nclient that reads only the kinds still learns `user`, and one that\nnegotiates the caps gets them from the same record.",
          "anyOf": [
            {
              "$ref": "#/$defs/InputContentParts"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "type",
        "protocol_version",
        "session_id",
        "model",
        "tools",
        "input_kinds"
      ]
    },
    "InputContentParts": {
      "description": "The caps on a content-part array -- a `user` message's, and a `tool_result`'s,\nwhich is held to the same limits -- as `init` advertises them.\n\nA client that sends an image is sending bytes into a channel with no\nbackpressure, so the limits are part of the handshake rather than something\nto discover by being rejected. Each is the cap the parser enforces: this is\nthe same constant, not a copy of it.",
      "type": "object",
      "properties": {
        "mime_types": {
          "description": "The image types an `image_url` part may name, as MIME types.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "max_image_bytes": {
          "description": "Most decoded bytes one image may carry.",
          "type": "integer",
          "format": "uint",
          "minimum": 0
        },
        "max_message_image_bytes": {
          "description": "Most decoded bytes across the images of one message.",
          "type": "integer",
          "format": "uint",
          "minimum": 0
        },
        "max_images": {
          "description": "Most images one message may carry.",
          "type": "integer",
          "format": "uint",
          "minimum": 0
        },
        "max_line_bytes": {
          "description": "Most bytes one input line may occupy. Applies to every kind, not just\n`user`: the cap is the reader's, before anything is parsed.",
          "type": "integer",
          "format": "uint",
          "minimum": 0
        },
        "max_echo_bytes": {
          "description": "Most bytes of a rejected line `input_error` echoes back.",
          "type": "integer",
          "format": "uint",
          "minimum": 0
        }
      },
      "required": [
        "mime_types",
        "max_image_bytes",
        "max_message_image_bytes",
        "max_images",
        "max_line_bytes",
        "max_echo_bytes"
      ]
    },
    "RunResult": {
      "description": "The envelope itself. A struct rather than a `json!` literal so the fields\nserialize in declaration order: `serde_json`'s map is sorted, which would\nprint this contract alphabetically and bury `result` in the middle.",
      "type": "object",
      "properties": {
        "type": {
          "description": "The record's tag. A consumer switches on it, so the schema states the\nvalue rather than leaving it an open string.",
          "type": "string",
          "const": "result"
        },
        "protocol_version": {
          "description": "The same contract version `init` carries, so a `--output-format json`\ncaller -- which never sees an init record -- can still pin what it is\nreading. Additive: a consumer that does not know the field ignores it.",
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        },
        "is_error": {
          "type": "boolean"
        },
        "result": {
          "type": "string"
        },
        "stop_reason": {
          "type": "string"
        },
        "error": {
          "anyOf": [
            {
              "$ref": "#/$defs/RunError"
            },
            {
              "type": "null"
            }
          ]
        },
        "session_id": {
          "description": "`null` when nothing was persisted, which is any run that failed before\nproducing a completion: there is no session to resume.",
          "type": [
            "string",
            "null"
          ]
        },
        "model": {
          "type": "string"
        },
        "num_turns": {
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        },
        "duration_ms": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "usage": {
          "$ref": "#/$defs/ReportUsage"
        }
      },
      "required": [
        "type",
        "protocol_version",
        "is_error",
        "result",
        "stop_reason",
        "model",
        "num_turns",
        "duration_ms",
        "usage"
      ]
    },
    "RunError": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ]
    },
    "ReportUsage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "completion_tokens": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "total_tokens": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0
        },
        "cached_tokens": {
          "description": "`null` on a route that reports no cache fields at all; `0` when it\nreported zero reads. Piped consumers branch on the difference.",
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "cache_write_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0
        },
        "estimated_cost_usd": {
          "type": [
            "number",
            "null"
          ],
          "format": "double"
        },
        "execution_ids": {
          "description": "Provider execution ids for the requests this run made, when the upstream\nreturned them. `jan usage generation <id>` turns one into the recorded\ncharge -- the authoritative counterpart to `estimated_cost_usd`. Omitted\nrather than empty when none were reported, so its absence is never read\nas \"no requests were made\".",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ]
    },
    "PermissionDecisionRecord": {
      "description": "How the CLI answered a [`StreamEvent::PermissionRequest`]. The loop does not\nemit this: the decision is made here, and without it a piped consumer sees\nthe request and never learns that the run was denied.",
      "type": "object",
      "properties": {
        "type": {
          "description": "The record's tag. A consumer switches on it, so the schema states the\nvalue rather than leaving it an open string.",
          "type": "string",
          "const": "permission_decision"
        },
        "request_id": {
          "type": "string"
        },
        "decision": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "request_id",
        "decision"
      ]
    },
    "InputErrorRecord": {
      "description": "A rejected input line, reported on stdout. Deliberately *not* a\n[`StreamEvent::Error`](crate::core::agent::events::StreamEvent::Error): the\nreport folds that into the run's outcome, so a typo in one line would mark\nan otherwise successful run as failed.",
      "type": "object",
      "properties": {
        "type": {
          "description": "The record's tag. A consumer switches on it, so the schema states the\nvalue rather than leaving it an open string.",
          "type": "string",
          "const": "input_error"
        },
        "message": {
          "type": "string"
        },
        "line": {
          "description": "The line that was rejected, so the client can match it to what it wrote.\nTruncated to [`MAX_ECHO_BYTES`], because a rejected line may be as large\nas [`MAX_LINE_BYTES`] and echoing it whole would hand the client back the\ncost the cap just removed.",
          "type": "string"
        },
        "line_truncated": {
          "description": "True when `line` is a prefix of what the client sent, so a client that\nmatches on the echo knows why it is short.",
          "type": "boolean"
        }
      },
      "required": [
        "type",
        "message",
        "line",
        "line_truncated"
      ]
    },
    "InputLine": {
      "description": "One input line, as the wire shape: the [`INPUT_KINDS`], with the fields\neach carries. The wire shape is a serde type rather than a hand-rolled walk\nover a `Value` so the protocol schema can be derived from it -- `jan cli\nagent schema` publishes this shape, and a hand-written copy of it would be\ncorrect only until the parser moved.\n\nThe `type` field is read separately, before deserializing: an unknown kind is\nreported against [`INPUT_KINDS`], which is the list `init` advertises.",
      "oneOf": [
        {
          "description": "A follow-up turn for the run in flight: `text`, or `content` as an\nOpenAI content-part array. Exactly one of the two, which JSON Schema\ncannot state, so the doc says it and the parser enforces it. A\ncontent-part message carries text parts and `image_url` parts, whose URL\nis a base64 `data:` URL -- the run shares no filesystem with a client.",
          "type": "object",
          "properties": {
            "text": {
              "type": [
                "string",
                "null"
              ]
            },
            "content": {
              "type": [
                "array",
                "null"
              ],
              "items": true
            },
            "type": {
              "type": "string",
              "const": "user"
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "description": "Stop the run; the terminal envelope still reports what it had produced.",
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "abort"
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "description": "The answer to a `permission_request` this run emitted.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "decision": {
              "$ref": "#/$defs/InputDecision"
            },
            "type": {
              "type": "string",
              "const": "permission"
            }
          },
          "required": [
            "type",
            "request_id",
            "decision"
          ]
        },
        {
          "description": "The answer to a `tool_request` this run emitted: the host executed the\ntool and this is its result, which becomes the model's tool message.\n\n`content` is required even for a failure. A tool message with nothing in\nit tells the model only that something happened, which is worse than a\nshort error. It is either a string or an OpenAI content-part array\n(`text` and `image_url` parts, under the same caps as a `user` message),\nso a camera can hand the model a frame.\n\n`details` is any JSON object the host wants a display to have. It is\nnever sent to the model: the run echoes it as a `tool_details` record\nafter the `tool_result`, and that is all.",
          "type": "object",
          "properties": {
            "request_id": {
              "type": "string"
            },
            "content": {
              "$ref": "#/$defs/ToolResultContent"
            },
            "is_error": {
              "type": "boolean",
              "default": false
            },
            "details": {
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": true
            },
            "type": {
              "type": "string",
              "const": "tool_result"
            }
          },
          "required": [
            "type",
            "request_id",
            "content"
          ]
        }
      ]
    },
    "InputDecision": {
      "description": "The decisions a client may answer a `permission_request` with: the wire\nvocabulary, which [`parse_input_line`] maps onto the tool gate's own enum.",
      "type": "string",
      "enum": [
        "allow_once",
        "allow_always",
        "deny"
      ]
    },
    "ToolResultContent": {
      "description": "A `tool_result`'s `content`: a plain string, or a content-part array.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": true
        }
      ]
    }
  },
  "x-protocol-version": 1
}