diff --git a/README.md b/README.md index c4d68ca..7e1547b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ The resulting binary is ~12 MB, has no .NET runtime dependency, and starts insta | `/status` | Show session token usage and cost | | `/compact` | Manually trigger context compaction | | `/reset` | Clear session and reset token tracker | +| `/load` | Load a previous session from disk | +| `/save` | Save current session to disk | ## Available Tools **File Operations:** @@ -88,71 +90,7 @@ The resulting binary is ~12 MB, has no .NET runtime dependency, and starts insta - `rename_file` - Rename or move a file - `copy_file` - Copy a file to a new location - `append_to_file` - Append lines to the end of a file - -**Directory Operations:** -- `list_dir` - List directory contents -- `create_dir` - Create a new directory (with parent directories) -- `rename_dir` - Rename or move a directory -- `delete_dir` - Delete a directory and all its contents - -**Command Execution:** -- `execute_command` - Run shell commands (with user approval) - -``` -AnchorCli/ -├── Program.cs # Entry point + CLI parsing -├── ReplLoop.cs # Main REPL loop with streaming, spinners, and cancellation -├── ChatSession.cs # AI chat client wrapper with message history -├── ToolRegistry.cs # Centralized tool registration and dispatch -├── AnchorConfig.cs # JSON file-based configuration (~APPDATA~/anchor/config.json) -├── ContextCompactor.cs # Conversation history compression -├── AppJsonContext.cs # Source-generated JSON context (AOT) -├── SetupTui.cs # Interactive setup TUI -├── Hashline/ -│ ├── HashlineEncoder.cs # Adler-8 + position-seed hashing -│ └── HashlineValidator.cs # Anchor resolution + validation -├── Tools/ -│ ├── FileTools.cs # read_file, grep_file, grep_recursive, find_files, get_file_info -│ ├── EditTools.cs # replace_lines, insert_after, delete_range, create/delete/rename/copy/append -│ ├── DirTools.cs # list_dir, create_dir, rename_dir, delete_dir -│ └── CommandTool.cs # execute_command -├── Commands/ -│ ├── ICommand.cs # Command interface -│ ├── CommandRegistry.cs # Command registration -│ ├── CommandDispatcher.cs # Command dispatch logic -│ ├── ExitCommand.cs # /exit command -│ ├── HelpCommand.cs # /help command -│ ├── ClearCommand.cs # /clear command -│ ├── StatusCommand.cs # /status command -│ ├── CompactCommand.cs # /compact command -│ ├── CompactCommand.cs # /compact command -│ ├── LoadCommand.cs # /load command -│ ├── SaveCommand.cs # /save command -│ └── ResetCommand.cs # /reset command -- `append_to_file` - Append lines to the end of a file -- `batch_edit` - Apply multiple edits atomically in a single operation -`/compact` | Manually trigger context compaction | -/load` | Load a previous chat session from file | -`/save` | Save current chat session to file | -`/reset` | Clear session and reset token tracker | -## Available Tools - -**File Operations:** -- `read_file` - Read a file (or a window) with Hashline-tagged lines -- `grep_file` - Search a file by regex — results are pre-tagged for immediate editing -- `grep_recursive` - Search for a regex pattern across all files in a directory tree -- `find_files` - Search for files matching glob patterns -- `get_file_info` - Get detailed file information (size, permissions, etc.) - -**Edit Operations:** -- `replace_lines` - Replace a range identified by `line:hash` anchors -- `insert_after` - Insert lines after an anchor -- `delete_range` - Delete a range between two anchors -- `create_file` - Create a new file with optional initial content -- `delete_file` - Delete a file permanently -- `rename_file` - Rename or move a file -- `copy_file` - Copy a file to a new location -- `append_to_file` - Append lines to the end of a file +- `batch_edit` - Apply multiple replace/delete operations atomically in a single call **Directory Operations:** - `list_dir` - List directory contents @@ -191,7 +129,9 @@ AnchorCli/ │ ├── StatusCommand.cs # /status command │ ├── CompactCommand.cs # /compact command │ ├── ResetCommand.cs # /reset command -│ └── SetupCommand.cs # /setup command +│ ├── SetupCommand.cs # /setup command +│ ├── LoadCommand.cs # /load command +│ └── SaveCommand.cs # /save command └── OpenRouter/ └── PricingProvider.cs # Fetch model pricing from OpenRouter ``` diff --git a/Tools/EditTools.cs b/Tools/EditTools.cs index 3b3027e..ab33038 100644 --- a/Tools/EditTools.cs +++ b/Tools/EditTools.cs @@ -352,8 +352,8 @@ internal static partial class EditTools } } - // Sort operations bottom-to-top (by start index descending) for safe application - var sortedOps = resolvedOps.OrderByDescending(x => x.StartIdx).ToList(); + // Sort operations top-to-bottom (by start index ascending) because we build a new list sequentially + var sortedOps = resolvedOps.OrderBy(x => x.StartIdx).ToList(); // Apply all operations to a single buffer var result = new List(lines.Length); diff --git a/docs/ToolConsolidation.md b/docs/ToolConsolidation.md deleted file mode 100644 index e48341f..0000000 --- a/docs/ToolConsolidation.md +++ /dev/null @@ -1,105 +0,0 @@ -# Tool Consolidation Ideas - -This document outlines opportunities to merge similar tools to simplify the API. - -## 1. File Write Operations - -**Current tools:** `CreateFile`, `InsertAfter`, `AppendToFile` - -**Proposed merge:** `WriteToFile` - -```csharp -public static string WriteToFile( - string path, - string[] content, - string? mode = "create", - string? anchor = null) -``` - -**Behavior:** -- `mode="create"` - Creates new file (error if exists) -- `mode="append"` - Appends to EOF (creates if missing) -- `mode="insert"` - Inserts after anchor (requires existing file) - -**Benefits:** -- Reduces 3 tools to 1 -- Cleaner API for LLM -- Unified error handling - -## 2. File Move Operations - -**Current tools:** `RenameFile`, `CopyFile` - -**Proposed merge:** `MoveFile` - -```csharp -public static string MoveFile( - string sourcePath, - string destinationPath, - bool copy = false) -``` - -**Behavior:** -- `copy=false` - Moves file (current RenameFile behavior) -- `copy=true` - Copies file (current CopyFile behavior) - -**Benefits:** -- 90% identical logic -- Only difference is File.Move vs File.Copy -- Both create parent directories -- Similar error handling patterns - -## 4. Grep Operations ✅ DONE - -**Current tools:** `GrepFile`, `GrepRecursive` - -**Proposed merge:** `Grep` - -```csharp -public static string Grep( - string path, - string pattern, - string mode = "recursive", - string? filePattern = null) -``` - -**Behavior:** -- `mode="file"` - Searches single file (current GrepFile) -- `mode="recursive"` - Searches directory recursively (current GrepRecursive) -- `filePattern` - Optional glob to filter files when recursive - -**Benefits:** -- Very similar logic -- Reduces 2 tools to 1 -- Cleaner API for LLM - -## 5. Delete Operations ✅ DONE - -**Current tools:** `DeleteFile`, `DeleteDir` - -**Proposed merge:** `Delete` - -```csharp -public static string Delete( - string path, - string mode = "file") -``` - -**Behavior:** -- `mode="file"` - Deletes a file -- `mode="dir"` - Deletes a directory (recursive) - -**Benefits:** -- Unified interface for all deletion -- Similar error handling patterns -- Reduces 2 tools to 1 - -These consolidations reduced the tool count from 17 to 13 tools (4 completed), making the API simpler and easier for the LLM to use effectively. - -**Completed merges**: -1. ✅ File Move Operations (2 → 1) - **DONE** -2. ✅ File Write Operations (3 → 1) - **DONE** -3. ✅ Delete Operations (2 → 1) - **DONE** -4. ✅ Grep Operations (2 → 1) - **DONE** - -**All high priority merges completed!**