# CrystFlux Code Consolidation Script

A consolidation tool for enabling LLMs to comprehend the entire codebase at once. Integrates the core, boundary, and adapter hierarchies into one file each, minimizing API calls for request-based billing LLM providers. It also streamlines usage in web chat–style AI by reducing context re-entry.

**Primary Use Cases**
- Provide complete implementation understanding to LLMs in one pass
- Enable high-level analysis based on the whole codebase instead of fragmented questions
- Project structure understanding, design pattern analysis, and quality evaluation

**Usage Notes**
- Recommend disabling IDE file reference features (prevents unnecessary API requests)
- For token-based billing, allowing LLM autonomous exploration starting from any adapter may be more efficient

## Usage

### Single File Output
```bash
uv run scripts/consolidate.py --root src/crystflux/v1 --format single --output crystflux_core.txt
```

### Layered Output
```bash
uv run scripts/consolidate.py --root src/crystflux/v1 --format layered --output-dir consolidated/
```

## Options

- `--root`: Root directory containing core files (default: ../src/crystflux/v1)
- `--format`: Output format - `single` or `layered` (default: single)
- `--output`: Output file for single format
- `--output-dir`: Output directory for layered format

## Output

The script generates consolidated text files with:
- Section headers (## Core, ## Boundary, ## Adapters)
- File path comments (# File: path/to/file.py)
- Original file content
- Statistics including byte count and estimated token count

## Excluded Files

The following files are excluded from consolidation:
- `__init__.py` - Package initialization files
- `py.typed` - Type marker file
- `numpy_chain.pyi` - Stub files
- External integrations: `fastapi.py`, `numpy.py`, `pandas.py`, `pydantic.py`

## Token Estimation

The script provides token estimation ranges:
- Code lines: 3-4 tokens per line
- Comment lines: 1.5-2 tokens per line
- Total: Minimum and maximum estimated tokens

## Example Output

```
=== Statistics ===
Output: crystflux_core.txt
Byte count: 57,239 bytes
Estimated tokens: 3,885-5,180 tokens
Files processed: 17 files
Breakdown:
  Core: 8 files
  Boundary: 5 files
  Adapters: 4 files
```
