Documentation
¶
Overview ¶
Package agents backs /tools/agents — the Agents UI Manager. It lets users manage AI agent sessions, workspaces, and presets from the browser and streams real-time agent output via Server-Sent Events.
Index ¶
- Variables
- func AskUsers() *askuser.Manager
- func Register(r tool.Router)
- func SetApprovals(m *gate.ApprovalManager)
- func SetAskUsers(m *askuser.Manager)
- func SetBroadcaster(b *Broadcaster)
- func SetConfigs(c *configs.Service)
- func SetDB(db *gorm.DB)
- func SetGateStatus(s GateStatus)
- func SetLayout(l agentconfig.Layout)
- func SetManager(m *registry.Manager)
- func SetPool(p *pool.Pool)
- func SetSpawnLogger(s *provider.SpawnLogger)
- type Broadcaster
- func (b *Broadcaster) Publish(sessionID, agentName string, ev event.AgentEvent)
- func (b *Broadcaster) PublishApprovalRequest(sessionID string, req gate.ApprovalRequest)
- func (b *Broadcaster) PublishApprovalResolved(sessionID, requestID, decision string)
- func (b *Broadcaster) PublishAskUser(sessionID, agentName string, payload []byte)
- func (b *Broadcaster) PublishAskUserResolved(sessionID, requestID string)
- func (b *Broadcaster) PublishLifecycle(sessionID, agentName, lifecycle string, pid int)
- func (b *Broadcaster) Subscribe(sessionID string) (<-chan Event, func())
- type Event
- type GateStatus
Constants ¶
This section is empty.
Variables ¶
var StaticFS embed.FS
Functions ¶
func AskUsers ¶
AskUsers returns the wired Manager so the boot path can hand it to the MCP handler. Reading this is racy if SetAskUsers is called concurrently with reads, but in practice it's set once during boot before serving begins.
func SetApprovals ¶
func SetApprovals(m *gate.ApprovalManager)
SetApprovals wires in the gate ApprovalManager. nil = gate disabled (handler endpoints fall back to 503).
func SetAskUsers ¶
SetAskUsers wires in the ask_user Manager. nil = ask_user MCP tool returns errors and the answer endpoint 503s.
func SetBroadcaster ¶
func SetBroadcaster(b *Broadcaster)
SetBroadcaster wires in the SSE event broadcaster.
func SetConfigs ¶
SetConfigs wires the shared configs service so the Providers page can toggle agents.gate_enabled inline. Without this, the toggle endpoint 503s.
func SetDB ¶
SetDB wires the shared GORM DB so channel handlers can read/write agent_channels rows. Without this, channel config endpoints 503.
func SetGateStatus ¶
func SetGateStatus(s GateStatus)
SetGateStatus records the boot-time gate-resolution result. Read by the Providers page. Call exactly once during server boot.
func SetLayout ¶
func SetLayout(l agentconfig.Layout)
SetLayout wires in the on-disk layout used for direct file reads.
func SetManager ¶
SetManager wires in the agents registry manager.
func SetSpawnLogger ¶
func SetSpawnLogger(s *provider.SpawnLogger)
SetSpawnLogger wires in the per-spawn jsonl writer/reader. The Providers page reads from it via List + Read; the pool factory already writes through it.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster fans out agent events to all subscribed SSE connections. Subscribe returns a receive channel and an unsub func. Publish is called from ClaudeFactory.OnEvent on every AgentEvent.
subs is keyed by sessionID ("" = global subscribers that receive all events). Channels are buffered at 64 so a slow client never stalls the agent reader goroutine.
func NewBroadcaster ¶
func NewBroadcaster() *Broadcaster
NewBroadcaster returns a ready Broadcaster.
func (*Broadcaster) Publish ¶
func (b *Broadcaster) Publish(sessionID, agentName string, ev event.AgentEvent)
Publish fires ev to all subscribers of sessionID and all global ("") subscribers. Non-blocking: a full channel's event is dropped rather than blocking.
func (*Broadcaster) PublishApprovalRequest ¶
func (b *Broadcaster) PublishApprovalRequest(sessionID string, req gate.ApprovalRequest)
PublishApprovalRequest fires when the gate binary dials the daemon socket with an unrecognised command. Browsers render this as a modal with 4 decision buttons (approve_once / approve_session / approve_always / block); the user's pick rides back through POST /approve.
Data is the JSON-encoded ApprovalRequest so the front-end can decode it once and use every field (cmd, work_dir, match_key, ...).
func (*Broadcaster) PublishApprovalResolved ¶
func (b *Broadcaster) PublishApprovalResolved(sessionID, requestID, decision string)
PublishApprovalResolved fires once a decision is delivered (UI click, timeout, or listener close). Browsers use this to dismiss any open modal across all tabs subscribed to the session.
func (*Broadcaster) PublishAskUser ¶
func (b *Broadcaster) PublishAskUser(sessionID, agentName string, payload []byte)
PublishAskUser fires when the ask_user MCP tool is invoked by an agent. Front-end renders an inline card with options + freeform input; user's pick rides back through POST /answer. Data is the JSON-encoded request body so every field (question, options, allow_freeform, ...) round-trips exactly once.
func (*Broadcaster) PublishAskUserResolved ¶
func (b *Broadcaster) PublishAskUserResolved(sessionID, requestID string)
PublishAskUserResolved fires once an ask_user request resolves (UI answer or timeout). Used by the UI to dismiss the inline card across all tabs subscribed to the session.
func (*Broadcaster) PublishLifecycle ¶
func (b *Broadcaster) PublishLifecycle(sessionID, agentName, lifecycle string, pid int)
PublishLifecycle pushes a lifecycle transition (Spawning, Killed) to subscribers. Idle/Working transitions are inferred from AgentEvent flow on the client side; only the bookend transitions — which never carry an AgentEvent — go through this channel.
func (*Broadcaster) Subscribe ¶
func (b *Broadcaster) Subscribe(sessionID string) (<-chan Event, func())
Subscribe registers a listener for a specific session (or "" for all). The caller must call the returned unsub func when the SSE connection closes.
type Event ¶
type Event struct {
SessionID string `json:"session_id"`
AgentName string `json:"agent_name"`
Type string `json:"type"`
Data string `json:"data"`
PID int `json:"pid,omitempty"`
Lifecycle string `json:"lifecycle,omitempty"`
}
Event is one SSE payload pushed to browser subscribers. Type distinguishes agent stream events ("text_delta", "tool_use", ...) from lifecycle events ("lifecycle"); the latter carry PID + lifecycle label in Data so the UI can update the status badge without re-fetching the page.
type GateStatus ¶
type GateStatus struct {
Enabled bool
Binary string // absolute path
Source string // gate.Source* constant
Reason string // populated when Enabled=false
}
GateStatus is the boot-time snapshot of the command gate. Populated once during server.go startup and read by the Providers page so operators can tell at a glance whether the gate sidecar is wired up.
Enabled=false means ResolveGateBinary returned an error — every command will hit fail-safe block at the matcher / no-socket path, except whitelist matches. Reason carries the error message so the UI can show actionable guidance (run `wick build`).
func GetGateStatus ¶
func GetGateStatus() GateStatus
GetGateStatus is the read side. Returns a zero value when boot hasn't reached SetGateStatus yet.