Skip to content

Commit 52bc0f3

Browse files
committed
Update documentation
1 parent 9ea00c0 commit 52bc0f3

5 files changed

Lines changed: 258 additions & 35 deletions

File tree

CLAUDE.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5+
## Rules
6+
7+
- Always update the `CLAUDE.md`, `README.md`, `docs/`, and `spec/` files when there are significant changes to the codebase or architecture.
8+
59
## Common Commands
610

711
```bash
@@ -17,7 +21,11 @@ code-lod init # Initialize in project directory
1721
code-lod generate # Generate descriptions
1822
code-lod status # Check description freshness
1923
code-lod validate # Validate descriptions
24+
code-lod update # Update stale descriptions
2025
code-lod read # Output descriptions in LLM-consumable format
26+
code-lod config set-model # Configure LLM models per scope
27+
code-lod install-hook # Install git pre-commit hook
28+
code-lod clean # Remove all code-lod data
2129

2230
# Documentation
2331
uv run mkdocs build # Build documentation
@@ -36,7 +44,7 @@ Code LoD is a CLI tool that generates and manages code descriptions at different
3644

3745
3. **Staleness Tracking** (`staleness.py`): `StalenessTracker` uses the hash index to determine if descriptions need regeneration.
3846

39-
4. **Generation** (`llm/`): Abstract `BaseGenerator` interface for LLM providers. Currently uses mock generator; real providers (OpenAI, Anthropic, Ollama) are planned.
47+
4. **Generation** (`llm/description_generator/`): LLM provider implementations (OpenAI, Anthropic, Ollama, Mock) with auto-detection from environment variables and scope-specific model selection.
4048

4149
5. **Storage** (`db.py`, `lod_file/`): Dual storage system:
4250
- SQLite database (`hash_index.db`) for metadata and caching
@@ -55,25 +63,26 @@ src/code_lod/
5563
├── cli/ # Typer CLI commands (one file per command)
5664
│ ├── __init__.py # Main app entry point
5765
│ ├── clean.py # Clean all code-lod data
58-
│ ├── config.py # Configuration management
66+
│ ├── config.py # Configuration management (config, set-model commands)
5967
│ ├── generate.py # Generate descriptions
60-
│ ├── hooks.py # Git hooks installation
68+
│ ├── hooks.py # Git hooks installation/removal
6169
│ ├── init.py # Initialize code-lod
6270
│ ├── read.py # Output descriptions
6371
│ ├── status.py # Check freshness status
6472
│ ├── update.py # Update stale descriptions
6573
│ └── validate.py # Validate descriptions
66-
├── config.py # Paths management
74+
├── config.py # Configuration and paths management
6775
├── db.py # SQLite hash index
6876
├── hashing.py # AST hash computation
6977
├── models.py # Pydantic data models
7078
├── staleness.py # StalenessTracker
7179
├── llm/
7280
│ ├── __init__.py
73-
│ └── description_generator/ # LLM generator abstraction
74-
│ ├── generator.py # BaseGenerator interface
81+
│ └── description_generator/ # LLM generator implementations
82+
│ ├── generator.py # BaseGenerator, Provider enum, get_generator()
7583
│ ├── anthropic.py # Anthropic Claude provider
7684
│ ├── openai.py # OpenAI provider
85+
│ ├── ollama.py # Ollama local models provider
7786
│ └── mock.py # Mock generator for testing
7887
├── parsers/ # BaseParser, tree-sitter implementations
7988
└── lod_file/ # .lod file read/write/comment parsing
@@ -90,8 +99,18 @@ src/code_lod/
9099

91100
### Configuration
92101

93-
Stored in `.code-lod/config.json` with supported languages. Paths are resolved relative to project root via `Paths` dataclass.
102+
Stored in `.code-lod/config.json`:
103+
- `languages`: List of supported languages
104+
- `provider`: LLM provider (openai, anthropic, ollama, mock)
105+
- `model_settings`: Hierarchical model configuration per scope
106+
- Supports different models for different scopes (project, package, module, class, function)
107+
108+
Provider auto-detection: Checks `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` environment variables. Falls back to mock if none found.
109+
110+
Paths are resolved relative to project root via `Paths` dataclass.
94111

95112
### Git Hooks
96113

97-
The `install_hook` command creates pre-commit hooks that run `code-lod validate --fail-on-stale` to ensure descriptions stay fresh.
114+
The `install-hook` command creates pre-commit hooks that run `code-lod validate --fail-on-stale` to ensure descriptions stay fresh. Use `uninstall-hook` to remove the hook.
115+
116+
Supports both `pre-commit` and `pre-push` hook types via `--hook-type` option.

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ Reading a project's README and source code works for small projects, but becomes
7070
| `validate` | Validate description freshness |
7171
| `update` | Update stale descriptions |
7272
| `read` | Output descriptions in LLM-consumable format |
73+
| `config` | Get or set configuration values |
74+
| `config set-model` | Configure LLM models per scope |
7375
| `install-hook` | Install git pre-commit hook |
76+
| `uninstall-hook` | Remove git hook |
7477
| `clean` | Remove all code-lod data |
7578

7679
## Architecture
@@ -80,7 +83,7 @@ Code LoD generates, manages, and updates code descriptions through a multi-layer
8083
1. **Parsing** (`parsers/`): Tree-sitter based parsers extract code entities (functions, classes, modules) with AST hashes
8184
2. **Hashing** (`hashing.py`): AST hashes are computed on normalized source to detect semantic changes
8285
3. **Staleness Tracking** (`staleness.py`): Uses the hash index to determine if descriptions need regeneration
83-
4. **Generation** (`llm/description_generator/`): Abstract `BaseGenerator` interface for LLM providers (Anthropic, OpenAI, Mock)
86+
4. **Generation** (`llm/description_generator/`): LLM provider implementations (OpenAI, Anthropic, Ollama, Mock) with auto-detection and scope-specific model selection
8487
5. **Storage** (`db.py`, `lod_file/`): Dual storage system with SQLite database and `.lod` files
8588

8689
### Storage
@@ -92,6 +95,46 @@ Code LoD uses a dual storage system:
9295

9396
Descriptions are organized by hierarchical scope: `project` > `package` > `module` > `class` > `function`.
9497

98+
## LLM Provider Configuration
99+
100+
Code LoD supports multiple LLM providers for generating descriptions:
101+
102+
### Supported Providers
103+
104+
- **OpenAI**: GPT-4, GPT-4o, GPT-3.5-turbo
105+
- **Anthropic**: Claude Sonnet, Claude Haiku, Claude Opus
106+
- **Ollama**: Local models (e.g., llama2, mistral, codellama)
107+
- **Mock**: Placeholder descriptions for testing (no API key required)
108+
109+
### Configuration
110+
111+
Set your API key via environment variables:
112+
113+
```bash
114+
# For OpenAI
115+
export OPENAI_API_KEY="sk-..."
116+
117+
# For Anthropic
118+
export ANTHROPIC_API_KEY="sk-ant-..."
119+
```
120+
121+
Code LoD auto-detects the available provider from environment variables. Configure different models for different scopes:
122+
123+
```bash
124+
# Set model for all scopes
125+
code-lod config set-model --provider openai --model gpt-4o
126+
127+
# Set model for specific scope
128+
code-lod config set-model --scope function --provider openai --model gpt-4o
129+
code-lod config set-model --scope project --provider anthropic --model claude-sonnet
130+
```
131+
132+
For Ollama (local models):
133+
134+
```bash
135+
code-lod config set-model --provider ollama --model codellama
136+
```
137+
95138
## Development
96139

97140
```bash

docs/architecture.md

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,23 @@ Code LoD uses a modular architecture with clear separation of concerns:
3939

4040
## Components
4141

42-
### CLI Layer (`cli.py`)
43-
44-
Built with [Typer](https://typer.tiangolo.com/), the CLI provides all user-facing commands:
45-
46-
| Command | Handler |
47-
|---------|---------|
48-
| `init` | Creates project structure and config |
49-
| `generate` | Parses code, generates descriptions |
50-
| `status` | Reports freshness status |
51-
| `validate` | Checks for stale descriptions |
52-
| `update` | Regenerates stale descriptions |
53-
| `read` | Outputs descriptions for LLMs |
54-
| `install-hook` | Installs git hooks |
42+
### CLI Layer (`cli/`)
43+
44+
Built with [Typer](https://typer.tiangolo.com/), the CLI provides all user-facing commands. Each command is implemented in its own module:
45+
46+
| Command | Handler | Description |
47+
|---------|---------|-------------|
48+
| `init` | `cli/init.py` | Creates project structure and config |
49+
| `generate` | `cli/generate.py` | Parses code, generates descriptions |
50+
| `status` | `cli/status.py` | Reports freshness status |
51+
| `validate` | `cli/validate.py` | Checks for stale descriptions |
52+
| `update` | `cli/update.py` | Regenerates stale descriptions |
53+
| `read` | `cli/read.py` | Outputs descriptions for LLMs |
54+
| `config` | `cli/config.py` | Get/set configuration values |
55+
| `config set-model` | `cli/config.py` | Configure LLM models per scope |
56+
| `install-hook` | `cli/hooks.py` | Installs git hooks |
57+
| `uninstall-hook` | `cli/hooks.py` | Removes git hooks |
58+
| `clean` | `cli/clean.py` | Removes all code-lod data |
5559

5660
### Parser Layer (`parsers/`)
5761

@@ -166,22 +170,67 @@ def authenticate_user(username: str, password: str) -> str:
166170
- **SQLite**: Fast lookups, caching, revert detection
167171
- **.lod files**: Human-readable, version-controlled, LLM-consumable
168172

169-
### LLM Integration (`llm/`)
173+
### LLM Integration (`llm/description_generator/`)
174+
175+
Abstract interface for description generation with multiple provider implementations:
176+
177+
```python
178+
class Provider(str, Enum):
179+
OPENAI = "openai"
180+
ANTHROPIC = "anthropic"
181+
OLLAMA = "ollama"
182+
MOCK = "mock"
183+
184+
def get_generator(
185+
provider: Provider | None = None,
186+
model: str | None = None,
187+
) -> DescriptionGenerator:
188+
"""Get a description generator instance."""
189+
```
190+
191+
#### Provider Implementations
192+
193+
**OpenAI** (`openai.py`): GPT-4, GPT-4o, GPT-3.5-turbo via `openai` package
194+
195+
**Anthropic** (`anthropic.py`): Claude Sonnet, Claude Haiku, Claude Opus via `anthropic` package
196+
197+
**Ollama** (`ollama.py`): Local models (codellama, mistral, llama2, etc.) via `ollama` package
170198

171-
Abstract interface for description generation:
199+
**Mock** (`mock.py`): Placeholder descriptions for testing (no API key required)
200+
201+
#### Auto-Detection
202+
203+
The `get_generator()` function auto-detects providers from environment variables:
204+
1. Checks `ANTHROPIC_API_KEY` → uses Anthropic
205+
2. Checks `OPENAI_API_KEY` → uses OpenAI
206+
3. Falls back to Mock generator
207+
208+
#### Scope-Specific Models
209+
210+
Configure different models for different hierarchical scopes:
211+
212+
```bash
213+
code-lod config set-model --scope function --provider openai --model gpt-4o
214+
code-lod config set-model --scope project --provider anthropic --model claude-sonnet
215+
```
216+
217+
#### Base Generator Interface
172218

173219
```python
174-
class BaseGenerator(ABC):
220+
class DescriptionGenerator(ABC):
175221
@abstractmethod
176-
def generate(self, entity: ParsedEntity) -> str:
222+
def generate(self, entity: ParsedEntity, context: str | None = None) -> str:
177223
"""Generate a description for a code entity."""
178-
```
179224

180-
Currently uses a mock generator. Planned providers:
225+
@abstractmethod
226+
def generate_batch(self, entities: list[ParsedEntity], context: str | None = None) -> list[str]:
227+
"""Generate descriptions for multiple entities."""
228+
```
181229

182-
- OpenAI (GPT-4, o1)
183-
- Anthropic (Claude)
184-
- Ollama (local models)
230+
The `BaseLLMDescriptionGenerator` provides:
231+
- Prompt templates for function, class, and module scopes
232+
- Source truncation for large code blocks
233+
- Automatic fallback to mock on API errors
185234

186235
## Data Models
187236

@@ -215,15 +264,31 @@ class ParsedEntity:
215264
```
216265
src/code_lod/
217266
├── __init__.py
218-
├── cli.py # Main CLI commands
219-
├── config.py # Configuration management
267+
├── __main__.py # Entry point
268+
├── cli/ # CLI commands (one per file)
269+
│ ├── __init__.py # Main app, command registration
270+
│ ├── clean.py # Clean command
271+
│ ├── config.py # Config and set-model commands
272+
│ ├── generate.py # Generate command
273+
│ ├── hooks.py # install-hook, uninstall-hook
274+
│ ├── init.py # Init command
275+
│ ├── read.py # Read command
276+
│ ├── status.py # Status command
277+
│ ├── update.py # Update command
278+
│ └── validate.py # Validate command
279+
├── config.py # Configuration and paths management
220280
├── db.py # SQLite database layer
221281
├── hashing.py # AST hash computation
222282
├── models.py # Pydantic data models
223283
├── staleness.py # Staleness tracking
224284
├── llm/ # LLM integration
225285
│ ├── __init__.py
226-
│ └── generator.py # Base generator interface
286+
│ └── description_generator/
287+
│ ├── generator.py # Base classes, Provider enum, get_generator()
288+
│ ├── anthropic.py # Anthropic Claude provider
289+
│ ├── openai.py # OpenAI provider
290+
│ ├── ollama.py # Ollama local models provider
291+
│ └── mock.py # Mock generator for testing
227292
├── parsers/ # Code parsers
228293
│ ├── __init__.py
229294
│ ├── base.py # BaseParser interface

docs/commands.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,5 +379,49 @@ code-lod config languages
379379
code-lod config languages python,javascript
380380
```
381381

382+
---
383+
384+
## `config set-model`
385+
386+
Configure LLM models per scope.
387+
388+
```bash
389+
code-lod config set-model [OPTIONS]
390+
```
391+
392+
### Options
393+
394+
| Option | Short | Default | Description |
395+
|--------|-------|---------|-------------|
396+
| `--scope` | `-s` | `None` | Scope to configure (project, package, module, class, function) |
397+
| `--provider` | `-p` | `None` | LLM provider (openai, anthropic, ollama, mock) |
398+
| `--model` | `-m` | `None` | Model name |
399+
400+
### Provider Options
401+
402+
| Provider | Environment Variable | Default Models |
403+
|----------|---------------------|----------------|
404+
| `openai` | `OPENAI_API_KEY` | gpt-4o, gpt-4-turbo, gpt-3.5-turbo |
405+
| `anthropic` | `ANTHROPIC_API_KEY` | claude-sonnet, claude-haiku, claude-opus |
406+
| `ollama` | (none) | codellama, mistral, llama2, etc. |
407+
| `mock` | (none) | (no API key required) |
408+
409+
### Examples
410+
411+
```bash
412+
# Set model for all scopes
413+
code-lod config set-model --provider openai --model gpt-4o
414+
415+
# Set different models for different scopes
416+
code-lod config set-model --scope function --provider openai --model gpt-4o
417+
code-lod config set-model --scope project --provider anthropic --model claude-sonnet
418+
419+
# Use Ollama for local generation
420+
code-lod config set-model --provider ollama --model codellama
421+
422+
# Use mock for testing (no API key)
423+
code-lod config set-model --provider mock
424+
```
425+
382426
!!! note
383-
This command is not yet fully implemented.
427+
If no provider is specified, Code LoD auto-detects from environment variables (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`).

0 commit comments

Comments
 (0)