TypeScript CLI AI Conversation App - Technical Plan
Plans a TypeScript CLI that runs an autonomous conversation between two AI personas via Ollama, from setup through testing.
What this file does
Plans a TypeScript CLI that runs an autonomous conversation between two AI personas via Ollama, from setup through testing.
When to use it
- Building a CLI tool that orchestrates multiple AI agents
- Structuring a TypeScript project with Ollama integration
- Designing a conversation system with distinct personas and state management
- Planning a phased implementation with clear success criteria
Assumes this stack
TypeScript CLI AI Conversation App - Technical Plan
Project Overview
A TypeScript CLI application that initiates and maintains an autonomous conversation between two AI personas using Ollama. The app starts with user input and then continues the conversation automatically until stopped.
Architecture Overview
Core Components
- CLI Interface - Handle user input and display conversation
- Conversation Manager - Orchestrate the conversation flow
- AI Client - Interface with Ollama API
- Persona Manager - Manage distinct AI personas
- State Manager - Track conversation history and context
Technology Stack
- Runtime: Node.js 22
- Language: TypeScript 5.x
- Package Manager: npm/pnpm
- CLI Framework: Commander.js or Inquirer.js
- AI Integration: Ollama JavaScript client
- Testing: Vitest
- Linting: ESLint with TypeScript plugin
- Formatting: Prettier
- Build Tool: tsx/tsup for development and production builds
Project Structure
ai-conversation-cli/
├── src/
│ ├── index.ts # Entry point
│ ├── cli/
│ │ ├── commands.ts # CLI command definitions
│ │ └── prompts.ts # User input handling
│ ├── conversation/
│ │ ├── manager.ts # Conversation orchestration
│ │ ├── personas.ts # AI persona definitions
│ │ └── history.ts # Conversation history management
│ ├── ai/
│ │ ├── client.ts # Ollama client wrapper
│ │ └── models.ts # AI model configurations
│ ├── utils/
│ │ ├── logger.ts # Logging utilities
│ │ └── formatter.ts # Output formatting
│ └── types/
│ └── index.ts # TypeScript type definitions
├── tests/
│ ├── unit/
│ └── integration/
├── .eslintrc.json
├── .prettierrc
├── tsconfig.json
├── vitest.config.ts
├── package.json
└── README.md
Implementation Plan
Phase 1: Project Setup
-
Initialize Project
- Create package.json with Node 22 engine requirement
- Install TypeScript and development dependencies
- Configure TypeScript (tsconfig.json)
- Set up ESLint with TypeScript rules
- Configure Prettier
- Set up Vitest for testing
-
Development Environment
- Configure hot reloading with tsx
- Set up debug configurations
- Create npm scripts for common tasks
Phase 2: Core Infrastructure
-
CLI Foundation
- Implement basic CLI structure using Commander.js
- Create initial prompt for user input using Inquirer.js
- Add graceful shutdown handling (Ctrl+C)
- Implement colored output using chalk
-
Ollama Integration
- Install and configure Ollama client
- Create abstraction layer for AI interactions
- Implement error handling for API failures
- Add configuration for different models
Phase 3: Conversation Logic
-
Persona System
- Define persona interface with characteristics
- Create at least two distinct personas
- Implement persona switching logic
- Add personality traits to responses
-
Conversation Manager
- Implement turn-based conversation flow
- Add context window management
- Create conversation history tracking
- Implement stopping conditions
-
State Management
- Track conversation state
- Implement conversation export functionality
- Add conversation replay capability
Phase 4: Features & Polish
-
Enhanced Features
- Add conversation speed control
- Implement conversation themes/topics
- Add conversation statistics
- Create conversation summaries
- Compact context into summaries when context window limit is approached
-
User Experience
- Add loading indicators
- Implement real-time typing effect
- Add conversation timestamps
- Create clear visual separation between speakers
Phase 5: Testing & Documentation
-
Testing Strategy
- Unit tests for core logic
- Integration tests for Ollama interaction
- Mock Ollama responses for testing
- Test CLI commands and user flows
-
Documentation
- API documentation
- User guide
- Configuration options
- Example conversations
Configuration Schema
interface Config {
ollama: {
baseUrl: string;
model: string;
temperature: number;
maxTokens: number;
};
conversation: {
maxTurns?: number;
turnDelay: number;
contextWindow: number;
};
personas: {
primary: PersonaConfig;
secondary: PersonaConfig;
};
}
interface PersonaConfig {
name: string;
personality: string;
speakingStyle: string;
interests: string[];
}
Key Dependencies
{
"dependencies": {
"commander": "^12.0.0",
"inquirer": "^9.2.0",
"ollama": "^0.5.0",
"chalk": "^5.3.0",
"ora": "^8.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.56.0",
"prettier": "^3.2.0",
"vitest": "^1.2.0",
"tsx": "^4.7.0",
"tsup": "^8.0.0"
}
}
Development Workflow
-
Local Development
npm run dev # Start with hot reload npm run lint # Run ESLint npm run format # Run Prettier npm run test # Run tests npm run test:watch # Run tests in watch mode -
Build & Distribution
npm run build # Build for production npm run start # Run production build
Error Handling Strategy
-
Ollama Connection Errors
- Retry logic with exponential backoff
- Graceful degradation
- Clear error messages
-
User Input Validation
- Validate conversation starters
- Handle empty inputs
- Provide helpful error messages
-
Runtime Errors
- Global error handler
- Logging to file option
- Debug mode for development
Performance Considerations
-
Memory Management
- Limit conversation history size
- Implement circular buffer for long conversations
- Clear old context periodically
-
API Optimization
- Implement request queuing
- Add response caching where appropriate
- Monitor API rate limits
Security Considerations
-
Input Sanitization
- Sanitize user inputs
- Prevent prompt injection
- Validate API responses
-
Configuration Security
- Support environment variables
- Secure API key storage
- No sensitive data in logs
Future Enhancements
-
Multiple AI Providers
- Support for OpenAI, Anthropic, etc.
- Provider abstraction layer
-
Advanced Features
- Multi-party conversations
- Voice input/output
- Web interface option
- Conversation branching
-
Analytics
- Conversation metrics
- Response quality tracking
- User behavior analytics
Success Criteria
-
Functionality
- Smooth conversation flow
- Distinct personas
- Reliable Ollama integration
- Graceful error handling
-
Code Quality
- 80%+ test coverage
- No ESLint errors
- Consistent formatting
- Well-documented code
-
User Experience
- < 2s response time
- Clear, intuitive interface
- Helpful error messages
- Smooth conversation display
Notes
- Ensure Ollama is installed and running locally
- Consider Docker setup for easier distribution
- Plan for different conversation styles and topics
- Think about conversation export formats (JSON, Markdown, etc.)
What's inside
5 phases, 10 components, 1 project tree, 2 config interfaces, 1 dependency list, 1 error strategy, 1 security section
Change this for your project
- Replace
danjdewhurst/ai-convowith your own repository name - Replace
ai-conversation-cliin the project tree with your project name - Replace
ollamamodel references like"model": "string"with your actual model name - Replace
"baseUrl": "string"with your Ollama server URL
Where it goes
Save in docs/ or the repository root. Gives agents and new contributors a map of the codebase.
Worth borrowing
- Separating persona definitions from conversation orchestration for testability
- Using a phased implementation plan with checkboxes to track progress
- Defining a configuration schema as a TypeScript interface before writing code
Related Documents
Design Document: BharatSeva AI
Describes a 10-agent AWS system that helps India's informal workers access government schemes via voice-first, serverless architecture.
OpenClaw Enterprise Transformation Plan
Transforms a single-user AI agent into a dual-mode platform supporting both viral open-source and Fortune 500 enterprise deployments through phased security, IAM, audit, multi-tenancy, and Kubernetes features.
Qwen Image and Edit: Open-sourcing and Local GGUF Generations with Lightning
Documents the Qwen-Image and Qwen-Image-Edit models, covering architecture, training, benchmarks, ComfyUI setup, and prompting techniques for local GGUF deployment.
University of Guelph Rocketry Club - Complete Tech Stack
Documents the full tech stack of a university rocketry club website with AI chatbot, member management, and project showcases.