UNPKG

@ooples/token-optimizer-mcp

Version:

Intelligent context window optimization for Claude Code - store content externally via caching and compression, freeing up your context window for what matters

197 lines 5.25 kB
/** * Smart Branch Tool - 60% Token Reduction * * Achieves token reduction through: * 1. Structured JSON output (instead of raw git branch text) * 2. Name-only mode (just branch names, no metadata) * 3. Filtering options (local, remote, merged/unmerged) * 4. Pagination (limit branches returned) * 5. Smart caching (reuse branch info based on git state) * * Target: 60% reduction vs full git branch output with details */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface BranchInfo { name: string; current: boolean; remote: string | null; upstream: string | null; lastCommit?: { hash: string; shortHash: string; author: string; date: Date; message: string; }; ahead?: number; behind?: number; merged?: boolean; } export interface SmartBranchOptions { cwd?: string; local?: boolean; remote?: boolean; all?: boolean; pattern?: string; merged?: boolean; unmerged?: boolean; mergedInto?: string; namesOnly?: boolean; includeCommit?: boolean; includeTracking?: boolean; sortBy?: 'name' | 'date' | 'author'; sortOrder?: 'asc' | 'desc'; limit?: number; offset?: number; useCache?: boolean; ttl?: number; } export interface SmartBranchResult { success: boolean; metadata: { totalBranches: number; returnedCount: number; truncated: boolean; currentBranch: string; repository: string; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; duration: number; cacheHit: boolean; }; branches?: Array<string | BranchInfo>; error?: string; } export declare class SmartBranchTool { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart branch listing with structured output and token optimization */ branch(options?: SmartBranchOptions): Promise<SmartBranchResult>; /** * Check if directory is a git repository */ private isGitRepository; /** * Get current branch name */ private getCurrentBranch; /** * Get latest commit hash for cache invalidation */ private getLatestCommitHash; /** * Build cache key from options */ private buildCacheKey; /** * Get branches from git */ private getBranches; /** * Check if branch is merged into target */ private isBranchMerged; /** * Get last commit info for a branch */ private getLastCommit; /** * Get tracking info (ahead/behind counts) */ private getTrackingInfo; /** * Sort branches by specified field */ private sortBranches; /** * Get branch statistics */ getStats(): { totalQueries: number; cacheHits: number; totalTokensSaved: number; averageReduction: number; }; } /** * Get smart branch tool instance */ export declare function getSmartBranchTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartBranchTool; /** * CLI function - Creates resources and uses factory */ export declare function runSmartBranch(options?: SmartBranchOptions): Promise<SmartBranchResult>; /** * MCP Tool Definition */ export declare const SMART_BRANCH_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: string; properties: { cwd: { type: string; description: string; }; all: { type: string; description: string; default: boolean; }; remote: { type: string; description: string; default: boolean; }; pattern: { type: string; description: string; }; merged: { type: string; description: string; default: boolean; }; unmerged: { type: string; description: string; default: boolean; }; namesOnly: { type: string; description: string; default: boolean; }; includeCommit: { type: string; description: string; default: boolean; }; includeTracking: { type: string; description: string; default: boolean; }; limit: { type: string; description: string; }; sortBy: { type: string; enum: string[]; description: string; default: string; }; }; }; }; //# sourceMappingURL=smart-branch.d.ts.map