Code-Reducer is a command-line orchestration tool that transforms source code into structured documentation using a Map-Reduce synthesis pattern. The system operates within a local boundary, interacting with the local filesystem and local Large Language Models (LLMs) via the api/chat protocol.
The system architecture is composed of three primary internal layers and external configuration files:
Acts as the entry point and lifecycle controller.
- Validation: Performs environment checks (git repository existence and working directory identification).
- State Management: Evaluates
engine.IsInitializedto determine if the operation is a fullinitor an incrementalupdate. - Dispatch: Validates the environment and passes the
config.Configto theenginepackage.
Manages hierarchical parameter resolution with the following precedence:
CLI flags Environment variables .code-reducer.yaml System defaults.
- Key Parameters:
ModelID,OllamaBaseURL,OllamaNumCtx, andDocsDir. - Extraction Steps: Defines
ExtractionStepobjects mapping specific phases of the synthesis pipeline to prompt templates.
The core computational component responsible for hierarchical content reduction.
-
Discovery & Mapping: Files are mapped into a
DirNodetree structure. -
Change Detection: Uses
MetadataCacheto compare current file SHA256 fingerprints against previous states. Changes propagate "Affected" status up theDirNodetree. -
Hierarchical Synthesis:
-
Leaf Processing: Uses
Chunkingfor segments exceeding the context window (using a0.75contextWindowAllocRatio). -
Recursion: If a segment is oversized, recursive reduction is applied. Recursion terminates if the output size is
$\ge$ 95% of the input. -
Aggregation: Summaries are aggregated from file-level
$\rightarrow$ module-level$\rightarrow$ directory-level.
-
Leaf Processing: Uses
- Documentation Rendering:
mkdocs.ymlfacilitates the deployment of the generated wiki, pulling frontend assets fromcdn.jsdelivr.netandcdnjs.cloudflare.com. - Static Analysis:
sonar-project.propertiesmanages the exclusion of test files and dependencies during analysis and consumescoverage.outreports.
| Mode | Command | Purpose |
|---|---|---|
| Initialization | init |
Performs a full repository scan and generates initial Markdown documentation. |
| Incremental | update |
Analyzes only files where SHA256 fingerprints have changed relative to the MetadataCache. |
To function, the environment must provide:
- Ollama Endpoint: A running local LLM instance accessible via the configured
OllamaBaseURL. - Valid Model: A
ModelIDconfigured in theConfigstruct. - Context Window: An integer
OllamaNumCtxgreater than zero.
- Documentation: Synthesized Markdown files are written to the path defined in
DocsDir. - State:
MetadataCache(JSON) is maintained in thedocsDirto enable incremental updates.