handlers

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package handlers provides a Dispatcher that implements acp.Client so the coder/acp-go-sdk ClientSideConnection can dispatch agent→client RPCs and notifications into opencodesdk. Each method routes to a user-supplied callback when present, and falls back to a sensible default otherwise (pass-through for fs/write, reject for permission, no-op for session/update, unsupported for terminal).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callbacks

type Callbacks struct {
	Permission          PermissionCallback
	FsWrite             FsWriteCallback
	SessionUpdate       SessionUpdateCallback
	Elicitation         ElicitationCallback
	ElicitationComplete ElicitationCompleteCallback
}

Callbacks bundles all user-supplied handler hooks.

type Dispatcher

type Dispatcher struct {
	Callbacks Callbacks
	Logger    *slog.Logger

	// StrictCwdBoundary rejects fs/write_text_file delegations for any
	// path outside Cwd. If StrictCwdBoundary is true but Cwd is empty,
	// every write is rejected.
	StrictCwdBoundary bool
	Cwd               string
}

Dispatcher implements acp.Client by routing incoming RPCs into the supplied Callbacks.

func (*Dispatcher) ReadTextFile

ReadTextFile handles fs/read_text_file delegations. opencode never emits these at present, but we implement the method anyway because we advertise fs.readTextFile capability and coder SDK requires the full interface.

func (*Dispatcher) RequestPermission

RequestPermission handles agent-initiated permission requests. If no callback is set, the request is rejected with the "reject" option (if offered) and an error is logged so developers notice the missing handler.

func (*Dispatcher) SessionUpdate

func (d *Dispatcher) SessionUpdate(ctx context.Context, params acp.SessionNotification) error

SessionUpdate handles inbound session/update notifications. The callback is invoked synchronously; a non-nil error is returned to the coder SDK which surfaces it as a notification-handling failure.

func (*Dispatcher) UnstableCompleteElicitation

func (d *Dispatcher) UnstableCompleteElicitation(ctx context.Context, params acp.UnstableCompleteElicitationNotification) error

UnstableCompleteElicitation routes elicitation/complete notifications to the configured callback. Notification-only: the callback's return path does not surface back to the agent.

func (*Dispatcher) UnstableCreateElicitation

UnstableCreateElicitation routes an agent-initiated elicitation/create request to the configured callback. When no callback is set, we return a Decline response so the agent gracefully recovers without the SDK having to synthesise a JSON-RPC error from inside the handler.

opencode 1.14.20 does not currently emit elicitation/create; this handler is wired in anticipation of future ACP agents that do.

func (*Dispatcher) WriteTextFile

WriteTextFile handles fs/write_text_file delegations. opencode emits this after an approved edit to sync the client's in-memory buffer with on-disk state. Default behavior is to write through; callers can override via FsWriteCallback.

type ElicitationCallback

ElicitationCallback is invoked when the agent issues an elicitation/create request (agent → client). Returning a non-nil error surfaces as a JSON-RPC error to the agent.

type ElicitationCompleteCallback

type ElicitationCompleteCallback func(ctx context.Context, params acp.UnstableCompleteElicitationNotification)

ElicitationCompleteCallback is invoked for elicitation/complete notifications. Notification-only: errors are not propagated.

type FsWriteCallback

type FsWriteCallback func(ctx context.Context, req acp.WriteTextFileRequest) error

FsWriteCallback is invoked when the agent delegates a file write. Return a non-nil error to refuse the write (opencode will surface this as a tool failure).

type PermissionCallback

type PermissionCallback func(ctx context.Context, req acp.RequestPermissionRequest) (acp.RequestPermissionResponse, error)

PermissionCallback is invoked when the agent requests permission for a tool call. Return the option the user selected, or return with ctx.Err != nil to signal cancellation.

type SessionUpdateCallback

type SessionUpdateCallback func(ctx context.Context, params acp.SessionNotification) error

SessionUpdateCallback is invoked for every session/update notification streamed by the agent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL