Documentation
¶
Overview ¶
Package bridge manages a single kiro-cli ACP subprocess.
Index ¶
- func ACPBridgeContractTest(t *testing.T, newBridge func() api.ACPBridge)
- type Bridge
- func (b *Bridge) Call(ctx context.Context, method string, params any) (*api.RPCResponse, error)
- func (b *Bridge) CurrentMode() string
- func (b *Bridge) ModelID() api.ModelID
- func (b *Bridge) Models() []api.SessionModel
- func (b *Bridge) Modes() []api.SessionMode
- func (b *Bridge) NotifCh() <-chan *api.RPCResponse
- func (b *Bridge) Notify(ctx context.Context, method string, params any) error
- func (b *Bridge) Respond(ctx context.Context, id int64, result any, err error) error
- func (b *Bridge) SessionID() api.SessionID
- func (b *Bridge) SetModel(ctx context.Context, modelID string) error
- func (b *Bridge) Start(ctx context.Context, opts *api.StartOpts) error
- func (b *Bridge) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ACPBridgeContractTest ¶
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 (*Bridge) Call ¶
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 ¶
CurrentMode returns the currently-selected session mode. Safe to call from any goroutine.
func (*Bridge) 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) Respond ¶
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 ¶
SessionID returns the bridge's ACP session id. Safe to call from any goroutine.
func (*Bridge) SetModel ¶
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 ¶
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).