Skip to content

Commit 72fa1ff

Browse files
committed
chore: remove dead code and unused token counter package
- Delete dead ESC listener code and bubbletea/time imports from agent - Remove internal/tokens/ package (empty stubs and trivial estimator) - Inline token estimation into usage_tracker as unexported helper - Remove unused EstimateAndUpdateUsageFromText dead method - Remove 9 unsupported provider env var entries from registry
1 parent e62ce67 commit 72fa1ff

File tree

7 files changed

+5
-194
lines changed

7 files changed

+5
-194
lines changed

cmd/root.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/mark3labs/mcphost/internal/hooks"
1717
"github.com/mark3labs/mcphost/internal/models"
1818
"github.com/mark3labs/mcphost/internal/session"
19-
"github.com/mark3labs/mcphost/internal/tokens"
2019
"github.com/mark3labs/mcphost/internal/tools"
2120
"github.com/mark3labs/mcphost/internal/ui"
2221
"github.com/spf13/cobra"
@@ -362,9 +361,6 @@ func runMCPHost(ctx context.Context) error {
362361
}
363362

364363
func runNormalMode(ctx context.Context) error {
365-
// Initialize token counters
366-
tokens.InitializeTokenCounters()
367-
368364
// Validate flag combinations
369365
if quietFlag && promptFlag == "" {
370366
return fmt.Errorf("--quiet flag can only be used with --prompt/-p")

internal/agent/agent.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"time"
87

9-
tea "charm.land/bubbletea/v2"
108
"charm.land/fantasy"
119

1210
"github.com/mark3labs/mcphost/internal/config"
@@ -355,72 +353,3 @@ func (a *Agent) GetModel() fantasy.LanguageModel {
355353
func (a *Agent) Close() error {
356354
return a.toolManager.Close()
357355
}
358-
359-
// escListenerModel is a simple Bubble Tea model for ESC key detection
360-
type escListenerModel struct {
361-
escPressed chan bool
362-
}
363-
364-
func (m escListenerModel) Init() tea.Cmd {
365-
return nil
366-
}
367-
368-
func (m escListenerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
369-
if msg, ok := msg.(tea.KeyPressMsg); ok {
370-
if msg.String() == "esc" {
371-
select {
372-
case m.escPressed <- true:
373-
default:
374-
}
375-
return m, tea.Quit
376-
}
377-
}
378-
return m, nil
379-
}
380-
381-
func (m escListenerModel) View() tea.View {
382-
return tea.NewView("")
383-
}
384-
385-
// listenForESC listens for ESC key press using Bubble Tea and returns true if detected
386-
func (a *Agent) listenForESC(stopChan chan bool, readyChan chan bool) bool {
387-
escPressed := make(chan bool, 1)
388-
389-
model := escListenerModel{
390-
escPressed: escPressed,
391-
}
392-
393-
p := tea.NewProgram(model, tea.WithoutRenderer())
394-
395-
go func() {
396-
if _, err := p.Run(); err != nil {
397-
select {
398-
case escPressed <- false:
399-
default:
400-
}
401-
}
402-
}()
403-
404-
go func() {
405-
time.Sleep(10 * time.Millisecond)
406-
select {
407-
case readyChan <- true:
408-
default:
409-
}
410-
}()
411-
412-
select {
413-
case <-stopChan:
414-
p.Kill()
415-
time.Sleep(50 * time.Millisecond)
416-
return false
417-
case pressed := <-escPressed:
418-
p.Kill()
419-
time.Sleep(50 * time.Millisecond)
420-
return pressed
421-
case <-time.After(30 * time.Second):
422-
p.Kill()
423-
time.Sleep(50 * time.Millisecond)
424-
return false
425-
}
426-
}

internal/models/registry.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ var providerEnvVars = map[string][]string{
5353
"bedrock": {"AWS_ACCESS_KEY_ID"},
5454
"google-vertex-anthropic": {"GOOGLE_APPLICATION_CREDENTIALS"},
5555
"ollama": {},
56-
"mistral": {"MISTRAL_API_KEY"},
57-
"groq": {"GROQ_API_KEY"},
58-
"deepseek": {"DEEPSEEK_API_KEY"},
59-
"xai": {"XAI_API_KEY"},
60-
"fireworks": {"FIREWORKS_API_KEY"},
61-
"together": {"TOGETHER_API_KEY"},
62-
"perplexity": {"PERPLEXITY_API_KEY"},
63-
"alibaba": {"DASHSCOPE_API_KEY"},
64-
"cohere": {"COHERE_API_KEY"},
6556
}
6657

6758
// ModelsRegistry provides validation and information about models.

internal/tokens/anthropic.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

internal/tokens/counter.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

internal/tokens/init.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

internal/ui/usage_tracker.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"image/color"
99

1010
"github.com/mark3labs/mcphost/internal/models"
11-
"github.com/mark3labs/mcphost/internal/tokens"
1211
)
1312

1413
// UsageStats encapsulates detailed token usage and cost breakdown for a single
@@ -64,13 +63,9 @@ func NewUsageTracker(modelInfo *models.ModelInfo, provider string, width int, is
6463
}
6564
}
6665

67-
// EstimateTokens provides a rough estimate of the number of tokens in the given text.
68-
// This uses a simple heuristic of approximately 4 characters per token, which is a
69-
// reasonable approximation for most models but not precise. Actual token counts may vary
70-
// significantly based on the specific tokenizer used by each model.
71-
func EstimateTokens(text string) int {
72-
// Rough approximation: ~4 characters per token for most models
73-
// This is not accurate but gives a reasonable estimate
66+
// estimateTokens provides a rough estimate of the number of tokens in the given text.
67+
// Uses a simple heuristic of ~4 characters per token.
68+
func estimateTokens(text string) int {
7469
return len(text) / 4
7570
}
7671

@@ -126,16 +121,8 @@ func (ut *UsageTracker) UpdateUsage(inputTokens, outputTokens, cacheReadTokens,
126121
// the usage statistics. This method is used when actual token counts are not available
127122
// from the API response.
128123
func (ut *UsageTracker) EstimateAndUpdateUsage(inputText, outputText string) {
129-
inputTokens := tokens.EstimateTokens(inputText)
130-
outputTokens := tokens.EstimateTokens(outputText)
131-
ut.UpdateUsage(inputTokens, outputTokens, 0, 0)
132-
}
133-
134-
// EstimateAndUpdateUsageFromText is an alias for EstimateAndUpdateUsage, providing
135-
// backward compatibility. It estimates token counts from text and updates usage statistics.
136-
func (ut *UsageTracker) EstimateAndUpdateUsageFromText(inputText, outputText string) {
137-
inputTokens := tokens.EstimateTokens(inputText)
138-
outputTokens := tokens.EstimateTokens(outputText)
124+
inputTokens := estimateTokens(inputText)
125+
outputTokens := estimateTokens(outputText)
139126
ut.UpdateUsage(inputTokens, outputTokens, 0, 0)
140127
}
141128

0 commit comments

Comments
 (0)