bridge

package
v0.2.49 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: GPL-2.0, GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package bridge manages a single kiro-cli ACP subprocess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACPBridgeContractTest

func ACPBridgeContractTest(t *testing.T, newBridge func() api.ACPBridge)

ACPBridgeContractTest verifies behavioral contracts that any api.ACPBridge implementation must satisfy without a real kiro-cli subprocess. Run this against both the real Bridge and test fakes to catch drift at the lifecycle level.

Assertions are limited to properties that hold universally (before Start is called), so fakes that pre-populate SessionID/ModelID for convenience are not penalized.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge is one kiro-cli ACP subprocess tied to one chat.

func New

func New(cliPath, workDir string) *Bridge

New returns a fresh bridge. Call Start before any other method.

func (*Bridge) Call

func (b *Bridge) Call(ctx context.Context, method string, params any) (*api.RPCResponse, error)

Call sends a JSON-RPC request and waits for the matching response. Blocks until the response arrives or the bridge's readLoop exits (which unblocks all pending waiters with a sentinel error). Agent turns can legitimately run for hours; the caller owns turn cancellation via Notify("session/cancel", ...). Shutdown ordering is enforced by Stop → readLoop fanout; no in-Call timeout is needed.

func (*Bridge) CurrentMode

func (b *Bridge) CurrentMode() string

CurrentMode returns the currently-selected session mode. Safe to call from any goroutine.

func (*Bridge) ModelID

func (b *Bridge) ModelID() api.ModelID

ModelID returns the currently-selected model id. Safe to call from any goroutine.

func (*Bridge) Models

func (b *Bridge) Models() []api.SessionModel

Models returns the available model catalog as declared by the agent on session/new or session/load, with [Deprecated] / [Legacy] entries filtered out (see api.TagExcluded). The returned slice is frozen (never mutated after construction); callers MUST NOT mutate it.

func (*Bridge) Modes

func (b *Bridge) Modes() []api.SessionMode

Modes returns the available session modes as declared by the agent on session/new or session/load. The returned slice is frozen (never mutated after construction); callers MUST NOT mutate it.

func (*Bridge) NotifCh

func (b *Bridge) NotifCh() <-chan *api.RPCResponse

NotifCh returns the channel of incoming ACP notifications from the bridge subprocess.

func (*Bridge) Notify

func (b *Bridge) Notify(ctx context.Context, method string, params any) error

Notify sends a JSON-RPC notification (no response expected).

func (*Bridge) Respond

func (b *Bridge) Respond(ctx context.Context, id int64, result any, err error) error

Respond writes a JSON-RPC response to a request we received from kiro-cli (e.g. fs/read_text_file, fs/write_text_file). Pass a non-nil result for success, a non-nil err for failure; exactly one must be set. Errors from the ACP namespace use code -32603 (internal error) unless err unwraps to an *api.RPCError with a specific code.

func (*Bridge) SessionID

func (b *Bridge) SessionID() api.SessionID

SessionID returns the bridge's ACP session id. Safe to call from any goroutine.

func (*Bridge) SetModel

func (b *Bridge) SetModel(ctx context.Context, modelID string) error

SetModel performs an in-session model swap via session/set_config_option (configId "model") — the v3 (KAS) replacement for the removed session/set_model. On success, updates the bridge's internal model id and returns nil. On failure (context too large, model unavailable, InvalidModelError), returns the error and leaves the model id unchanged.

func (*Bridge) Start

func (b *Bridge) Start(ctx context.Context, opts *api.StartOpts) error

Start launches the kiro-cli subprocess and either creates a new ACP session (acpSessionID == "") or loads an existing one. Exactly one call per bridge instance. mcpServers is the ACP mcpServers array (enabled user-configured MCP servers); pass nil for an empty set.

func (*Bridge) Stop

func (b *Bridge) Stop()

Stop kills the subprocess and closes NotifCh. Safe to call multiple times; subsequent calls are no-ops. Multiple call sites (hub.Shutdown, cullIdleBridges, session/load recovery) can race to stop the same bridge; the sync.Once gate prevents a double-close panic on b.done. Reaps the process via cmd.Wait so the OS releases its process entry immediately (no <defunct> accumulation across chat lifecycle churn).

Jump to

Keyboard shortcuts

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