Crates.io | ai-session |
lib.rs | ai-session |
version | 0.3.4 |
created_at | 2025-06-24 02:11:09.375434+00 |
updated_at | 2025-06-24 02:11:09.375434+00 |
description | AI-optimized terminal session management library |
homepage | |
repository | https://github.com/nwiizo/ccswarm |
max_upload_size | |
id | 1723804 |
size | 544,536 |
AI-optimized terminal session management with 93% token savings and multi-agent coordination
AI-Session is a next-generation terminal session manager designed specifically for AI agents and modern development workflows. It replaces traditional terminal multiplexers like tmux with intelligent features for AI context management, multi-agent coordination, and semantic output processing.
🎯 Complete tmux replacement • 93% token savings • Cross-platform PTY • MCP protocol
Add to your Cargo.toml
:
[dependencies]
ai-session = "0.1"
use ai_session::{SessionManager, SessionConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create session manager
let manager = SessionManager::new();
// Configure AI-optimized session
let mut config = SessionConfig::default();
config.enable_ai_features = true;
config.context_config.max_tokens = 4096;
// Create and use session
let session = manager.create_session_with_config(config).await?;
session.start().await?;
// Execute commands
session.send_input("echo 'Hello, AI!'\n").await?;
let output = session.read_output().await?;
println!("Output: {}", String::from_utf8_lossy(&output));
// Get AI-optimized context
let context = session.get_ai_context().await?;
println!("Session ID: {}", context.session_id);
session.stop().await?;
Ok(())
}
use ai_session::coordination::{CoordinationBus, Message};
// Create shared coordination bus
let bus = Arc::new(RwLock::new(CoordinationBus::new()));
// Create multiple agent sessions
let frontend_session = manager.create_session(frontend_config).await?;
let backend_session = manager.create_session(backend_config).await?;
// Agents can communicate via the bus
bus.write().await.broadcast(Message {
msg_type: MessageType::TaskAssignment,
content: json!({"task": "implement feature"}),
// ...
}).await?;
ai-session/
├── core/ # Core session management
├── context/ # AI context optimization
├── output/ # Intelligent output parsing
├── coordination/ # Multi-agent communication
├── observability/ # Metrics and tracing
├── security/ # Security and isolation
├── persistence/ # Session state storage
└── integration/ # External tool integration
Install the CLI:
cargo install ai-session --features cli
Usage:
# Create a new AI session
ai-session create --name dev --ai-context
# List sessions
ai-session list --detailed
# Execute command in session
ai-session exec dev "cargo build" --capture
# Show AI context
ai-session context dev --lines 50
# Migrate from tmux
ai-session migrate --all
The library automatically manages context to stay within token limits:
let context = session.get_context().await?;
context.add_message("user", "Run the test suite").await?;
// Automatic summarization when approaching limits
if context.approaching_limit() {
context.summarize_oldest().await?;
}
let analysis = session.analyze_output().await?;
println!("Detected: {:?}", analysis.patterns);
println!("Entities: {:?}", analysis.entities);
println!("Suggested actions: {:?}", analysis.suggestions);
// Track AI decision making
let tracer = session.get_tracer();
tracer.record_decision("Choosing test framework", json!({
"options_considered": ["pytest", "unittest"],
"choice": "pytest",
"reasoning": "Better async support"
})).await?;
// Performance profiling
let profile = session.get_performance_profile().await?;
println!("Token usage: {}", profile.token_metrics);
println!("Latency: {:?}", profile.operation_latencies);
For teams currently using tmux:
use ai_session::integration::TmuxCompatLayer;
let tmux = TmuxCompatLayer::new();
// List existing tmux sessions
let sessions = tmux.list_tmux_sessions().await?;
// Migrate a session
let migration = MigrationHelper::new();
let result = migration.migrate_tmux_session("dev-session").await?;
// Creates equivalent ai-session with captured state
let ai_session = manager.create_from_migration(result).await?;
Benchmarks on typical AI workloads:
The library implements defense-in-depth:
📚 Comprehensive Documentation Available:
Contributions are welcome! Please see CONTRIBUTING.md.
Recent benchmarks on typical AI workloads:
Licensed under MIT - see LICENSE file.
Developed as part of the ccswarm project for AI agent orchestration.