V2/token optimization (#11)

* v2.0: token-optimization overhaul

Additive (backward-compatible flags):
- file_read: skeleton mode, strip (imports/license/block_comments),
  compact_line_numbers, 8-char etag with prefix-match compat
- ast_query: format=verbose|compact|location, pagination cursor
- file_search: cluster mode, pagination cursor
- lsp_query (references): compact output

Breaking (v2):
- Preambles removed; opt-in verbose=true restores
- edit_apply: response=count|diff|none, default count
- ping tool removed
- symbol_at/find_definition/find_references merged into lsp_query
- Tool descriptions trimmed -83%, help moved to filepuff://help/<tool>
- Batch file_read dedups by etag

Protocol:
- ResourceLink returned for file_read >64 KiB (force_inline override)
- OnAfterInitialize hook reads capabilities.experimental.filepuff
  for session defaults (default_format, default_max_results,
  default_cluster, compact_refs, line_numbers,
  resource_link_threshold)

* fix: drop --max-total-count from ripgrep args

The flag does not exist in stable ripgrep (confirmed up to 15.1.0 --
"unrecognized flag --max-total-count, similar flags that are
available: --max-count"). Every file_search call failed on hosts with
stock rg. --max-count is per-file, not a drop-in replacement, so rely
on the in-process truncation in parseOutput that was already the
documented safety net.
This commit is contained in:
2026-04-19 19:56:49 +01:00
committed by GitHub
parent b131c1edd3
commit 5ad975ee7a
26 changed files with 4909 additions and 507 deletions
+3 -25
View File
@@ -43,23 +43,7 @@ func Hello() string {
ctx := context.Background()
// Test 1: Ping tool (health check)
t.Run("ping", func(t *testing.T) {
req := mcp.CallToolRequest{}
result, err := srv.handlePing(ctx, req)
if err != nil {
t.Errorf("handlePing() error = %v", err)
}
if result == nil {
t.Fatal("handlePing() returned nil")
return
}
if len(result.Content) == 0 {
t.Fatal("handlePing() returned empty content")
}
})
// Test 2: File read
// Test: File read (ping removed — Change 3)
t.Run("file_read", func(t *testing.T) {
req := mcp.CallToolRequest{}
req.Params.Arguments = map[string]interface{}{
@@ -144,14 +128,8 @@ func TestMCPToolDiscovery(t *testing.T) {
t.Fatal("MCP server not initialized")
}
// Verify each expected tool works
ctx := context.Background()
// Test ping tool
pingReq := mcp.CallToolRequest{}
if _, err := srv.handlePing(ctx, pingReq); err != nil {
t.Errorf("ping tool failed: %v", err)
}
// Ping tool removed (Change 3 — MCP protocol has own liveness check).
// Tools verified via integration tests in TestIntegrationFileOperations.
}
// TestMCPErrorResponses tests error handling following MCP spec.