README

colmugx/acp/agent does not have a README file

#
AgentAuthenticateHandler

Typed async authentication handlers.

#
AgentCancelHandler

type AgentCancelHandler = async (AgentContext,
CancelParams
) -> Unit

#
AgentContextNotificationBroker

type AgentContextNotificationBroker = async (
ClientNotification
) -> Result[Unit, AgentContextError]

The notification-side composition seam. Notifications have no response value, so success is represented only by Unit.

#
AgentContextRequestBroker

The request-side composition seam. It is a one-shot broker, not a queue or a mutable registry; connection state remains owned by the runtime.

#
AgentLoadSessionHandler

Typed async handler signatures for optional session operations.

#
AgentNewSessionHandler

Typed async handler signatures for the required session operations.

#
AgentAdapterError

pub(all) suberror AgentAdapterError {
EndpointMismatch(reason~ : String)
UnexpectedMessage(kind~ : String)
LateCompletion(request_id~ :
RequestId
)
CompletionMismatch(method_name~ : String)
} derive(Eq,
Debug
)

Fail-fast adapter failures indicate an invalid composition boundary or a completion that no longer belongs to the owner-held reservation.

#
AgentContextError

pub(all) suberror AgentContextError {
AgentContextUnavailable(method_name~ : String)
AgentContextCancelled(method_name~ : String)
AgentContextBrokerFailure(method_name~ : String)
AgentContextReplyMismatch(method_name~ : String)
} derive(Eq,
Debug
)

Failures crossing an Agent-to-Client context port. Runtime adapters may construct these values from negotiated capability gates or transport cancellation, while application code never handles untyped JSON here.

#
AgentAdapterAdmission

pub(all) enum AgentAdapterAdmission {
Immediate(AgentAdapterStep)
Invoke(state~ : AgentAdapterState, invocation~ : AgentAdapterInvocation)
}

Admission is synchronous and owner-loop controlled. Initialize and protocol errors are immediate; only typed invocations cross the async task boundary.

#
AgentAdapterCommand

pub(all) enum AgentAdapterCommand {
CancelRequest(request_id~ :
RequestId
)
TraceError(method_name~ : String, error~ :
JsonRpcError
)
CloseConnection(reason~ : String)
} derive(Eq,
Debug
)

Runtime-facing commands emitted by the Agent adapter. These values are intents only; the adapter never owns tasks, queues, or connection state.

#
AgentAdapterCompletion

pub(all) enum AgentAdapterCompletion {
AuthenticateCompleted(id~ :
RequestId
, result~ : Result[
AuthenticateResult
,
HandlerError
])
LogoutCompleted(id~ :
RequestId
, result~ : Result[
LogoutResult
,
HandlerError
])
SessionNewCompleted(id~ :
RequestId
, result~ : Result[
NewSessionResult
,
HandlerError
])
SessionLoadCompleted(id~ :
RequestId
, result~ : Result[
LoadSessionResult
,
HandlerError
])
SessionResumeCompleted(id~ :
RequestId
, result~ : Result[
ResumeSessionResult
,
HandlerError
])
SessionListCompleted(id~ :
RequestId
, result~ : Result[
ListSessionsResult
,
HandlerError
])
SessionDeleteCompleted(id~ :
RequestId
, result~ : Result[
DeleteSessionResult
,
HandlerError
])
SessionCloseCompleted(id~ :
RequestId
, result~ : Result[
CloseSessionResult
,
HandlerError
])
SessionSetModeCompleted(id~ :
RequestId
, result~ : Result[
SetSessionModeResult
,
HandlerError
])
SessionSetConfigOptionCompleted(id~ :
RequestId
, result~ : Result[
SetSessionConfigOptionResult
,
HandlerError
])
SessionPromptCompleted(id~ :
RequestId
, result~ : Result[
PromptResult
,
HandlerError
])
SessionCancelCompleted(result~ : Result[Unit,
HandlerError
])
} derive(Eq,
Debug
)

The result of one typed handler invocation. No wire response is produced here: the owner loop serializes this completion through agent_adapter_complete.

#
AgentAdapterInvocation

pub(all) enum AgentAdapterInvocation {
AuthenticateInvocation(id~ :
RequestId
, params~ :
AuthenticateParams
)
LogoutInvocation(id~ :
RequestId
, params~ :
LogoutParams
)
SessionNewInvocation(id~ :
RequestId
, params~ :
NewSessionParams
)
SessionLoadInvocation(id~ :
RequestId
, params~ :
LoadSessionParams
)
SessionResumeInvocation(id~ :
RequestId
, params~ :
ResumeSessionParams
)
SessionListInvocation(id~ :
RequestId
, params~ :
ListSessionsParams
)
SessionDeleteInvocation(id~ :
RequestId
, params~ :
DeleteSessionParams
)
SessionCloseInvocation(id~ :
RequestId
, params~ :
CloseSessionParams
)
SessionSetModeInvocation(id~ :
RequestId
, params~ :
SetSessionModeParams
)
SessionSetConfigOptionInvocation(id~ :
RequestId
, params~ :
SetSessionConfigOptionParams
)
SessionPromptInvocation(id~ :
RequestId
, params~ :
PromptParams
)
SessionCancelInvocation(params~ :
CancelParams
)
} derive(Eq,
Debug
)

A typed operation admitted by the Agent adapter. The operation carries only immutable protocol values; connection state is owned by the caller that admitted it.

#
AgentAdapterOutput

Typed adapter output. Responses and notifications are wire values that the owner loop serializes; commands are interpreted by the native runtime.

#
AgentAdapterReservation

pub(all) enum AgentAdapterReservation {
Idle
AuthenticatePending(
RequestId
)
LogoutPending(
RequestId
)
} derive(Eq,
Debug
)

Authentication/lifecycle reservations are immutable protocol state. A pending reservation prevents a second state-changing request from using a stale snapshot while its first handler is still running.

#
AgentAdapterState

State owned by the connection/reducer loop. Handler tasks receive a copy of this value only through an admission result; they never mutate it.

#
AgentAdapterState::reservation

#
AgentAdapterStep

pub(all) struct AgentAdapterStep {
state : AgentAdapterState
outputs : Array[AgentAdapterOutput]
} derive(Eq,
Debug
)

One explicit state transition produced by admission or completion.

#
AgentAuthService

Immutable authentication service. methods is copied and checked before the service can be used by an endpoint.

#
AgentContext

pub struct AgentContext {
request_broker : async (
ClientRequest
) -> Result[AgentOutboundReply, AgentContextError]
notification_broker : async (
ClientNotification
) -> Result[Unit, AgentContextError]
}

Opaque typed outbound context supplied to one Agent invocation. It owns only the two immutable broker closures; it contains no connection state, queue, task, global registry, or raw protocol value.

#
AgentContext::cancel_request

async fn AgentContext::cancel_request(self : AgentContext, request_id :
RequestId
) -> Unit raise AgentContextError

Request cancellation of one in-flight typed request. The runtime decides how to cancel the task; this facade only emits the typed notification.

#
AgentContext::elicitation_complete

Complete a typed elicitation notification. No response is synthesized.

#
AgentContext::elicitation_create

Create either form- or URL-mode elicitation using the stable union.

#
AgentContext::read_text_file

Read one absolute filesystem path through the negotiated Client service.

#
AgentContext::request_permission

Ask the Client for permission to execute a tool call.

#
AgentContext::session_update

Deliver a typed session update notification. No response is synthesized.

#
AgentContext::terminal_create

Create a terminal owned by the caller's Client runtime.

#
AgentContext::terminal_kill

Kill a typed terminal process.

#
AgentContext::terminal_output

Read accumulated output from a typed terminal handle.

#
AgentContext::terminal_release

Release a typed terminal handle.

#
AgentContext::terminal_wait_for_exit

Wait for a typed terminal to exit.

#
AgentContext::write_text_file

Write one absolute filesystem path through the negotiated Client service.

#
AgentEndpoint

An opaque, fully validated Agent endpoint. It contains immutable service closures and derived initialization data, never connection-scoped state.

#
AgentEndpoint::auth_methods

Return a defensive copy of the advertised authentication methods.

#
AgentEndpoint::cancel

Invoke the required typed session/cancel handler.

#
AgentEndpoint::capabilities

Return capabilities derived from service presence and support values.

#
AgentEndpoint::info

Return the immutable implementation information for initialization.

#
AgentEndpoint::prompt

Invoke the required typed session/prompt handler.

#
AgentOutboundReply

The closed set of typed results that a Client can return to an Agent.

Constructor names are deliberately prefixed so this facade cannot be confused with the corresponding wire request or endpoint constructors.

#
AgentSessionService

pub struct AgentSessionService {
new_handler : async (AgentContext,
NewSessionParams
) ->
NewSessionResult

prompt_handler : async (AgentContext,
PromptParams
) ->
PromptResult

cancel_handler : async (AgentContext,
CancelParams
) -> Unit
load_handler : async (AgentContext,
LoadSessionParams
) ->
LoadSessionResult
?
resume_handler : async (AgentContext,
ResumeSessionParams
) ->
ResumeSessionResult
?
list_handler : async (AgentContext,
ListSessionsParams
) ->
ListSessionsResult
?
delete_handler : async (AgentContext,
DeleteSessionParams
) ->
DeleteSessionResult
?
close_handler : async (AgentContext,
CloseSessionParams
) ->
CloseSessionResult
?
set_mode_handler : async (AgentContext,
SetSessionModeParams
) ->
SetSessionModeResult
?
set_config_option_handler : async (AgentContext,
SetSessionConfigOptionParams
) ->
SetSessionConfigOptionResult
?
}

Immutable required/optional session service. The fields remain private so callers cannot construct a half-populated service record.

#
AgentSpec

Immutable specification consumed by the Reader composition program.

#
AgentSupport

pub struct AgentSupport {
prompt_image : Bool
prompt_audio : Bool
prompt_embedded_context : Bool
mcp_http : Bool
mcp_sse : Bool
additional_directories : Bool
}

Non-service support declarations used to derive prompt/MCP capabilities. These are immutable values, not a second manually supplied capability map.

#
agent_adapter_admit

Decode and admit one message. This function is synchronous and pure from the owner loop's perspective; it never calls an application handler.

#
agent_adapter_cancel_completion

fn agent_adapter_cancel_completion(invocation : AgentAdapterInvocation) -> AgentAdapterCompletion

Synthesize the typed cancellation completion for one invocation. The owner loop uses this when it grants an inbound cancellation so the reservation and wire id settle through the normal completion path.

#
agent_adapter_complete

fn agent_adapter_complete(state : AgentAdapterState, invocation : AgentAdapterInvocation, completion : AgentAdapterCompletion) -> AgentAdapterStep raise AgentAdapterError

Complete one admitted invocation in the owner loop. A state-changing completion must match its immutable reservation; duplicate/late auth and logout completions fail explicitly instead of producing a second response.

#
agent_adapter_execute

async fn agent_adapter_execute(invocation : AgentAdapterInvocation, endpoint : AgentEndpoint, context : AgentContext) -> AgentAdapterCompletion noraise

Execute one already-admitted typed operation. This function has no protocol state parameter and cannot emit stdout; it only returns a typed completion for the owner loop.

#
agent_adapter_failure_completion

fn agent_adapter_failure_completion(invocation : AgentAdapterInvocation) -> AgentAdapterCompletion

Synthesize the redacted typed failure completion for one invocation, following the agent_adapter_call convention for unknown failures. The owner task boundary uses this when async execution itself fails before a typed completion exists.

#
agent_adapter_invocation_method_name

fn agent_adapter_invocation_method_name(invocation : AgentAdapterInvocation) -> String

The stable wire method name of one typed invocation. Runtime bridges use it for trace intents only; it never replaces the typed completion.

#
agent_adapter_state_new

#
agent_context

Construct one immutable context around caller-owned typed transport ports. This is intentionally a one-shot constructor rather than a builder.

#
agent_endpoint_from_spec

fn agent_endpoint_from_spec(spec : AgentSpec) -> AgentEndpoint

#
agent_runtime_owner_port

Bind one Agent endpoint and its outbound context onto the single connection owner-loop engine. The returned port captures only the immutable endpoint and context values; every protocol transition stays inside the engine-owned AgentAdapterState. There is no second owner loop, shadow pending map, Ref, Mutex, or builder surface here.

Residual AgentAdapterError values (EndpointMismatch, UnexpectedMessage) indicate composition or protocol bugs, but the owner port closures are total by signature. Each residual is therefore answered with an explicit typed fallback instead of being swallowed: requests get exactly one internal-error response plus one trace effect, notifications get one trace effect and no response, and the owner state is held unchanged. The fallback is visible on the wire and in the trace sink; it is never a silent success.

#
agent_runtime_run

async fn agent_runtime_run(endpoint~ : AgentEndpoint, context~ : AgentContext, initial_state~ : AgentAdapterState, ports~ :
RuntimePorts
, options~ :
RuntimeOptions
) -> Unit

Run one Agent connection on the single native owner-loop engine. This is a thin composition of connection_runtime_run_owner with agent_runtime_owner_port: it validates the options fail-fast and creates no connection state of its own.

#
agent_runtime_run_with_outbound

Run one Agent connection on the single native owner-loop engine with the engine-level outbound channel handed to the Agent context factory. The factory runs after the connection-local queues and shutdown state exist and before the loop starts; it typically builds agent_context_over_channel (in connection/broker) so handlers running mid-execution can issue reverse requests and stream notifications through the real engine. This runner adds no second loop or channel state of its own: it validates the options fail-fast and reuses the same single reader/writer/reducer engine as agent_runtime_run, whose signature and behavior stay unchanged.

#
agent_serve_stdio

async fn agent_serve_stdio(endpoint~ : AgentEndpoint, context~ : AgentContext, initial_state~ : AgentAdapterState, options? :
RuntimeOptions
, trace? : (
RuntimeTraceEvent
) -> Unit) -> Unit

Serve this process's real stdio as one Agent connection: inbound ACP frames arrive on stdin, outbound frames (including one final response per request) go to stdout, and every diagnostic goes to the trace sink (stderr by default). This is a thin composition of agent_runtime_run over runtime_stdio_ports: it validates the options fail-fast before any I/O binding and creates no connection state of its own. The loop ends when stdin reaches EOF or the engine fails; both outcomes surface through the same single reader/writer/reducer engine as every other runner.

#
agent_serve_stdio_with_outbound

Serve this process's real stdio as one Agent connection with the engine-level outbound channel handed to the Agent context factory, so handlers running mid-execution can stream session/update notifications and issue reverse requests (session/request_permission, elicitation, filesystem, terminal) through the real engine instead of a fail-fast broker. Without this composition a stdio Agent could answer requests but never exercise the reverse direction of the protocol; the factory timing mirrors agent_runtime_run_with_outbound (after the connection-local queues exist, before the loop starts). This is a thin composition over runtime_stdio_ports: it validates the options fail-fast before any I/O binding and creates no second loop, channel state, or connection state of its own. The loop ends when stdin reaches EOF or the engine fails.

#
agent_session_service

fn agent_session_service(new_session~ : async (AgentContext,
NewSessionParams
) ->
NewSessionResult
, prompt~ : async (AgentContext,
PromptParams
) ->
PromptResult
, cancel~ : async (AgentContext,
CancelParams
) -> Unit, load? : async (AgentContext,
LoadSessionParams
) ->
LoadSessionResult
, resume_session? : async (AgentContext,
ResumeSessionParams
) ->
ResumeSessionResult
, list? : async (AgentContext,
ListSessionsParams
) ->
ListSessionsResult
, delete? : async (AgentContext,
DeleteSessionParams
) ->
DeleteSessionResult
, close? : async (AgentContext,
CloseSessionParams
) ->
CloseSessionResult
, set_mode? : async (AgentContext,
SetSessionModeParams
) ->
SetSessionModeResult
, set_config_option? : async (AgentContext,
SetSessionConfigOptionParams
) ->
SetSessionConfigOptionResult
) -> AgentSessionService

Compose all required session callbacks once. Optional callbacks are represented by None; there is no mutable registration phase.

#
agent_support

fn agent_support(prompt_image? : Bool, prompt_audio? : Bool, prompt_embedded_context? : Bool, mcp_http? : Bool, mcp_sse? : Bool, additional_directories? : Bool) -> AgentSupport