Metadata-Version: 2.4
Name: sage-tui
Version: 1.1.0
Summary: Interactive TUI for Sage AI agent
Author-email: Sage Choi <iamsagebynature@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Sage Choi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: click>=8.0
Requires-Dist: python-dotenv>=1.0
Requires-Dist: sage-agent>=1.5.0rc1
Requires-Dist: textual>=0.50
Description-Content-Type: text/markdown

# sage-tui

Interactive terminal user interface for the Sage AI agent framework.

## Features

- Split-screen layout with chat, status, and log panels
- Streaming and batch response modes with animated thinking indicator
- Collapsible tool call display with color-coded status (running, success, error)
- Markdown rendering for agent responses
- Permission modal for tool approval
- Parallel subagent orchestration
- Context window usage bar with color gradient
- Token breakdown and session cost tracking
- Auto-generated session titles via LLM
- Input history navigation
- Smart auto-scroll that respects manual scroll position
- Log forwarding to TUI panel

## Installation

```bash
uv add sage-tui
```

Or with pip:

```bash
pip install sage-tui
```

Requires Python 3.10 or later.

## Quick Start

```bash
# Point directly at an agent definition
sage-tui -c /path/to/AGENTS.md

# Or use a config.toml
sage-tui --config /path/to/config.toml

# Or set the env var and just run
export SAGE_CONFIG_PATH=/path/to/config.toml
sage-tui
```

## CLI Options

| Option | Description |
|--------|-------------|
| `--agent-config`, `-c PATH` | Path to AGENTS.md or directory containing one. Inferred from config.toml if omitted. |
| `--config PATH` | Path to main config.toml. Also reads the `SAGE_CONFIG_PATH` env var. |
| `--verbose`, `-v` | Enable debug logging. |

## Keyboard Shortcuts

| Key | Action |
|-----|--------|
| Enter | Submit message |
| Shift+Enter / Ctrl+J | Insert newline |
| Up / Down | Navigate input history (single-line mode) |
| Ctrl+B | Toggle status panel |
| Ctrl+L | Toggle log panel |
| Ctrl+N | New session (clear chat, reset agent) |
| Ctrl+S | Toggle streaming / batch mode |
| Ctrl+O | Orchestrate subagents (if available) |
| Ctrl+Q | Quit |
| Y / N | Approve or deny in permission modal |

## Layout

The TUI is divided into four areas:

- **Chat panel** (left, flexible width) -- Conversation history with inline collapsible tool calls and a message input box at the bottom.
- **Status panel** (right, 40 columns, hidden by default) -- Session info, context window usage bar, token breakdown, agent info, skills, and active agents. Toggle with Ctrl+B.
- **Log panel** (bottom, hidden by default) -- Scrollable log viewer for the `sage.*` logging namespace. Toggle with Ctrl+L.
- **Status bar** (bottom, 1 line) -- Agent state, model name, stream mode indicator, token usage, cost, and keyboard hints.

## Configuration

There are three ways to configure which agent the TUI loads:

**1. Direct agent path**

```bash
sage-tui -c /path/to/AGENTS.md
```

Point at an AGENTS.md file or a directory that contains one.

**2. Via config.toml**

```bash
sage-tui --config /path/to/config.toml
```

The TUI reads the `agents_dir` and `primary` fields from config.toml to resolve the primary agent definition.

**3. Auto-discovery**

```bash
export SAGE_CONFIG_PATH=/path/to/config.toml
sage-tui
```

When no flags are given, the TUI reads the `SAGE_CONFIG_PATH` environment variable, locates config.toml, and resolves the primary agent from there.

A `.env` file in the working directory is loaded automatically via python-dotenv.

## Streaming vs Batch

The TUI supports two response modes, toggled at runtime with Ctrl+S. In **streaming** mode, tokens appear incrementally as the model generates them, with an animated thinking indicator while waiting. In **batch** mode, the full response is displayed only after generation completes. Streaming is the default.

## Development

See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.

## License

MIT
