Skip to main content

Purpose

The tui package is a thin interactive shell around loop.Loop with a small persisted provider config.

Main entrypoints

tui.New(systemPrompt string, opts ...Option)

Constructs a TUIApp with a system prompt and registered tools. Useful option helpers:
  • tui.WithTool(name, tool)
  • tui.WithTools(map[string]loop.Tool)

(*TUIApp).Run(ctx)

Starts the read-eval-print loop:
  • loads ~/.config/hrns/config.json
  • runs onboarding if the config file is missing or empty
  • builds openai.Client for the current provider
  • constructs loop.Loop from the stored system prompt and tools
  • prints the banner
  • prints the active provider and model
  • reads a line from stdin
  • handles slash commands
  • appends user messages
  • runs the agent loop
  • prints streamed chunks
  • stores the final message history for the next turn

Slash commands

The package currently handles:
  • /model <model>
  • /new
  • /providers
  • /connect
  • /help
Command parsing is still basic string splitting. Model changes are persisted to the config file. Provider additions are also persisted, but the active session client is not rebuilt after /connect.

Rendering behavior

The package uses github.com/fatih/color for simple terminal coloring. It renders:
  • harness messages in blue
  • errors in red
  • tool names in red with yellow arguments
  • reasoning text in gray
Assistant response text is printed with the default color settings.

Relationship to the rest of hrns

The TUI is the easiest way to try the loop, but it is not the core abstraction. If you want a web UI, service, editor integration, or batch runner, you usually replace tui rather than extend it.