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.

52.4 KB
Raw Blame
{
  "protocol_version": 1,
  "envelope": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "RpcEnvelope",
    "type": "object",
    "properties": {
      "jsonrpc": {
        "type": "string"
      },
      "id": true,
      "method": {
        "type": "string"
      },
      "params": true
    },
    "required": [
      "jsonrpc",
      "method"
    ]
  },
  "requests": {
    "initialize": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "InitializeParams",
      "type": "object",
      "properties": {
        "protocolVersion": {
          "type": "integer",
          "format": "uint32",
          "minimum": 0
        },
        "clientInfo": {
          "$ref": "#/$defs/ClientInfo"
        },
        "capabilities": {
          "default": null
        }
      },
      "additionalProperties": false,
      "required": [
        "protocolVersion",
        "clientInfo"
      ],
      "$defs": {
        "ClientInfo": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "name",
            "version"
          ]
        }
      }
    },
    "session/list": {
      "type": "object",
      "properties": {}
    },
    "session/start": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionStartParams",
      "type": "object",
      "properties": {
        "cwd": {
          "type": "string"
        },
        "model": {
          "type": [
            "string",
            "null"
          ]
        },
        "ephemeral": {
          "type": "boolean",
          "default": false
        },
        "tools": {
          "description": "Host tools this session may call. Kept as raw values until declaration\nso a malformed entry is reported as `invalid_tools` with the reason,\nrather than as a generic params error that names nothing.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/HostToolDeclSchema"
          },
          "default": []
        },
        "builtins": {
          "description": "`false` advertises only the host tools: no built-ins, MCP, plugin,\n`ask`, `todo` or monitor tools. `subagents: true` adds back only\n`dispatch_subagent`, `list_subagents`, `message_subagent` and\n`stop_subagent`.",
          "type": "boolean",
          "default": true
        },
        "subagents": {
          "description": "Whether the session may delegate to subagents; defaults to `builtins`.\nWith `builtins: false` it adds only `dispatch_subagent`,\n`list_subagents`, `message_subagent` and `stop_subagent`, and every\nchild is held to the session's host tools.\n`false` withholds subagent tools even from a session with built-ins.",
          "type": [
            "boolean",
            "null"
          ],
          "default": null
        },
        "systemPrompt": {
          "description": "The session's whole system prompt, sent byte for byte in place of the\none Jan composes: no Jan identity, guides, environment, date, git state\nor recalled project memory. Its answers are still indexed for later\nsessions unless it is `ephemeral`. Jan may still append runtime notices\nto the conversation.\nChildren keep their own prompts.",
          "type": [
            "string",
            "null"
          ],
          "default": null
        },
        "permissions": {
          "$ref": "#/$defs/PermissionOwner",
          "default": "jan"
        }
      },
      "additionalProperties": false,
      "required": [
        "cwd"
      ],
      "$defs": {
        "HostToolDeclSchema": {
          "description": "The declaration shape, for the document only: the dispatcher parses the\nreal `HostToolDecl`, which lives outside this module and carries no schema.",
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string",
              "default": ""
            },
            "parameters": {
              "description": "JSON Schema for the arguments, advertised to the model verbatim.",
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": true,
              "default": null
            },
            "capability": {
              "anyOf": [
                {
                  "$ref": "#/$defs/HostCapability"
                },
                {
                  "type": "null"
                }
              ],
              "default": null
            }
          },
          "additionalProperties": false,
          "required": [
            "name"
          ]
        },
        "HostCapability": {
          "description": "What a host says a tool does, which decides how the loop treats it.\nAbsent means opaque: prompted unless `auto_approve`, sequential, withheld in\nPlan mode -- the plugin/MCP default.",
          "oneOf": [
            {
              "description": "Observes without side effects (a camera, a sensor): never prompted,\nadvertised in Plan mode, and run concurrently with other reads.",
              "type": "string",
              "const": "read"
            },
            {
              "description": "Acts on the world: prompted even under `auto_approve` unless the host\nowns the gate, run sequentially, withheld in Plan mode.",
              "type": "string",
              "const": "actuator"
            }
          ]
        },
        "PermissionOwner": {
          "description": "Who gates host tool calls. `jan` prompts through `permission_request` the\nway any opaque tool is prompted; `host` means the host's own callback is\nthe gate, so Jan never asks about a host tool.",
          "type": "string",
          "enum": [
            "jan",
            "host"
          ]
        }
      }
    },
    "session/resume": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    },
    "session/fork": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    },
    "session/archive": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    },
    "turn/start": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "TurnStartParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        },
        "input": true
      },
      "additionalProperties": false,
      "required": [
        "sessionId",
        "input"
      ]
    },
    "turn/steer": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "TurnSteerParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        },
        "input": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId",
        "input"
      ]
    },
    "turn/interrupt": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    },
    "permission/respond": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "PermissionResponseParams",
      "type": "object",
      "properties": {
        "requestId": {
          "type": "string"
        },
        "decision": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "requestId",
        "decision"
      ]
    },
    "tool/respond": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "ToolRespondParams",
      "type": "object",
      "properties": {
        "requestId": {
          "type": "string"
        },
        "content": {
          "$ref": "#/$defs/ToolResultContent"
        },
        "isError": {
          "type": "boolean",
          "default": false
        },
        "details": {
          "description": "Host/UI-only data, echoed as `item/tool_details` and never sent to the\nmodel.",
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true,
          "default": null
        }
      },
      "additionalProperties": false,
      "required": [
        "requestId",
        "content"
      ],
      "$defs": {
        "ToolResultContent": {
          "description": "A host tool's answer: text, or OpenAI content parts (`text` / `image_url`\nwith a base64 `data:` URL) under the same caps as a user message.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": true
            }
          ]
        }
      }
    },
    "session/tools/get": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    },
    "session/tools/set": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionToolsSetParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        },
        "tools": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/HostToolDeclSchema"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId",
        "tools"
      ],
      "$defs": {
        "HostToolDeclSchema": {
          "description": "The declaration shape, for the document only: the dispatcher parses the\nreal `HostToolDecl`, which lives outside this module and carries no schema.",
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string",
              "default": ""
            },
            "parameters": {
              "description": "JSON Schema for the arguments, advertised to the model verbatim.",
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": true,
              "default": null
            },
            "capability": {
              "anyOf": [
                {
                  "$ref": "#/$defs/HostCapability"
                },
                {
                  "type": "null"
                }
              ],
              "default": null
            }
          },
          "additionalProperties": false,
          "required": [
            "name"
          ]
        },
        "HostCapability": {
          "description": "What a host says a tool does, which decides how the loop treats it.\nAbsent means opaque: prompted unless `auto_approve`, sequential, withheld in\nPlan mode -- the plugin/MCP default.",
          "oneOf": [
            {
              "description": "Observes without side effects (a camera, a sensor): never prompted,\nadvertised in Plan mode, and run concurrently with other reads.",
              "type": "string",
              "const": "read"
            },
            {
              "description": "Acts on the world: prompted even under `auto_approve` unless the host\nowns the gate, run sequentially, withheld in Plan mode.",
              "type": "string",
              "const": "actuator"
            }
          ]
        }
      }
    },
    "session/model/set": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionModelSetParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        },
        "model": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId",
        "model"
      ]
    },
    "session/reset": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "SessionIdParams",
      "type": "object",
      "properties": {
        "sessionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "sessionId"
      ]
    }
  },
  "notifications": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "RpcNotification",
    "type": "object",
    "properties": {
      "jsonrpc": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "params": true
    },
    "required": [
      "jsonrpc",
      "method",
      "params"
    ]
  },
  "events": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "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": "#"
          },
          "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"
        ]
      }
    ],
    "$defs": {
      "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"
        ]
      }
    }
  }
}