|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with this LLM plugin repository. |
4 | 4 |
|
5 | | -## Plugin Development Commands |
| 5 | +## Project Overview |
6 | 6 |
|
7 | | -Use `llm install .` to install LLM plugins from the current directory (not pip install). |
| 7 | +`llm-tools-patch` is an LLM plugin that provides comprehensive text file manipulation tools through a unified `Patch` toolbox. The plugin is designed to give AI agents safe, controlled access to common file operations. |
8 | 8 |
|
9 | | -Test the plugin after installation: |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Environment Setup |
| 12 | +```bash |
| 13 | +make dev-setup # Complete development environment setup |
| 14 | +source .venv/bin/activate # Activate virtual environment |
| 15 | +``` |
| 16 | + |
| 17 | +### Plugin Installation & Testing |
10 | 18 | ```bash |
11 | | -llm tools # List available tools to verify registration |
12 | | -llm prompt -m gpt-4o-mini "Please read and modify this config file" --tool Patch # Test functionality |
| 19 | +llm install . # Install plugin from current directory (not pip install) |
| 20 | +llm tools # Verify plugin registration - should show Patch tools |
| 21 | +llm prompt "Read the README.md file" --tool Patch_patch_read README.md # Test functionality |
| 22 | +``` |
| 23 | + |
| 24 | +### Code Quality & Testing |
| 25 | +```bash |
| 26 | +make test # Run comprehensive test suite |
| 27 | +make lint # Run ruff linting |
| 28 | +make format # Format code with ruff |
| 29 | +make check # Run both linting and tests |
| 30 | +make test-coverage # Generate coverage report |
| 31 | +``` |
| 32 | + |
| 33 | +### Build & Distribution |
| 34 | +```bash |
| 35 | +make build # Build distribution packages |
| 36 | +make upload-test # Upload to TestPyPI |
| 37 | +make upload # Upload to PyPI (production) |
13 | 38 | ``` |
14 | 39 |
|
15 | 40 | ## Architecture Overview |
16 | 41 |
|
17 | | -This is an LLM plugin that provides text file manipulation tools through a Toolbox pattern. The plugin exposes file reading, writing, and patching functions bundled in a single `Patch` class. |
| 42 | +### File Structure |
| 43 | +- `llm_tools_patch.py` - Main plugin module containing all functionality |
| 44 | +- `tests/test_patch.py` - Comprehensive test suite |
| 45 | +- `pyproject.toml` - Project configuration and dependencies |
| 46 | +- `Makefile` - Development workflow automation |
| 47 | + |
| 48 | +### Core Architecture |
18 | 49 |
|
19 | | -### Core Components |
| 50 | +**Patch Toolbox Class** (`llm_tools_patch.Patch`): |
| 51 | +- Extends `llm.Toolbox` following LLM plugin conventions |
| 52 | +- Methods automatically become tools with naming pattern `Patch_method_name` |
| 53 | +- Bundles five core file operations in a single toolbox |
20 | 54 |
|
21 | | -**Patch** (main toolbox class): Bundles all file manipulation tools |
22 | | -- Extends `llm.Toolbox` |
23 | | -- Methods become available as tools with naming pattern `Patch_method_name` |
24 | | -- Contains file operations: reading, writing, and making targeted changes to text files |
| 55 | +**Individual Functions**: Can also be imported directly: |
| 56 | +- `patch_read()` - Read complete file contents |
| 57 | +- `patch_write()` - Write/overwrite file content |
| 58 | +- `patch_edit()` - Single string replacement |
| 59 | +- `patch_multi_edit()` - Multiple sequential edits |
| 60 | +- `patch_info()` - File metadata and information |
25 | 61 |
|
26 | 62 | ### Key Features |
27 | 63 |
|
28 | | -- **Safe file operations**: Read files without modification |
29 | | -- **Targeted patching**: Make specific changes to parts of text files |
30 | | -- **Text-focused**: Designed for configuration files, code, documentation, and other text content |
31 | | -- **LLM-friendly**: Simple interface optimized for AI agent usage |
| 64 | +- **Atomic operations**: Multi-edit operations succeed completely or fail completely |
| 65 | +- **Safety first**: Comprehensive validation and error handling |
| 66 | +- **Encoding detection**: Automatic UTF-8 handling with fallback detection |
| 67 | +- **Path resolution**: Support for relative paths, absolute paths, and `~` expansion |
| 68 | +- **LLM-optimized**: Clear error messages and straightforward operations |
| 69 | +- **Extensive testing**: Edge cases, Unicode support, large files, error conditions |
| 70 | + |
| 71 | +## Development Guidelines |
| 72 | + |
| 73 | +### Adding New Features |
| 74 | +1. Add functionality to `llm_tools_patch.py` |
| 75 | +2. Add corresponding method to `Patch` class if user-facing |
| 76 | +3. Add comprehensive tests to `tests/test_patch.py` |
| 77 | +4. Update docstrings following existing patterns |
| 78 | +5. Run `make check` to ensure quality standards |
| 79 | + |
| 80 | +### Testing Philosophy |
| 81 | +- Test both individual functions and toolbox methods |
| 82 | +- Cover edge cases: empty files, Unicode, large content, permission errors |
| 83 | +- Validate error conditions and error messages |
| 84 | +- Use pytest fixtures for consistent test setup |
| 85 | + |
| 86 | +### Error Handling Pattern |
| 87 | +All functions should: |
| 88 | +- Return success messages with specific details (character counts, replacement counts) |
| 89 | +- Return error messages starting with "Error:" for failures |
| 90 | +- Handle common exceptions (FileNotFoundError, PermissionError, UnicodeDecodeError) |
| 91 | +- Provide actionable error messages for users |
| 92 | + |
| 93 | +## Tool Usage Patterns |
| 94 | + |
| 95 | +### Safe File Reading |
| 96 | +Always use `patch_read()` or `patch_info()` before modifying files to understand their content and ensure accessibility. |
| 97 | + |
| 98 | +### Targeted Editing |
| 99 | +For precise changes, use `patch_edit()` with enough context in the search string to ensure uniqueness. Use `replace_all=True` only when intentionally replacing all occurrences. |
| 100 | + |
| 101 | +### Batch Operations |
| 102 | +Use `patch_multi_edit()` for multiple related changes. Remember that edits are applied sequentially, so later edits operate on the results of earlier ones. |
| 103 | + |
| 104 | +### File Creation |
| 105 | +Use `patch_write()` to create new files or completely replace existing content. Parent directories are created automatically. |
| 106 | + |
| 107 | +## Plugin Integration |
| 108 | + |
| 109 | +The plugin registers with LLM using the entry point system: |
| 110 | +- `pyproject.toml` defines `llm_tools_patch = "llm_tools_patch"` entry point |
| 111 | +- `@llm.hookimpl` decorator on `register_tools()` function |
| 112 | +- Tools become available as `Patch_method_name` in LLM conversations |
0 commit comments