Skip to content
Website ↗

Initialize a daemon connection ​

After opening a Codant daemon connection, send daemon/initialize as a JSON-RPC 2.0 request with a non-empty string ID. Wait for a successful response with the same ID. On stdio, encode each request as one UTF-8 JSON line terminated by LF. The daemon rejects other requests with IDs until initialization succeeds. See packages/api/src/connection.ts and packages/api/test/protocol.test.ts. Protocol schema source

Request ​

This handshake uses baseline protocol 0.1. Initialization succeeds once per connection. Initialize each new connection separately. Until the handshake has succeeded, you can correct the parameters or try another version supported by your client. See packages/api/src/protocol-initialization.ts and packages/api/test/protocol.test.ts.

json
{"jsonrpc":"2.0","id":"init","method":"daemon/initialize","params":{"protocolVersion":"0.1"}}

Successful response ​

A successful response echoes the request id and places these fields in result. protocolVersion is the request version accepted by the daemon. See initializeResponseSchema and ConnectionProtocol.initialize in packages/api/src/protocol-initialization.ts.

FieldMeaning
protocolVersionThe protocol version for this connection, 0.1 in the example.
serverVersionThe software version reported by the daemon. The current implementation sets SERVER_VERSION to 0.0.1.
instanceIdThe daemon instance identifier. Calling daemon/ping on the same daemon returns the same identifier.
capabilitiesThe identifiers advertised on this connection, including callable methods and notification names such as session/event.

Use the advertised capabilities to enable features, and check the request shape for the version you use. The capability list depends on the accepted version and available server features. For example, the baseline response omits skills/list and skills/toggle when the skills runtime is unavailable. For versions with optional negotiation fields, send only combinations your client understands. See capabilitiesForProtocol and ConnectionProtocol.initialize in packages/api/src/protocol-initialization.ts and the skills capability assertions in packages/api/test/protocol.test.ts.

If the reply advertises daemon/ping, send the following request and compare the returned instanceId. Its parameters are the empty object {} and its result has the shape { "instanceId": "…" }. See packages/api/src/daemon-lifecycle-rpc.ts and packages/cli/test/bridge-cli.test.ts.

json
{"jsonrpc":"2.0","id":"ping","method":"daemon/ping","params":{}}

Errors and recovery ​

An error response contains an integer error.code, an error.message, and optional error.data. Errors for valid requests normally echo the request ID. Parse errors and invalid requests use id: null. The table covers initialization and the follow-up calls in this example. See packages/api/src/protocol.ts, packages/api/src/connection.ts, packages/api/src/protocol-initialization.ts, and packages/api/test/protocol.test.ts.

CodeMeaning in this flow
-32700The line could not be parsed as JSON.
-32600The request envelope fails the Codant schema, for example a batch array or a numeric ID.
-32601The requested method was not found.
-32602The request parameters are invalid.
-32001During initialization, the requested version is unsupported or an explicitly requested optional feature is unavailable.
-32002The daemon rejected a follow-up request because the connection is still uninitialized.
-32003During initialization, the connection had already completed a successful handshake.

After -32001 or -32602, an uninitialized connection can retry with a version and parameters supported by the client. Continue only after a successful response. A daemon/initialize frame without an ID is treated as a notification and ignored. If the handshake deadline expires, the daemon closes the connection and you must open a new one. See packages/api/src/protocol-initialization.ts, packages/api/src/connection.ts, and packages/api/test/protocol.test.ts.