Purpose
Thetui package is a thin terminal wrapper around loop.Loop with a small persisted provider config. It supports an interactive shell and a one-shot exec mode.
Main entrypoints
tui.New(opts ...Option)
Constructs a TUIApp with registered tools, agents, and built-in slash commands.
Useful option helpers:
tui.WithTool(name, tool)tui.WithTools(map[string]loop.Tool)tui.WithAgent(agent.Agent)tui.WithAgents([]agent.Agent)tui.WithSkills([]skills.Skill)tui.WithSystemPrompt(string)
(*TUIApp).Run(ctx)
Starts the bundled runner:
- loads
~/.config/hrns/config.json - runs onboarding if the config file is missing or empty
- selects the saved current agent, repairs a stale saved agent, or saves one registered agent as current
- composes the system message from the selected agent or base prompt plus discovered skill metadata
- builds
openai.Clientfor the current provider - constructs
loop.Loopfrom the current client and registered tools - detects interactive mode by default or
execmode when the first CLI argument isexec - in interactive mode, prints the banner, reads stdin, handles slash commands, runs the loop, and stores message history
- in
execmode, parses-message,-provider,-model, and-agent, runs one turn, streams chunks, and exits
Slash commands
The package currently handles:/new/models/model <model>/providers/provider <name>/agents/agent <agent>/connect/help
/help is rendered from that registry. Model changes are persisted to the config file. /provider <name> also persists currentProvider and rebuilds the in-memory client. /connect saves a new provider entry and updates currentProvider, but it does not switch the live client by itself. /agent <agent> persists currentAgent and resets the active system message to that agent’s prompt.
Exec flags
When the bundled binary is invoked ashrns exec, the package accepts:
-messagefor the one user prompt to run-providerto choose a saved provider for that run-modelto override the model used for the one-shot run-agentto choose a registered agent prompt for that run
-provider is supplied without -model, exec uses the selected provider’s saved default model.
Rendering behavior
The package usesgithub.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
Relationship to the rest of hrns
The bundled runner 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 a richer batch runner, you usually replacetui rather than extend it.