1
0

Compare commits

..

3 Commits

4 changed files with 25 additions and 21 deletions

13
Commands/SetupCommand.cs Normal file
View File

@@ -0,0 +1,13 @@
namespace AnchorCli.Commands;
public class SetupCommand : ICommand
{
public string Name => "setup";
public string Description => "Run interactive setup wizard to configure API key and model";
public Task ExecuteAsync(string[] args, CancellationToken ct)
{
SetupTui.Run();
return Task.CompletedTask;
}
}

View File

@@ -37,15 +37,15 @@ internal sealed class TokenTracker
/// <summary>
/// Returns true if the context is getting too large and should be compacted.
/// Triggers at min(75% of model context, 100K tokens).
/// Triggers at min(75% of model context, 150K tokens).
/// </summary>
public bool ShouldCompact()
{
if (LastInputTokens <= 0) return false;
int threshold = ContextLength > 0
? Math.Min((int)(ContextLength * 0.75), 100_000)
: 100_000;
? Math.Min((int)(ContextLength * 0.75), 150_000)
: 150_000;
return LastInputTokens >= threshold;
}

View File

@@ -183,6 +183,7 @@ commandRegistry.Register(new HelpCommand(commandRegistry));
commandRegistry.Register(new ClearCommand());
commandRegistry.Register(new StatusCommand(model, endpoint));
commandRegistry.Register(new CompactCommand(compactor, history));
commandRegistry.Register(new SetupCommand());
var commandDispatcher = new CommandDispatcher(commandRegistry);

View File

@@ -24,7 +24,8 @@ This eliminates:
- **Interactive REPL**: Chat with an AI model to edit files, manage directories, and execute commands
- **Slash Commands**: `/setup`, `/help`, `/exit`, `/clear`, `/status`, `/compact`
- **Token Tracking**: Real-time token usage and cost per response, plus session totals
- **Context Compaction**: Automatic conversation history compression when approaching context limits
- **Model Pricing Display**: Shows current model pricing from OpenRouter in the header
- **Context Compaction**: Automatic conversation history compression when approaching context limits, including stale tool result compaction
- **Comprehensive Toolset**: 15 tools for file operations, editing, directory management, and command execution
- **AOT-Ready**: Native AOT compilation for ~12 MB binaries with no .NET runtime dependency
- **Rich CLI**: Beautiful terminal output using Spectre.Console with tables, rules, and colored text
@@ -40,13 +41,11 @@ This eliminates:
## Quick Start
```bash
# Option 1: Set environment variables
export ANCHOR_API_KEY=your_key_here
export ANCHOR_MODEL=qwen3.5-27b # optional, default: gpt-4o
# Run the application
dotnet run --project AnchorCli
# Option 2: Use interactive setup
# First time? The app will prompt you to run /setup
# Or run it explicitly:
dotnet run --project AnchorCli
/setup
```
@@ -60,20 +59,11 @@ dotnet publish AnchorCli -r linux-x64 -c Release
The resulting binary is ~12 MB, has no .NET runtime dependency, and starts instantly.
## Environment Variables
| Variable | Default | Description |
|---|---|---|
| `ANCHOR_API_KEY` | *(required)* | API key for the LLM provider |
| `ANCHOR_ENDPOINT` | `https://openrouter.ai/api/v1` | Any OpenAI-compatible endpoint |
| `ANCHOR_MODEL` | `gpt-4o` | Model name |
| `ANCHOR_MAX_TOKENS` | `4096` | Max response tokens |
## Slash Commands
| Command | Description |
|---|---|
| `/setup` | Run interactive TUI to configure API key, model, endpoint |
| `/setup` | Run interactive TUI to configure API key and model (also accessible via `anchor setup` subcommand) |
| `/help` | Show available tools and commands |
| `/exit` | Exit the application |
| `/clear` | Clear the conversation history |
@@ -113,7 +103,7 @@ The resulting binary is ~12 MB, has no .NET runtime dependency, and starts insta
```
AnchorCli/
├── Program.cs # Entry point + REPL loop + AI client setup
├── AnchorConfig.cs # Environment variable configuration
├── AnchorConfig.cs # JSON file-based configuration (~APPDATA~\anchor\config.json)
├── ContextCompactor.cs # Conversation history compression
├── AppJsonContext.cs # Source-generated JSON context (AOT)
├── Hashline/
@@ -137,7 +127,7 @@ AnchorCli/
## How It Works
1. **Setup**: Configure API credentials via environment variables or `/setup` command
1. **Setup**: Configure API credentials via the `/setup` command (or `anchor setup` subcommand)
2. **REPL Loop**: You interact with the AI through a conversational interface
3. **Tool Calling**: The AI can call any of the available tools to read/edit files, manage directories, or execute commands
4. **Hashline Validation**: All file edits are validated using the Hashline technique to ensure precision