Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

openLittleTwo

πŸ€– AI-Powered Multi-Channel Gateway with Efficient Algorithm Architecture

A modern, extensible AI gateway platform that combines the efficient algorithm architecture from Claude Code with the comprehensive functionality of OpenClaw.

🎯 Project Overview

openLittleTwo is designed to be a high-performance, feature-rich AI assistant framework that:

From Claude Code (Algorithm & Architecture):

βœ… Efficient Task Management System - State machine-based task lifecycle with priority queues
βœ… Advanced Tool Interface Pattern - Factory pattern with permission system and lazy loading
βœ… Intelligent Query Engine - Context compaction, token budget optimization, streaming responses
βœ… Reactive State Management - Memoization, LRU cache, real-time updates
βœ… Modular Command System - Dynamic loading, feature flags, dead code elimination

From OpenClaw (Functionality):

βœ… Multi-Channel Integration - IRC, Slack, Telegram, Discord, Matrix, Line, WhatsApp, WebChat
βœ… Plugin System - Dynamic plugin loading, lifecycle management, hot-reload support
βœ… Gateway Server - WebSocket communication, authentication, event-driven architecture
βœ… CLI Toolchain - Comprehensive command-line interface with rich subcommands
βœ… Agent System - Sandbox execution, multi-agent coordination
βœ… Security Features - Permission model, audit logging, secret management

πŸ“ Project Structure

openLittleTwo/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/                    # Core Algorithm Architecture (from Claude Code)
β”‚   β”‚   β”œβ”€β”€ Task.ts             # Task state machine and lifecycle
β”‚   β”‚   β”œβ”€β”€ Tool.ts             # Tool interface and factory pattern
β”‚   β”‚   β”œβ”€β”€ QueryEngine.ts      # Intelligent query processing engine
β”‚   β”‚   └── StateManager.ts     # Reactive state management
β”‚   β”‚
β”‚   β”œβ”€β”€ channels/               # Multi-Channel Support (from OpenClaw)
β”‚   β”‚   └── BaseChannel.ts      # Abstract channel base class
β”‚   β”‚
β”‚   β”œβ”€β”€ plugins/                # Plugin System (from OpenClaw)
β”‚   β”‚   └── PluginSystem.ts     # Plugin loader and registry
β”‚   β”‚
β”‚   β”œβ”€β”€ gateway/                # Gateway Server (from OpenClaw)
β”‚   β”‚   └── GatewayServer.ts    # WebSocket server implementation
β”‚   β”‚
β”‚   β”œβ”€β”€ cli/                    # CLI Interface
β”‚   β”‚   β”œβ”€β”€ index.ts            # Entry point
β”‚   β”‚   └── CommandRouter.ts    # Command routing system
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/                  # Built-in Tools
β”‚   β”‚   └── builtinTools.ts     # Core tool implementations
β”‚   β”‚
β”‚   └── index.ts                # Main exports
β”‚
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── README.md

πŸš€ Quick Start

Installation

# Clone or navigate to the project directory
cd openLittleTwo

# Install dependencies
npm install

# Build the project
npm run build

Usage

Start Gateway Server

# Start on default port 8080
npm run cli -- start

# Custom port and host
npm run cli -- start --port 3000 --host localhost

Interactive Chat Mode

npm run cli -- chat

Manage Channels

# List all channels
npm run cli -- channel list

# Check channel status
npm run cli -- channel status

Manage Plugins

# List installed plugins
npm run cli -- plugin list

# Enable a plugin
npm run cli -- plugin enable my-plugin

# Disable a plugin
npm run cli -- plugin disable my-plugin

System Status

npm run cli -- status

Configuration

# View all config
npm run cli -- config list

# Get specific config value
npm run cli -- config get debug

# Set config value
npm run cli -- config set debug true

Task Management

# List active tasks
npm run cli -- task

# View task details
npm run cli -- task <task-id>

# Show all tasks including completed
npm run cli -- task --all

πŸ—οΈ Architecture Highlights

1. Task Management System (from Claude Code)

Implements a sophisticated task state machine:

type TaskType = 
  | 'local_bash'       // Shell commands
  | 'local_agent'      // AI agent tasks
  | 'remote_agent'     // Remote agent tasks
  | 'channel_message'  // Channel message handling
  | 'plugin_task'      // Plugin-specific tasks
  | 'gateway_request'  // WebSocket requests

type TaskStatus = 
  | 'pending' β†’ 'running' β†’ 'completed' | 'failed' | 'killed'
  | ↔ 'paused'
  | ↔ 'retrying'

Key Features:

  • Priority queue system (low/normal/high/critical)
  • Automatic retry mechanism with configurable limits
  • Concurrent task limiting
  • Graceful cancellation via AbortController
  • Task output persistence to disk

2. Tool Interface Pattern (from Claude Code)

Clean factory-based tool creation:

const MyTool = buildTool({
  name: 'my_tool',
  description: async () => 'Tool description',
  inputSchema: z.object({ /* Zod schema */ }),
  
  async call(args, context, canUseTool) {
    // Implementation
    return { data: result }
  },
  
  // Optional safety features
  isReadOnly: () => false,
  isDestructive: () => true,
  isConcurrencySafe: () => false,
})

Built-in Tools:

  • bash - Execute shell commands
  • read / write - File operations
  • grep - Pattern search
  • glob - File discovery

3. Query Engine (from Claude Code)

Intelligent context management:

  • Token Budget Optimization: Tracks usage per turn
  • Context Compaction: Automatically compresses long conversations
  • Tool Orchestration: Parallel tool execution with dependency resolution
  • Streaming Responses: Real-time output delivery
  • Error Recovery: Graceful degradation on failures

4. Channel Integration (from OpenClaw)

Multi-platform messaging support:

Channel Type Status Protocol
IRC βœ… Planned IRC protocol
Slack βœ… Planned Slack API
Telegram βœ… Planned Bot API
Discord βœ… Planned Discord.js
Matrix βœ… Planned Matrix SDK
Line βœ… Planned Line Messaging API
WhatsApp βœ… Planned Business API
WebChat βœ… Planned WebSocket
Webhook βœ… Planned HTTP endpoints

5. Plugin System (from OpenClaw)

Extensible plugin architecture:

// plugin.json
{
  "name": "my-plugin",
  "version": "1.0.0",
  "main": "index.ts"
}

// index.ts
import { definePlugin } from 'openlittletwo'

export default definePlugin((context) => ({
  tools: [/* custom tools */],
  channels: [/* channel integrations */],
  hooks: {
    onMessage: async (message) => { /* ... */ },
  }
}))

Plugin Capabilities:

  • Provide custom tools
  • Add new channel integrations
  • Register CLI commands
  • Hook into message lifecycle
  • Manage own configuration

6. Gateway Server (from OpenClaw)

Real-time communication hub:

const gateway = new GatewayServer({
  port: 8080,
  host: '0.0.0.0',
  authSecret: process.env.AUTH_SECRET,
})

await gateway.start()

// Handle events
gateway.on('client_connected', (event) => {
  console.log('New client:', event.clientId)
})

// Send messages
gateway.sendToClient(clientId, {
  type: 'response',
  payload: { text: 'Hello!' }
})

// Broadcast to all authenticated clients
gateway.broadcast({
  type: 'event',
  payload: { type: 'notification', data: {} }
})

Features:

  • WebSocket connection management
  • Client authentication
  • Heartbeat monitoring
  • Message broadcasting
  • Event-driven architecture
  • Connection limits

πŸ”§ Development

Adding New Tools

Create a file in src/tools/:

// src/tools/my-tool.ts
import { z } from 'zod'
import { buildTool } from '../core/Tool'

export const MyTool = buildTool({
  name: 'my_tool',
  inputSchema: z.object({ query: z.string() }),
  
  async call(args) {
    return { data: `Result for: ${args.query}` }
  },
  
  isReadOnly: () => true,
})

Register in src/tools/builtinTools.ts:

export const getBuiltinTools = (): Tools => [
  // ... existing tools
  MyTool,
]

Adding New Channels

Extend BaseChannel:

// src/channels/my-channel.ts
import { BaseChannel, ChannelConfig } from './BaseChannel'

export class MyChannel extends BaseChannel {
  readonly type = 'custom' as const
  readonly name = 'My Channel'

  async connect() {
    // Initialize connection
    this.setStatus('connected')
  }

  async disconnect() {
    // Cleanup
    this.setStatus('disconnected')
  }

  async sendMessage(userId, content) {
    // Send message
  }

  async handleMessage(message) {
    // Process incoming message
  }
}

Creating Plugins

See plugins/ directory structure:

my-plugin/
β”œβ”€β”€ plugin.json          # Manifest
β”œβ”€β”€ index.ts            # Entry point
β”œβ”€β”€ tools/              # Custom tools
└── README.md           # Documentation

πŸ“Š Performance Optimizations

Inherited from Claude Code's efficient design:

  1. Memoization: Expensive computations cached automatically
  2. Lazy Loading: Modules loaded on-demand to reduce startup time
  3. Dead Code Elimination: Feature flags remove unused code paths
  4. LRU Caching: Intelligent cache eviction prevents memory bloat
  5. Parallel Execution: Independent tasks run concurrently
  6. Streaming I/O: Large results streamed to reduce memory pressure
  7. Context Compression: Long conversations summarized efficiently

πŸ”’ Security Model

Permission system inspired by Claude Code:

  • Tool-level permissions: Each tool declares safety properties
  • Input validation: Zod schemas enforce strict types
  • Sandboxing: Agent execution isolated from host
  • Audit logging: All actions recorded for compliance
  • Rate limiting: Prevent abuse and resource exhaustion
  • Authentication: Secure client verification

🌐 Integrations

Supported Platforms (from OpenClaw)

  • Messaging: Slack, Telegram, Discord, IRC, Matrix, Line, WhatsApp
  • Voice: TTS/STT integration planned
  • Media: Image/audio/video processing pipeline
  • Web: Browser automation, web scraping
  • Code: Git integration, IDE extensions
  • Cloud: AWS, GCP, Azure adapters

AI Providers

Pluggable AI backend:

  • OpenAI API
  • Anthropic Claude
  • Local models (Ollama, llama.cpp)
  • Custom providers via plugin interface

πŸ“ API Reference

Detailed API documentation available in source code TypeScript definitions.

Key exports:

  • Task - Task management types and utilities
  • Tool / buildTool - Tool interface and factory
  • QueryEngine - Query processing engine
  • StateManager - Global state management
  • BaseChannel / ChannelRegistry - Channel abstraction
  • GatewayServer - WebSocket gateway
  • PluginLoader - Plugin system
  • CLICommandRouter - CLI framework

🀝 Contributing

Contributions welcome! Please read our guidelines:

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing)
  5. Open Pull Request

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

  • Claude Code - For the elegant algorithm architecture and design patterns
  • OpenClaw - For the comprehensive multi-channel gateway functionality
  • The open-source community for inspiration and tools

Built with ❀️ using algorithms from Claude Code + functionality from OpenClaw

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages