Embed with RPC
yuke --rpc serves the yuke protocol on stdin and stdout. Your app starts yuke as a child process, sends initialize, and then sends requests and reads updates. Each message is one line of JSON-RPC 2.0. The server ends when its stdin ends.
The messages take conventions of the Agent Client Protocol (ACP): "jsonrpc": "2.0", noun/verb methods, and camelCase fields. The protocol is not ACP: for example, it has session/input in place of session/prompt, and a tool update uses a saved call position rather than a provider call id.
This guide is the reference of the protocol: the transports, the requests, the updates, and their fields. The TypeScript types of the messages are in ~/.local/lib/yuke/protocol/bindings/. The source of the types and of the bindings is crates/protocol.
Plugins load in this mode without the tui service.
Transports
| Command | Behavior |
|---|---|
yuke --rpc | Serve the protocol on stdin and stdout. |
yuke --rpc --listen unix://PATH | Serve the clients of a Unix socket, one at a time. The sessions outlive each client. |
yuke --rpc --connect unix://PATH | Join stdin and stdout to the server of a Unix socket. |
- Each message is one line. The end of stdin ends the server.
- A server on a socket keeps the sessions, turns, and jobs when a client leaves.
- A new client of the socket replaces the active client. The socket has mode 0600, so each process of the user can connect. The server holds
PATH.lock, so a second server on the path fails. - SIGINT, SIGTERM, and SIGHUP end the server. The active client gets the updates of the shutdown.
- Each type holds one message. The protocol has no batches: a line that is no JSON object gets -32600.
- A notice that comes while no client is connected goes to stderr. The server drops the session updates and the extension events of that interval. The store keeps the saved events, and
session/loadsends them again.
Messages
- Each connection starts with
initialize. ItsinstanceIdis the id of the server process. A client that reconnects and gets another id talks to a new process, so the turns and jobs of the old process are gone. The client then loads each session again. - Requests:
initialize,session/new,session/fork,session/load,session/close,session/input,session/removeInput,session/setSettings,session/rename,session/list,session/get,session/remove,auth/login,auth/cancelLogin,auth/logout,auth/setApiKey,catalog/list,job/list,job/stop,credential/update,interaction/respond,mcp/list,plugin/list,plugin/sync,plugin/check,plugin/apply,plugin/find,plugin/add,plugin/remove,profile/reload,blob/put,blob/get. - Notifications from a client:
session/cancelandsession/background.session/backgroundmoves each tool call of the session that waits for a job, such as a running command, to the background, and the turn goes on. - Notifications from the server:
session/update,notice,extension/event,extension/cancel, andauth/loginFinished. - Server requests:
extension/request. A client answers each one. It answers -32601 for a method or an extension that it does not know. The server numbers its requests from 1, apart from the ids of the client. noticeis text for the user, for the whole process or one session. It is not part of session history.profile/reloadloads the plugins ofconfig.jsonand the providers ofproviders.jsonagain. The open sessions stay open. Their process jobs go on, and their plugin jobs stop. It fails while a turn runs, or for a badconfig.json,plugins.lock, orproviders.json. A failure keeps the old plugins and providers. A plugin that does not load does not fail it, and anoticenames it. The next request of an open session can miss the prompt cache when the reload changes its tools.
Sessions
- A session is open after
session/new,session/fork, orsession/load, untilsession/closeor the shutdown of the server. Many sessions can be open at once. The requests that use a live session need an open session, andsession/loadopens a closed one. A plugin can open a session too. A session that no client and no plugin holds closes by itself when it runs no turn: after 30 seconds, or aftersessionIdleMinutesofconfig.jsonwhile a job runs. That close stops its jobs. - A session row holds the facts of the session (
sessionId,model,folder,title?,createdAt,updatedAt,forkOf?,parent?) and itsstatenow:closed,idle, orrunning.session/getgives the row of one session. - A text message or an explicit rename supplies the title. Initial message text normalizes whitespace and truncates the title to 200 Unicode scalar values.
session/rename { sessionId, title }changes the title of an open or closed session and answers{}without a session update. session/newcan name aparent, and each row of the session then holds thatparent. Asession/listwithoutparentshows only the sessions without a parent. Asession/listwithparentshows the children of that session. Asession/removeremoves the children and their children too, and it fails while one of these sessions is open. A fork has no parent. A fork starts with the titleFork — <source title>when the source has a title, bounded to 200 Unicode scalar values. A fork without a source title has no title until its first message.session/listgives the saved sessions in pages, newest event first, of every folder or of onefolder. A page has 50 rows, orlimitfrom 1 to 100. ItsnextCursoris an opaque text that continues the same list. The pages are no snapshot: a session that moves to the front between two pages comes only in a new list.session/removedeletes a saved session with its events, pending inputs, and blobs. Its forks stay. It fails for an open session, so a client closes it first withsession/close. That method stops the turn and the jobs. A removal fails with -32003 while another writer holds the session.- The settings of a session (model, request settings, folder) do not change during a turn:
session/setSettingsfails while a turn runs or input waits. blob/put { sessionId, data }decodes the base64dataand saves the bytes in a saved session. It answers the blob{ digest, len }for a media block of an input.blob/get { sessionId, blob }answers the bytes as base64{ data }, also for a closed session. It reads the blob by its digest, and fails with -32007 when the session has no such blob.session/removedeletes the blobs.session/loadsends the session as updates: the saved events, astateupdate, aninputAcceptedfor each pending input, ajobupdate for each running job, aninteractionRequestedfor each open question, and anmcpServerupdate for each MCP server. Then come the live updates of the load time that these do not hold, and the empty answer. A client applies the updates in order. It drops a saved event that it has (byseq), aninputAcceptedthat it has (byinputId), and aninteractionRequestedthat it has (byinteractionId). The server disconnects a client that falls behind. On stdin and stdout, that ends the server. On a socket, the client connects and loads again.
Turns and updates
session/inputstarts a turn when the session is idle. During a turn, an input joins the turn at its next round. Astateupdate tells when a turn runs.session/loadstarts no turn.- During a turn, a client can add and remove inputs, cancel the turn, move its waiting tool calls to the background, close the session, and list and stop jobs.
session/updatecarries a saved event with its event number (seq), or a live update of a running turn.- The queue:
inputAcceptedandinputRemovedare live updates. A queued input leaves the queue when a saved commit names it inconsumed, or wheninputRemovednames it. - Live model updates belong to a draft and retain native block ids and boundaries. They exclude provider replay state.
draftCommittedcarries oneeventNumberand an array of original draft block ids, in saved block order. Array indeximaps to block indexiin that commit. A client replaces the whole draft.draftDiscardedremoves a draft without a confirmed replacement. It never removes saved history.turnUnconfirmeddiscards provisional tool state when the turn has no confirmed terminal commit. Reload the journal. Before the next turn, the server ends a turn that the store holds as open, and sends that commit as a saved event.- Tool updates use
{ eventNumber, blockIndex }within the enclosing session. The position names the saved call block. - Saved commits still contain model context data. A visible-history projection is separate from that raw journal.
- After a cancelled or failed turn, the next turn gets a notification from
host:sessionafter its other inputs.
Inputs
- An input has a source:
user, or apluginwith a name. The inputs of yuke itself use names that start withhost:. - An input has a kind:
messagefor a text of a person, ornotificationfor a notice that no person wrote. A client shows a notification as a notice. The model reads a notification in<system_notification plugin="name">. - An input holds the content that the user saw. It holds model content only when the model reads other blocks.
- A saved commit starts with the model blocks of its consumed inputs.
consumedgives the id, the source, the kind, and the block count of each input. It gives the content that the user saw only when that content differs.
Questions
A plugin or yuke asks the user with an interactionRequested live update: a questions request with its source. Each question has options, other for a typed answer, or both. The client answers all questions at once with interaction/respond, or cancels the whole request with cancelled. An answer that does not fit its questions, or an unknown id, fails the request. An interactionClosed update ends each request: an answer, an abort of the asker, or the close of the session. A run without a client (yuke -p) answers each request with no answer.
Jobs
The background jobs of a session run while the session is open. job/list lists them. A job update holds the whole job at its start and at its end. job/stop waits for the end, and its job update comes first. session/close stops the jobs of the session. A client that wants a warning first reads job/list. A process job that ends by itself also sends an input from host:jobs, after its job update. A plugin job sends an input from its plugin only when the plugin ends it with a report. The state of a job is running, ended, or stopped. Its kind is process (command, log, exitCode) or plugin (plugin).
Credentials and models
auth/login { provider }starts the device login of a provider with a login flow, and answers itsloginId,verificationUrl, anduserCodeat once. A login in progress of the provider ends ascancelledfirst. The client shows the page and the code. The server polls the provider, saves the login inauth.json, and sendsauth/loginFinished { loginId, provider, outcome }:succeeded,cancelled, orfailed { error }.auth/cancelLogin { loginId }asks a login in progress to stop. A poll that got the approval still saves the login, so the outcome tells what happened. A client that missed the notification, for example after a reconnect, reads the state withcatalog/list. No answer and no notification holds a token.auth/logout { provider }removes what yuke stored for a provider: its login or its API key inauth.json, and the token ofcredential/update. A login in progress of the provider ends first, and the removal comes after it. yuke revokes no token at the provider.yuke logout PROVIDERchangesauth.jsononly: a running server keeps a token ofcredential/update.auth/setApiKey { provider, apiKey }stores the key inauth.jsonfor a provider with an API key variable. The new key replaces the stored key and wins over the variable. Each session takes the key at its next turn.credential/updategives the server anaccessTokenfor a provider with a login flow. An orchestrator can refresh one account and update many servers. The server keeps the token only in memory and never refreshes it. It uses the token from the next model request on, also in a running turn. After the first update, the server never uses the stored login of the provider.catalog/listgives the providers that are ready now, or every provider withall: true. Each provider has its state (readywith its credential,needsApiKeywith the variable, orneedsLogin) and its models: limits, prices, tool support, input kinds, and the reasoning choices with the reasoning settings that a session sends for each. A provider is ready when its API key variable holds UTF-8 text that is not empty, when it has a stored key, a login, or a pushed token, or when it needs no key. The server does not test the credential. A client asks again afterprofile/reload.
Plugins
plugin/listgives each plugin ofconfig.jsonwith itssource, itsstateon disk, and itsload. Thesourceis the folder text of a local plugin, or the{ git, folder?, ref? }object of a Git plugin. Thestatekind islocal,notInstalledwith thecommit?of the lock, orinstalledwith itscommit. Theloadkind isloaded,pendinguntil the nextprofile/reload, orfailedwith itserror. It uses no network.plugin/syncinstalls the commits ofplugins.lockand locks each new Git plugin at the commit of its ref.plugin/check { target }takes{ "kind": "all" }or{ "kind": "names", "names": [...] }. It installs each new commit of an installed Git plugin, and answers thechangeswith theirlog. It checks the others, and answers each plugin that it cannot check infailedwith itserror.plugin/apply { plugins }writes the{ source, commit }of each plugin intoplugins.lock. It fails for a plugin that the lock does not have.plugin/find { git, ref? }answers thepluginsof a repository: thenameand thefolder?of eachplugin.json.plugin/add { git, names?, ref? }adds those plugins toconfig.jsonby name, installs them, and locks them. It answers each one with itsname,source, andcommit. Withoutnames, the repository must have one plugin.plugin/remove { name }removes a plugin fromconfig.jsonandplugins.lock.- Each edit keeps the comments of
config.json. Git never asks for a password, so a private repository needs a credential helper or an ssh agent. A new commit loads atprofile/reload.
Plugin events and requests
extension/eventis an event of a plugin, for the whole process or one session.extensionis the name that the host gives the plugin. The plugin chooseseventanddata, and it puts a version indatawhen the shape changes. A client ignores an extension that it does not know. The event is not part of session history, andsession/loaddoes not send it again. The events and notices of the plugins keep their order, but they have no order against the session updates.extension/request { sessionId, extension, request, data }is a request of a plugin to the active client. The plugin choosesrequestanddata, and the client chooses the result or the error. With no client, the request fails at once in the plugin. A new client or a disconnect fails each request that waits, and no client gets it again. The server sets no time limit. The request has no order against the events, the notices, and the session updates.extension/cancel { requestId }tells the client that the plugin stopped waiting: a cancel of the plugin or the close of its session. The client can stop its work. Its answer is optional, and the server ignores it. An answer and a cancel can cross, so a client ignores a cancel of a request that it answered.
MCP servers
Each open session runs the servers of the user config and of .mcp.json in its folder. An mcpServer live update holds the whole state of one server, with its source (user or project). Its state has the kind connecting, connected with its tool count, failed with its error, disabled, or untrusted. mcp/list gives each server of a session.
Project servers start only after the user confirms them. yuke asks one question from host:mcp, with the options "Start" and "Don't start", and keeps a start for that folder and that list of servers. See MCP servers.
Shapes
- A union of objects has the tag
kind, as in{ "kind": "userText", "text": "hi" }. Only a union of a text and an object, as thesourceof a plugin, has no tag. - Each method, field, tag value, and enum value is camelCase. A method is
noun/verb, as insession/setSettings. - A failure is the kind
failedwith the texterror. - An absent field is left out. No value is
null, apart from theidof a response to a message without a readable id, as JSON-RPC asks. - A flag whose absence means
falseis left out when it isfalse. - A time is in milliseconds since the Unix epoch, and its name ends in
At(createdAt,expiresAt). A duration names its unit (durationMs,afterMs).
Errors
A request fails with one of these codes. The message is text for a person, and a client does not parse it.
| Code | Constant | Meaning |
|---|---|---|
| -32700 | PARSE_ERROR | The line is no JSON. |
| -32600 | INVALID_REQUEST | The message is no JSON object, or it has no valid jsonrpc, id, or method. |
| -32601 | METHOD_NOT_FOUND | The server has no such method. |
| -32602 | INVALID_PARAMS | The params do not fit the method, or a value of them cannot work. |
| -32603 | INTERNAL_ERROR | The server failed. |
| -32002 | SESSION_NOT_FOUND | The session is not open, or the store has no such session. |
| -32003 | SESSION_OWNED | Another writer holds the session. |
| -32004 | JOB_NOT_FOUND | The session runs no such job. |
| -32005 | INTERACTION_NOT_FOUND | The session has no such open question. |
| -32006 | LOGIN_NOT_FOUND | No such login is in progress. |
| -32007 | BLOB_NOT_FOUND | The session has no blob with this digest. |
| -32008 | SESSION_OPEN | The session is open, so it cannot be removed. Close it first. |
| -32009 | TURN_ACTIVE | A turn runs or input waits. Send the request again after the turn ends. |
| -32010 | TRY_AGAIN | Another call opens or closes the session, or a reload runs. Send the request again after it ends. |
| -32011 | STOPPING | The server shuts down. |
| -32012 | NOT_INITIALIZED | The connection sent no initialize yet. |
Compatibility
- A client ignores each field, kind, method, notification, and error code that it does not know.
- A new field, kind, method, notification, or error code does not change
PROTOCOL_VERSION. - A removal, a rename, or a change of the meaning or the type of an existing item increases
PROTOCOL_VERSION. initializegives the version that the server selects. A client that does not speak that version disconnects.