Skip to content

Commit 5b59cf3

Browse files
committed
Big honking warning about file access
1 parent 6fd92ee commit 5b59cf3

File tree

3 files changed

+151
-34
lines changed

3 files changed

+151
-34
lines changed

CLAUDE.md

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,112 @@
11
# CLAUDE.md
22

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.
44

5-
## Plugin Development Commands
5+
## Project Overview
66

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.
88

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
1018
```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)
1338
```
1439

1540
## Architecture Overview
1641

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
1849

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
2054

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
2561

2662
### Key Features
2763

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

README.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,92 @@
55
[![Tests](https://github.com/dannyob/llm-tools-patch/actions/workflows/test.yml/badge.svg)](https://github.com/dannyob/llm-tools-patch/actions/workflows/test.yml)
66
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/dannyob/llm-tools-patch/blob/main/LICENSE)
77

8-
LLM tools for reading, writing and changing text files
8+
LLM plugin providing comprehensive text file manipulation, including reading, writing, and edits.
99

1010
## Installation
1111

12-
Install this plugin in the same environment as [LLM](https://llm.datasette.io/). You'll need at least the [0.26a1 alpha](https://llm.datasette.io/en/latest/changelog.html#a1-2025-05-25).
12+
Install this plugin in the same environment as [LLM](https://llm.datasette.io/). You'll need at least LLM [0.26a1](https://llm.datasette.io/en/latest/changelog.html#a1-2025-05-25) or later.
1313

14-
## Installation
15-
16-
Install this plugin using `llm install`:
14+
### From PyPI (recommended)
1715

1816
```bash
1917
llm install llm-tools-patch
2018
```
2119

22-
Or install from source:
20+
### From source
2321

2422
```bash
2523
git clone https://github.com/dannyob/llm-tools-patch
2624
cd llm-tools-patch
2725
llm install .
2826
```
2927

28+
## ⚠️ Security Warning
29+
30+
**This plugin provides AI agents with direct file system access.** The tools can read, write, and modify any files that your user account can access. Before enabling this plugin:
31+
32+
- Remember that AI agents can access files outside your current working directory
33+
- Only use with trusted AI models and prompts
34+
- Use `--ta` (tool approval) mode - review all file operations carefully
35+
- Consider the potential impact if an AI agent modifies important files
36+
3037
## Usage
3138

32-
This plugin provides tools for text file operations:
39+
The plugin provides a single `Patch` toolbox with five core operations:
3340

34-
- Reading text files
35-
- Writing text files
36-
- Making targeted changes/patches to text files
41+
### Available Tools
3742

38-
Use the `Patch` toolbox in your LLM conversations:
43+
- `read` - Read complete contents of a text file
44+
- `write` - Write new content to a file (overwrites existing)
45+
- `edit` - Make a single string replacement
46+
- `multi_edit` - Apply multiple string replacements in sequence
47+
- `info` - Get file metadata and information
48+
49+
### Basic Usage
50+
51+
```bash
52+
# Make a single edit
53+
llm -c prompt -m gpt-4o-mini "Change port 8080 to 3000 in config.txt" --tool Patch --ta
54+
```
3955

4056
```bash
41-
llm prompt -m gpt-4o-mini "Add a smiley face to the first heading in the README.md file" --tool Patch --chain-limit 0 --ta
57+
# Make multiple edits
58+
llm -c prompt -m gpt-4o-mini "Add a smiley face to the first heading in README.md" --tool Patch --ta --chain-limit 0
4259
```
4360

44-
You'll probably want to use both the `--ta` option (which requires a user confirmation before executing any function) and `--chain-limit 0`, which allows for indefinite tool calls in an `llm` session (`llm`'s default is 5).
61+
### Recommended Options
62+
63+
For interactive use, combine these flags:
64+
- `--ta` - Requires user confirmation before executing functions (safety)
65+
- `--chain-limit 0` - Allows unlimited tool calls in one session (default is 5)
4566

4667
## Development
4768

48-
To install for development:
69+
### Setup Development Environment
70+
71+
```bash
72+
# Clone and set up development environment
73+
git clone https://github.com/dannyob/llm-tools-patch
74+
cd llm-tools-patch
75+
make dev-setup
76+
source .venv/bin/activate
77+
```
78+
79+
### Testing
4980

5081
```bash
51-
llm install -e .
82+
make test # Run all tests
83+
make test-coverage # Run tests with coverage report
84+
make quick-test # Fast test run (exits on first failure)
5285
```
5386

54-
To run tests:
87+
### Plugin Testing
88+
89+
After installation, verify the plugin is working:
5590

5691
```bash
57-
make test
92+
llm tools # Should list Patch tools
93+
llm prompt "Read this README.md file" --tool Patch
5894
```
5995

6096
## Credits and Thanks

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "llm-tools-patch"
3-
version = "0.1"
3+
version = "0.2"
44
description = "LLM tools for reading, writing and changing text files"
55
readme = "README.md"
66
authors = [{name = "Danny O'Brien"}]

0 commit comments

Comments
 (0)