Documentation
¶
Overview ¶
Package cli provides a CLI input component for interactive user sessions. It reads from stdin, publishes user messages to NATS, and handles Ctrl+C signals.
Package cli provides a CLI input component for interactive user sessions.
The CLI input component reads from stdin, publishes user messages to the router via NATS, displays responses, and handles Ctrl+C signals for loop cancellation.
Architecture ¶
The CLI component is an input component that bridges terminal interaction with the agentic system:
┌─────────────┐ user.message.cli.* ┌────────────┐
│ │ ──────────────────────────▶│ │
│ CLI Input │ │ Router │
│ │◀────────────────────────── │ │
└─────────────┘ user.response.cli.* └────────────┘
│
│ Ctrl+C
▼
user.signal.{loop_id}
NATS Subjects ¶
The component uses three subject patterns:
- user.message.cli.{session_id} - Published when user enters text
- user.response.cli.{session_id} - Subscribed for router responses
- user.signal.{loop_id} - Published on Ctrl+C to cancel active loop
Local Commands ¶
Some commands are handled locally without routing to the server:
- /quit, /exit - Exit the CLI session
- /clear - Clear the active loop tracking
All other input (including /commands) is published to the router.
Configuration ¶
The component is configured via JSON:
{
"user_id": "coby",
"session_id": "terminal-1",
"prompt": "> ",
"stream_name": "USER"
}
Signal Handling ¶
Pressing Ctrl+C sends a cancel signal for the currently active loop. If no loop is active, it displays a message. Press Ctrl+C twice to exit when no loop is running.
Example Usage ¶
The CLI component is typically created via the component registry:
config := json.RawMessage(`{
"user_id": "coby",
"session_id": "session-001"
}`)
comp, err := cli.NewComponent(config, deps)
if err != nil {
log.Fatal(err)
}
comp.Start(ctx)
Package cli provides Prometheus metrics for CLI input component.
Index ¶
- func NewComponent(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)
- func Register(registry *component.Registry) error
- type Component
- func (c *Component) ConfigSchema() component.ConfigSchema
- func (c *Component) DataFlow() component.FlowMetrics
- func (c *Component) GetActiveLoop() string
- func (c *Component) Health() component.HealthStatus
- func (c *Component) Initialize() error
- func (c *Component) InputPorts() []component.Port
- func (c *Component) Meta() component.Metadata
- func (c *Component) OutputPorts() []component.Port
- func (c *Component) SetActiveLoop(loopID string)
- func (c *Component) SetReader(r io.Reader)
- func (c *Component) SetWriter(w io.Writer)
- func (c *Component) Start(ctx context.Context) error
- func (c *Component) Stop(timeout time.Duration) error
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewComponent ¶
func NewComponent(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)
NewComponent creates a new CLI input component
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component implements the CLI input processor
func (*Component) ConfigSchema ¶
func (c *Component) ConfigSchema() component.ConfigSchema
ConfigSchema returns the configuration schema
func (*Component) DataFlow ¶
func (c *Component) DataFlow() component.FlowMetrics
DataFlow returns current data flow metrics
func (*Component) GetActiveLoop ¶
GetActiveLoop returns the active loop ID
func (*Component) Health ¶
func (c *Component) Health() component.HealthStatus
Health returns current health status
func (*Component) Initialize ¶
Initialize prepares the component
func (*Component) InputPorts ¶
InputPorts returns input port definitions
func (*Component) OutputPorts ¶
OutputPorts returns output port definitions
func (*Component) SetActiveLoop ¶
SetActiveLoop sets the active loop ID (for testing)