i-self 0.4.3

Personal developer-companion CLI: scans your repos, indexes code semantically, watches your activity, and moves AI-agent sessions between tools (Claude Code, Aider, Goose, OpenAI Codex CLI, Continue.dev, OpenCode).
#![allow(dead_code)]

use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::fmt;
use uuid::Uuid;

/// Unique identifier for agents
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct AgentId(String);

impl AgentId {
    pub fn new() -> Self {
        Self(Uuid::new_v4().to_string())
    }
}

impl fmt::Display for AgentId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", &self.0[..8])
    }
}

impl Default for AgentId {
    fn default() -> Self {
        Self::new()
    }
}

/// Priority levels for agent tasks
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum TaskPriority {
    Low = 0,
    Normal = 1,
    High = 2,
    Critical = 3,
}

/// Types of agent tasks
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TaskType {
    ScanRepository,
    AnalyzeCode,
    ExtractPatterns,
    SummarizeWork,
    UpdateKnowledge,
    QueryKnowledge,
}

/// A task to be executed by an agent
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentTask {
    pub id: String,
    pub task_type: TaskType,
    pub priority: TaskPriority,
    pub payload: serde_json::Value,
    pub metadata: TaskMetadata,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TaskMetadata {
    pub source: Option<String>,
    pub target: Option<String>,
    pub tags: Vec<String>,
}

impl AgentTask {
    pub fn new(task_type: TaskType, payload: impl Serialize) -> Result<Self> {
        Ok(Self {
            id: Uuid::new_v4().to_string(),
            task_type,
            priority: TaskPriority::Normal,
            payload: serde_json::to_value(payload)?,
            metadata: TaskMetadata::default(),
        })
    }

    pub fn with_priority(mut self, priority: TaskPriority) -> Self {
        self.priority = priority;
        self
    }

    pub fn with_source(mut self, source: impl Into<String>) -> Self {
        self.metadata.source = Some(source.into());
        self
    }
}

/// Result from agent execution
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentResult {
    pub task_id: String,
    pub success: bool,
    pub data: serde_json::Value,
    pub summary: String,
    pub confidence: f32,
}

/// Core agent trait
#[async_trait]
pub trait Agent: Send + Sync {
    /// Execute the agent's task
    async fn execute(&self, context: super::AgentContext) -> Result<AgentResult>;
    
    /// Get agent name
    fn name(&self) -> &str;
    
    /// Get agent capabilities
    fn capabilities(&self) -> Vec<String>;
}