src — learning

Module: src-learning Cohesion: 0.80 Members: 0

src — learning

The src/learning module provides a Persistent Learning System designed for continuous improvement of the application's intelligence and effectiveness. It tracks various operational aspects, learns from them, and generates insights to guide future actions. All collected data is persisted to an SQLite database, allowing for long-term learning and adaptation.

Purpose and Features

The primary goal of this module is to enable the system to learn from its own operations and interactions. This includes:

Core Component: PersistentLearning Class

The heart of this module is the PersistentLearning class. It acts as the central orchestrator for all learning activities, managing data recording, retrieval, and analysis across different domains.

Overview

The PersistentLearning class:

Singleton Access

To ensure a single, consistent learning state across the application, PersistentLearning is implemented as a singleton.

Learning Domains

The PersistentLearning class categorizes its learning into three main domains: Repair, Conventions, and Tools.

1. Repair Learning

This domain focuses on understanding and improving the process of fixing errors.

2. Convention Detection

This domain aims to identify and track common coding patterns and conventions within specific projects.

3. Tool Effectiveness Tracking

This domain monitors the usage and performance of various internal tools.

Data Persistence and Database Interaction

All learning data is persisted to an SQLite database. The PersistentLearning module interacts with the database layer in two primary ways:

  1. AnalyticsRepository: For repair_learning and tool_stats data, PersistentLearning delegates to getAnalyticsRepository(). This repository likely encapsulates specific SQL operations for these domains.
  2. Direct DatabaseManager Access: For conventions data and some specific statistical queries (e.g., getRepairStats's topStrategies query), PersistentLearning directly uses getDatabaseManager().getDatabase() to execute SQL statements. This allows for more flexible and domain-specific queries not covered by the AnalyticsRepository.

Insights and Reporting

Beyond raw data, the module provides mechanisms to synthesize information:

Key Internal Logic: Error Normalization

A critical private method is normalizeErrorPattern(error: string). This function preprocesses raw error messages by removing variable elements like line numbers, file paths, and specific identifiers. This ensures that different occurrences of the same underlying error are recognized as such, allowing for effective pattern matching and learning in the repair domain.

System Overview

graph TD
    subgraph Learning Module
        PL[PersistentLearning]
        getPL(getPersistentLearning)
    end

    subgraph Database Layer
        AR[AnalyticsRepository]
        DM[DatabaseManager]
    end

    subgraph Consumers
        IM[Integration Module]
        BA[BaseAgent]
        Tests[Tests]
    end

    getPL --> PL
    PL -- uses --> AR
    PL -- uses --> DM

    IM -- calls --> getPL
    IM -- calls --> PL::recordRepairAttempt
    IM -- calls --> PL::getBestRepairStrategies
    IM -- calls --> PL::recordToolUsage
    IM -- calls --> PL::getStats

    BA -- calls --> PL::formatStats

    Tests -- calls --> PL::getToolStats
    Tests -- calls --> PL::getRepairStats

Integration Points and Usage

The PersistentLearning module is designed to be integrated throughout the application where learning opportunities arise.

By centralizing learning logic in this module, the system can continuously adapt and improve its performance based on real-world interactions, making it more robust and intelligent over time.