# @ai-assistant/cli Command-line interface for AI Terminal Assistant - interact with AI directly from your terminal. ## ๐Ÿ“ฆ Installation ```bash # Global installation pnpm add -g @ai-assistant/cli # Or run directly with npx/bunx npx @ai-assistant/cli bunx @ai-assistant/cli ``` ## ๐ŸŒŸ Features - **Dual Modes** - Server mode and client attach mode - **Interactive Chat** - Rich terminal UI with syntax highlighting - **Streaming Responses** - Real-time AI responses - **File Attachments** - Attach files to messages - **Command History** - Navigate through previous commands - **Auto-completion** - Tab completion for commands - **Colored Output** - Beautiful terminal formatting - **Session Management** - Persistent conversation history ## ๐Ÿš€ Quick Start ### Server Mode Start a local AI server: ```bash # Start server on default port 3000 ai-assist serve # Start on custom port ai-assist serve --port 8080 # With specific model ai-assist serve --model claude-haiku-3-20251120 # With verbose logging ai-assist serve --verbose ``` ### Client Mode Attach to a running AI server: ```bash # Attach to local server ai-assist attach # Attach to remote server ai-assist attach https://ai-server.example.com # Attach with authentication ai-assist attach https://ai-server.example.com --token YOUR_TOKEN # Attach to specific session ai-assist attach --session my-session-id ``` ## ๐Ÿ“š Commands ### Global Options ```bash ai-assist [command] [options] Options: -h, --help Show help -v, --version Show version --config Path to config file --verbose Enable verbose logging ``` ### Server Command ```bash ai-assist serve [options] Options: -p, --port Server port (default: 3000) -h, --host Server host (default: localhost) --api-key Anthropic API key (or use ANTHROPIC_API_KEY env) --model AI model to use --max-tokens Maximum response tokens --no-auth Disable authentication --cors-origin CORS allowed origins ``` ### Attach Command ```bash ai-assist attach [server-url] [options] Arguments: server-url Server URL (default: http://localhost:3000) Options: -s, --session Session ID to attach to -t, --token Authentication token --no-history Don't load session history --stream Enable streaming mode ``` ## โŒจ๏ธ Interactive Commands Once connected, use these commands in the chat interface: ``` /help Show available commands /clear Clear the screen /history Show message history /attach Attach a file to the next message /model Switch AI model /session new Start a new session /session list List available sessions /session switch Switch to another session /export Export conversation to file /quit Exit the CLI ``` ## ๐ŸŽจ Terminal UI Features ### Message Display - **User messages** - Displayed with `>` prefix in cyan - **AI responses** - Formatted with syntax highlighting - **Code blocks** - Highlighted based on language - **Markdown** - Rendered with terminal formatting - **Progress indicators** - Animated spinners during processing ### Keyboard Shortcuts - `โ†‘/โ†“` - Navigate message history - `Tab` - Auto-complete commands - `Ctrl+C` - Cancel current operation - `Ctrl+D` - Exit (same as /quit) - `Ctrl+L` - Clear screen (same as /clear) - `PgUp/PgDn` - Scroll through long responses ## ๐Ÿ”ง Configuration ### Configuration File Create `~/.ai-assistant/config.json`: ```json { "defaultServer": "http://localhost:3000", "apiKey": "sk-ant-xxxxx", "model": "claude-sonnet-4-20250514", "theme": "dark", "editor": "vim", "history": { "enabled": true, "maxSize": 1000 }, "display": { "showTimestamps": true, "syntax_highlighting": true, "word_wrap": true, "max_width": 120 } } ``` ### Environment Variables ```bash # API Configuration export ANTHROPIC_API_KEY=sk-ant-xxxxx export AI_MODEL=claude-sonnet-4-20250514 # CLI Configuration export AI_CLI_SERVER=http://localhost:3000 export AI_CLI_SESSION=my-session export AI_CLI_TOKEN=auth-token # Display Configuration export AI_CLI_COLOR=true export AI_CLI_EDITOR=vim ``` ## ๐Ÿ”Œ Scripting and Automation ### Pipe Input ```bash # Send a single message echo "What is TypeScript?" | ai-assist attach # Process a file cat code.ts | ai-assist attach --message "Review this code" # Chain with other commands git diff | ai-assist attach --message "Explain these changes" ``` ### Script Mode ```bash #!/bin/bash # Create a script for batch processing ai-assist attach < debug.log ``` ### Common Issues 1. **"Cannot connect to server"** - Check if server is running - Verify server URL and port - Check firewall settings 2. **"Authentication failed"** - Verify API key is set - Check token expiration - Ensure server auth is configured 3. **"Session not found"** - Session may have expired - Use `/session list` to see available sessions - Create new session with `/session new` ## ๐Ÿค Contributing Contributions are welcome! See the main repository's contributing guide. ## ๐Ÿ“„ License MIT License - see [LICENSE](../../LICENSE) for details. ## ๐Ÿ”— Links - [Main Repository](https://github.com/username/ai-terminal-assistant) - [Documentation](https://docs.example.com/cli) - [Issue Tracker](https://github.com/username/ai-terminal-assistant/issues)