← all documents · raw markdown · 3 KB

KAI Refactoring Plan: Decoupling the God Function (v7.9.7)

> Codex v9.10.64 · Track 4 · 🔴 not started · Codex §Comprehensive Plans

> AI / low-credit: One extraction phase per session; compile-verify after each; on stop log Last worked / Next.

1. Objective

Refactor App::process_input in src/main.rs to improve maintainability, reduce cognitive load for developers, and prepare for multi-threaded cognitive processing.

2. Current State (P0 Risk)

3. Targeted Architecture

3.1 Extraction of Command Handler

Extract L3972-L4746 into App::handle_command(&mut self, input: &str) -> bool.

3.2 The Cognitive Pipeline

Create a new method App::run_cognitive_cycle(&mut self, input: &str).

Inside this, group module updates into logical "Phases":

1. Ingestion Phase: Amygdala, LexSem, Wernicke, Hub Ingest.

2. Retrieval Phase: RSHL Query, Hippocampus CA3, Predictor.

3. Limbic Processing Phase: Dopamine, VTA, Serotonin, Norepinephrine, ACC, Cortisol.

4. Social/ToM Phase: ToM, TPJ, STS, Mirror Neurons, Oxytocin.

5. Executive/Decision Phase: PFC, Basal Ganglia, OFC, Cerebellum.

6. Integration Phase: Claustrum, Global Workspace, Self-State Hub.

7. Synthesis Phase: Voice Engine, NLS, Broca.

3.3 State Encapsulation

Move module-specific logic (e.g., the complex RPE math) into the modules themselves where possible. process_input should ideally just be a series of self.module.update(...) calls.

4. Implementation Steps

Phase 1: Command Decoupling

Phase 2: Signal Integration

Phase 3: Function Shrinkage

5. Performance Gains

6. v7.9.7 Specific: Vocal Pipeline Decoupling