src — features

Module: src-features Cohesion: 0.80 Members: 0

src — features

The src/features module serves as the central aggregation point for Code Buddy's "enhanced features." It provides a unified interface to access and manage various sophisticated functionalities, drawing inspiration from tools natively, OpenAI Codex CLI, Gemini CLI, and Aider.

This module does not contain the implementation logic for these features directly. Instead, it re-exports the core components (manager classes, utility functions, and types) from their respective sub-modules, making them easily discoverable and accessible throughout the application.

Purpose

The primary goals of src/features/index.ts are:

  1. Centralized Access: Provide a single entry point for consuming all enhanced features, simplifying imports and reducing boilerplate in other parts of the codebase.
  2. Feature Discovery: Clearly list and categorize the available features, making it easier for developers to understand Code Buddy's capabilities.
  3. Initialization & Management: Offer convenience functions (initializeEnhancedFeatures, resetAllEnhancedFeatures) to set up and tear down all feature managers consistently.
  4. Status Reporting: Provide a diagnostic function (getFeatureStatusSummary) for quick insights into the operational state of various features.

Architecture

The src/features module acts as a facade, importing specific components from dedicated sub-modules and re-exporting them. Each major feature typically follows a singleton pattern, managed by a dedicated "Manager" class, accessible via a get*Manager() function.

graph TD
    subgraph Features Module
        F[src/features/index.ts]
    end

    subgraph Sub-Modules
        C[checkpoints/persistent-checkpoint-manager.js]
        Cmd[commands/slash-commands.js]
        H[hooks/hook-system.js]
        S[security/security-modes.js]
        VI[input/voice-input-enhanced.js]
        TTS[input/text-to-speech.js]
        BT[tasks/background-tasks.js]
        Init[utils/init-project.js]
        MCP[mcp/config.js]
    end

    F --> C
    F --> Cmd
    F --> H
    F --> S
    F --> VI
    F --> TTS
    F --> BT
    F --> Init
    F --> MCP

Notice the aliasing pattern (_PersistentCheckpointManager as PersistentCheckpointManager). This is a common practice to clearly distinguish the imported symbol from the re-exported symbol, especially when the imported symbol might be used internally within index.ts (though not in this specific case for the managers).

Key Features and Exports

This module exports a comprehensive set of functionalities. For each, the primary manager class, its singleton getter, and a reset function (useful for testing) are typically exported, along with relevant types.

1. Persistent Checkpoints

Inspired by Gemini CLI, this feature allows saving and restoring the state of the project at various points.

2. Slash Commands

Advanced enterprise architecture for, this system allows defining and executing commands prefixed with a slash.

3. Hook System

Advanced enterprise architecture for, this allows custom logic to be injected at various points in the application lifecycle.

4. Security Modes

Inspired by OpenAI Codex CLI, this feature controls the operational security posture of Code Buddy.

5. Voice Input

Inspired by Aider, this enables interaction with Code Buddy using spoken language.

6. Text-to-Speech (TTS)

This feature integrates text-to-speech capabilities, often complementing voice input.

7. Background Tasks

Inspired by Codex CLI Cloud, this allows for asynchronous, non-blocking operations.

8. Project Initialization

Utilities for setting up a new Code Buddy project.

9. MCP Config Extensions

Utilities for managing the Code Buddy's Master Configuration Protocol (MCP) configuration.

Core Utility Functions

Beyond re-exporting individual feature components, src/features/index.ts provides several high-level functions for managing the entire suite of features:

initializeEnhancedFeatures(workingDirectory?: string)

This function initializes all singleton feature managers. It's the recommended way to set up Code Buddy's enhanced capabilities at application startup.

import { initializeEnhancedFeatures } from './features';

const { checkpoints, slashCommands, hooks, security, voiceInput, tasks } =
  initializeEnhancedFeatures('/path/to/project');

class="hl-cmt">// Now you can interact with the managers:
slashCommands.registerCommand({
  name: 'mycommand',
  description: 'A custom command',
  handler: async (args) => { /* ... */ }
});

resetAllEnhancedFeatures()

This function resets all feature managers to their initial state. It's primarily useful for testing scenarios to ensure a clean slate between tests.

import { resetAllEnhancedFeatures, getSlashCommandManager } from './features';

class="hl-cmt">// Perform some operations...
getSlashCommandManager().registerCommand(...);

class="hl-cmt">// Reset for the next test
resetAllEnhancedFeatures();

class="hl-cmt">// Now getSlashCommandManager() will return a fresh instance
class="hl-cmt">// with no registered commands from previous operations.

getFeatureStatusSummary()

This function generates a human-readable string summarizing the current status and configuration of all enhanced features. It's invaluable for debugging, diagnostics, or providing users with an overview of Code Buddy's active capabilities.

import { getFeatureStatusSummary } from './features';

console.log(getFeatureStatusSummary());
/* Example Output:
🌟 Code Buddy Enhanced Features
════════════════════════════════════════════════════════════━━━━
...
📸 Persistent Checkpoints
   • 0 checkpoints stored
   • Storage: /tmp/codebuddy-checkpoints
...
*/

Contribution Guidelines

When adding a new enhanced feature to Code Buddy:

  1. Create a Dedicated Module: Implement the feature in its own sub-module (e.g., src/new-feature/new-feature-manager.ts). Follow the singleton manager pattern if applicable.
  2. Export via src/features/index.ts: Import the necessary components from your new module into src/features/index.ts and re-export them.
    class="hl-cmt">// src/features/index.ts
    import {
      NewFeatureManager as _NewFeatureManager,
      getNewFeatureManager as _getNewFeatureManager,
      resetNewFeatureManager as _resetNewFeatureManager,
    } from '../new-feature/new-feature-manager.js';

    export {
      _NewFeatureManager as NewFeatureManager,
      _getNewFeatureManager as getNewFeatureManager,
      _resetNewFeatureManager as resetNewFeatureManager,
    };
    export type { NewFeatureConfig } from '../new-feature/new-feature-manager.js';

  1. Integrate with Utilities:

This approach ensures consistency, maintainability, and ease of use for all enhanced features within Code Buddy.