Wraith.Kiro.ACP (Wraith v0.1.0)

View Source

Ported from shadow_corp. A client for the Agent Client Protocol — JSON-RPC 2.0 over WebSocket — as spoken by the Kiro Agent Server (KAS).

One process per connection. The owner (the process that called connect/2) receives everything the agent sends that is not a reply:

{:acp, pid, {:notification, method, params}}
{:acp, pid, {:request, id, method, params}}   # answer with respond/3
{:acp, pid, {:closed, reason}}

Replies to our own requests come back to the caller of request/4.

Two KAS facts baked in: over the WS transport every client is an observer, so (1) _kiro/auth/getAccessToken can never be satisfied by us — the credential lives in the VM — and (2) permission answers must go through _kiro/permission/respond (permit/3), a plain reply is dropped.

Summary

Functions

Answer (or dismiss with nil) a _kiro/userInput question.

Returns a specification to start this module under a supervisor.

Close a live session (it stays on disk; ensure_session re-hydrates it).

Open a WebSocket to url (ws:// or wss://). opts[:protocols] are Sec-WebSocket-Protocol values (MicroVM auth rides here), opts[:owner] defaults to the caller. Returns once the upgrade succeeded.

Create-or-load a session under a caller-chosen id (idempotent + overrideSessionId), with steering documents. extra carries e.g. %{customAgents: [agent], modeId: agent.id}.

Fire a notification (no reply expected).

Grant/deny a session/request_permission the observer way.

Send a request and wait for the reply (result or error).

Switch a session's agent (mode): a reopened session keeps the one it was saved with otherwise.

A steering note into a session: _session/steer (a persisted user-style message).

Types

conn()

@type conn() :: pid()

Functions

answer_question(conn, tool_call_id, answer)

Answer (or dismiss with nil) a _kiro/userInput question.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close_session(conn, session_id)

Close a live session (it stays on disk; ensure_session re-hydrates it).

connect(url, opts \\ [])

@spec connect(String.t(), keyword()) :: {:ok, conn()} | {:error, term()}

Open a WebSocket to url (ws:// or wss://). opts[:protocols] are Sec-WebSocket-Protocol values (MicroVM auth rides here), opts[:owner] defaults to the caller. Returns once the upgrade succeeded.

ensure_session(conn, session_id, cwd, steering \\ [], extra \\ %{})

Create-or-load a session under a caller-chosen id (idempotent + overrideSessionId), with steering documents. extra carries e.g. %{customAgents: [agent], modeId: agent.id}.

notify(conn, method, params)

Fire a notification (no reply expected).

permit(conn, tool_call_id, option_id)

Grant/deny a session/request_permission the observer way.

request(conn, method, params, timeout \\ 60000)

@spec request(conn(), String.t(), map(), timeout()) ::
  {:ok, map()} | {:error, map() | term()}

Send a request and wait for the reply (result or error).

set_mode(conn, session_id, mode_id)

Switch a session's agent (mode): a reopened session keeps the one it was saved with otherwise.

steer(conn, session_id, message)

A steering note into a session: _session/steer (a persisted user-style message).