@profullstack/ai v1.1.1
@profullstack/ai
A powerful AI agent CLI tool for interactive conversations with AI, featuring file operations and command execution capabilities.
Installation
npm install -g @profullstack/aiOr using pnpm:
pnpm add -g @profullstack/aiFeatures
- š¤ Interactive AI Chat: Conversational interface with AI models
- š File Operations: Read, write, and delete files with permission prompts
- ā” Command Execution: Run system commands safely with user approval
- š Permission System: Granular control with "allow", "disallow", "allow forever" options
- š Multi-Provider Support: Works with OpenAI GPT and Anthropic Claude models
- āļø Flexible Configuration: Customizable settings and API key management
- š Conversation History: Track and export chat sessions
Usage
Enhanced Mode (Default)
The AI agent runs in enhanced mode by default, which enables file operations and command execution:
aiThis starts an interactive session where the AI can:
- Read and analyze files in your project
- Create, modify, and delete files (with your permission)
- Execute commands like
npm install,git status, etc. - List directory contents and check file existence
Security: You'll be prompted before any file or command operation with options:
- Allow (this time only)
- Disallow (reject the action)
- Allow forever (permanently allow this type of action)
Text-Only Mode
To use the traditional text-only mode without file/command capabilities:
ai --no-enhancedInteractive Mode (Default)
Simply run ai to start an interactive chat session:
aiThis will start an interactive prompt where you can have conversations with the AI:
š¤ AI Agent
Type your questions or commands. Type "exit" or "quit" to leave.
ai > Hello, how are you?
š¤ Hello! I'm your AI assistant. How can I help you today?
ai > What can you do?
š¤ I can help you with a wide variety of tasks including:
⢠Answering questions on various topics
⢠Helping with writing and editing
⢠Explaining concepts and ideas
⢠Providing suggestions and recommendations
⢠Assisting with problem-solving
⢠And much more! Just ask me anything you'd like help with.
ai > exit
Goodbye! šSingle Query Mode
Ask a single question and get a response:
ai ask "What is the capital of France?"Available Commands in Interactive Mode
helpor?- Show help messageclear- Clear conversation historyconfig- Show current configurationexit,quit, orq- Exit the AI agent
Permission Management
Control what actions the AI can perform:
# Show current permissions
ai config --show-permissions
# Reset all permissions (will prompt again for each action)
ai config --reset-permissionsPermission Types:
file_read- Reading filesfile_write- Writing/creating filesfile_delete- Deleting filescommand_exec- Executing system commands
Permission Levels:
- Allow (this time only) - Permit the action once
- Disallow - Reject the action
- Allow forever - Permanently allow this action type
- x Auto-approve - Automatically allow approved actions (for commands in approved list)
Approved Commands Management
Control which commands can be auto-approved:
# Show approved commands list
ai config --show-commands
# Add a command to approved list
ai config --add-command "git status"
# Remove a command from approved list
ai config --remove-command "rm -rf"
# Reset to default approved commands
ai config --reset-commandsDefault Approved Commands:
Safe, read-only commands like ls, pwd, git status, npm list, etc. are pre-approved for auto-execution when auto-approve mode is enabled.
Quick Setup
For first-time setup, use the interactive setup command:
ai setupThis will guide you through:
- Setting up OpenAI and/or Anthropic API keys
- Choosing your preferred AI model
- Configuring response settings
Configuration
View Current Configuration
ai config --showSet Configuration Values
ai config --set model=gpt-4
ai config --set temperature=0.8
ai config --set maxTokens=2000API Key Management
# Interactive setup (recommended)
ai setup
# Manual API key setup
ai config --set-openai-key sk-your-openai-key-here
ai config --set-anthropic-key sk-ant-your-anthropic-key-here
# Check API key status
ai config --show-keysAPI keys are stored securely in ~/.config/ai/config.json and can also be set via environment variables:
export OPENAI_API_KEY=sk-your-openai-key-here
export ANTHROPIC_API_KEY=sk-ant-your-anthropic-key-hereReset Configuration
ai config --resetExport/Import Configuration
# Export configuration to a file
ai config --export my-config.json
# Import configuration from a file
ai config --import my-config.jsonExport All Data
Export all your AI agent data (configuration, API keys, conversation history) to a zip file:
ai exportThis creates ~/ai-agent.zip containing:
- Configuration settings (model, temperature, etc.)
- API keys (OpenAI, Anthropic)
- All conversation history
To restore on another machine:
# Copy the zip file to the target machine, then:
unzip ~/ai-agent.zip -d ~Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
model | string | gpt-3.5-turbo | AI model to use |
temperature | number | 0.7 | Response creativity (0.0-2.0) |
maxTokens | number | 1000 | Maximum response length |
systemPrompt | string | You are a helpful AI assistant. | System prompt |
verbose | boolean | false | Enable verbose output |
openaiApiKey | string | null | OpenAI API key for GPT models |
anthropicApiKey | string | null | Anthropic API key for Claude models |
apiEndpoint | string | null | Custom API endpoint |
Command Line Options
Interactive Mode Options
ai chat [options]Options:
-m, --model <model>- AI model to use-t, --temperature <temp>- Response creativity (0.0-2.0)--max-tokens <tokens>- Maximum response length--system <prompt>- System prompt to use--verbose- Enable verbose output
Single Query Options
ai ask <question> [options]Same options as interactive mode.
Examples
Enhanced Agent Usage
import { EnhancedAIAgent } from '@profullstack/ai';
const agent = new EnhancedAIAgent({
model: 'gpt-3.5-turbo',
temperature: 0.7
});
// AI can now read files, write files, and execute commands
const response = await agent.query('Read my package.json and create a simple README for this project');
console.log(response);Basic Agent Usage (Text-only)
import { AIAgent } from '@profullstack/ai';
const agent = new AIAgent({
model: 'gpt-3.5-turbo',
temperature: 0.7
});
const response = await agent.query('Hello, world!');
console.log(response);File Operations
import { readFile, writeFile, executeCommand } from '@profullstack/ai';
// These functions include built-in permission prompts
const content = await readFile('./myfile.txt');
await writeFile('./output.txt', 'Hello, world!');
const result = await executeCommand('npm test');Configuration Management
import { getConfig, updateConfig, setOpenAIKey, getOpenAIKey } from '@profullstack/ai';
// Get current configuration
const config = getConfig();
console.log(config);
// Update configuration
updateConfig('temperature', 0.8);
updateConfig('model', 'gpt-4');
// Set API keys
setOpenAIKey('sk-your-openai-key-here');
setAnthropicKey('sk-ant-your-anthropic-key-here');
// Get API keys
const openaiKey = getOpenAIKey(); // Checks env var first, then config file
const anthropicKey = getAnthropicKey();Conversation History
import { AIAgent } from '@profullstack/ai';
const agent = new AIAgent();
await agent.query('Hello!');
await agent.query('How are you?');
// Get conversation stats
const stats = agent.getStats();
console.log(stats);
// Export history
const history = agent.exportHistory('markdown');
console.log(history);
// Clear history
agent.clearHistory();Development
Setup
git clone https://github.com/profullstack/ai.git
cd ai
pnpm installRun Examples
pnpm run exampleRun CLI Locally
pnpm run cliAPI Reference
EnhancedAIAgent Class
The enhanced agent extends AIAgent with file and command capabilities.
Constructor
new EnhancedAIAgent(options)Options:
model- AI model to usetemperature- Response creativitymaxTokens- Maximum response lengthsystem- System promptverbose- Enable verbose outputenableActions- Enable file/command operations (default: true)
Methods
query(message)- Send a message and get a response (with action processing)clearHistory()- Clear conversation historygetHistory()- Get conversation historygetStats()- Get conversation statisticsexportHistory(format)- Export history in specified formatsetActionsEnabled(enabled)- Enable/disable action processinggetActionsEnabled()- Check if actions are enabled
AIAgent Class
Basic text-only agent without file/command capabilities.
Constructor
new AIAgent(options)Options:
model- AI model to usetemperature- Response creativitymaxTokens- Maximum response lengthsystem- System promptverbose- Enable verbose output
Methods
query(message)- Send a message and get a responseclearHistory()- Clear conversation historygetHistory()- Get conversation historygetStats()- Get conversation statisticsexportHistory(format)- Export history in specified format
Configuration Functions
getConfig()- Get current configurationupdateConfig(key, value)- Update configuration valueresetConfig()- Reset to default configurationexportConfig(filePath)- Export configuration to fileimportConfig(filePath)- Import configuration from filevalidateConfig(config)- Validate configurationgetAvailableModels()- Get list of available modelsgetConfigSchema()- Get configuration schema
Action Functions
File and command operations with built-in permission prompts:
readFile(filePath)- Read a file with permission checkwriteFile(filePath, content)- Write to a file with permission checkdeleteFile(filePath)- Delete a file with permission checkexecuteCommand(command, options)- Execute a command with permission checklistFiles(dirPath)- List files in a directoryfileExists(filePath)- Check if a file exists
Permission Functions
resetPermissions()- Reset all action permissionsshowPermissions()- Display current permission settingsACTION_TYPES- Constants for action typesPERMISSION_LEVELS- Constants for permission levels
API Key Functions
getOpenAIKey()- Get OpenAI API key (env var or config file)setOpenAIKey(key)- Set OpenAI API key in config filegetAnthropicKey()- Get Anthropic API key (env var or config file)setAnthropicKey(key)- Set Anthropic API key in config file
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For support, please open an issue on GitHub or contact us at support@profullstack.com.