src — collaboration

Module: src-collaboration Cohesion: 0.80 Members: 0

src — collaboration

The src/collaboration module provides the foundational components for enabling both AI-driven and human-driven collaborative workflows within Code Buddy. It encompasses two distinct, yet conceptually related, collaboration paradigms:

  1. AI-centric Task Management: Facilitates structured multi-AI agent collaboration on development tasks, tracking progress, and generating work logs.
  2. Real-time Human Collaboration: Enables shared sessions between human users (and potentially AI agents), offering features like real-time synchronization, messaging, and moderated changes.

This module is crucial for orchestrating complex development efforts, whether by a team of AI agents following a defined methodology or by a mixed team of human developers and AI assistants working together in real-time.


AI Collaboration Manager (AIColabManager)

The AIColabManager class is designed to manage a structured, multi-AI collaboration workflow, adhering to a defined methodology (e.g., COLAB.md). Its primary role is to break down a project into manageable tasks, track their status, log AI agent activities, and provide context for ongoing work.

Purpose

AIColabManager acts as a central coordinator for AI agents, ensuring they work on well-defined tasks, record their progress, and can hand off work effectively. It maintains a persistent state of tasks and work logs, allowing for continuity across sessions and agents.

Key Concepts

Core Functionality

The AIColabManager provides a comprehensive set of methods for managing the AI collaboration lifecycle:

1. Data Persistence

The manager persists its state to JSON files within a .codebuddy directory in the working directory:

2. Task Management

3. Work Log Management

4. Handoff Management

5. COLAB.md Management

6. AI Instructions and Reporting

Task Lifecycle

The following Mermaid diagram illustrates the typical lifecycle of a ColabTask within the AIColabManager:

graph TD
    A[createTask] --> B{Task Status};
    B -- not_started --> C[getNextTask];
    C --> D[startTask];
    D --> E{Task Status};
    E -- in_progress --> F[updateTaskStatus];
    F --> G[completeTask];
    G --> H[addWorkLogEntry];
    H --> I[updateColabMd];
    I --> J[saveData];
    J --> K{Task Status};
    K -- completed --> L[getTasks];
    L --> M[getStatus];
    L --> N[listTasks];

Integration

AIColabManager is primarily integrated with the command handling system, specifically commands/handlers/colab-handler.ts. This handler translates user commands (e.g., /colab start, /colab log, /colab status) into calls to the AIColabManager methods.

It uses a singleton pattern (getAIColabManager) to ensure that only one instance of the manager exists per application context, maintaining a consistent state across different parts of the codebase.


Real-time Collaboration Managers

The collaboration module offers two classes for real-time, human-centric collaboration: CollaborativeSessionManager and TeamSessionManager. While they share conceptual similarities, TeamSessionManager is the more robust, feature-rich, and persistent solution, designed for comprehensive team collaboration. CollaborativeSessionManager appears to be a simpler, in-memory alternative or precursor.

CollaborativeSessionManager (Brief Overview)

This class provides a basic framework for real-time collaborative sessions. It manages:

It's suitable for simpler, ephemeral collaboration needs where persistence and advanced features like audit logs or external server synchronization are not required.

TeamSessionManager (Detailed Explanation)

The TeamSessionManager is a comprehensive system for managing persistent, real-time collaborative sessions for teams. It goes beyond basic synchronization to include robust member management, role-based permissions, audit logging, and secure data persistence.

Purpose

TeamSessionManager enables multiple users to work together on a shared Code Buddy workspace in real-time. It provides mechanisms for communication, shared context, moderated changes, and a complete history of session activities, making it ideal for complex team projects.

Key Concepts

Core Functionality

1. Member and Session Lifecycle

2. Collaboration Features

3. Permissions and Audit

4. Data Persistence and Encryption

5. Real-time Communication (WebSocket)

TeamSessionManager integrates with a WebSocket server to enable real-time updates across all connected clients.

6. Reporting and Utilities

WebSocket Communication Flow

graph TD
    A[TeamSessionManager] --> B{connectWebSocket};
    B --> C[WebSocket Server];
    C -- "open" --> D[ws.on('open')];
    D --> E[startHeartbeat];
    C -- "message" --> F[ws.on('message')];
    F --> G[handleWebSocketMessage];
    G -- "update local state" --> H[emit events];
    H --> I[Other components];
    J[shareMessage/updateCursorPosition/etc.] --> K[broadcastUpdate];
    K --> C;
    C -- "updates" --> F;

Integration

TeamSessionManager is designed to be the backbone for multi-user Code Buddy experiences. While the provided call graph shows extensive unit testing (team-session.test.ts), its integration with higher-level UI components or daemon processes would involve:

Similar to AIColabManager, TeamSessionManager also uses a singleton pattern (getTeamSessionManager) to ensure a single, consistent instance.


Module Exports (src/collaboration/index.ts)

The index.ts file serves as the public API for the collaboration module, re-exporting the main classes and their associated singleton functions:

This allows other parts of the codebase to import AIColabManager, CollaborativeSessionManager, getAIColabManager, getCollaborationManager, and their related types directly from src/collaboration.

Note on Overlapping Types: The comment in index.ts highlights that team-session.js has overlapping types with collaborative-mode.js. This suggests that TeamSessionManager is the more evolved and feature-complete solution for "team collaboration," and developers should generally prefer importing TeamSessionManager directly if its advanced features (persistence, encryption, audit logs, full WebSocket integration) are required, rather than relying solely on the simpler CollaborativeSessionManager exported via index.ts.


Integration Points & Execution Flows

The collaboration module is a critical piece for enabling Code Buddy's advanced capabilities.

In summary, the collaboration module provides a robust and flexible framework for managing complex development workflows, catering to both autonomous AI agents and interactive human teams, with a strong emphasis on persistence, real-time synchronization, and accountability.