@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
196 lines • 5.08 kB
TypeScript
/**
* Smart Log Tool - 75% Token Reduction
*
* Achieves token reduction through:
* 1. Structured JSON output (instead of full git log text)
* 2. Pagination (limit commits returned)
* 3. Field selection (only return requested fields)
* 4. Format options (oneline, short, full)
* 5. Filtering (by author, date range, file path)
*
* Target: 75% reduction vs full git log output
*/
import { CacheEngine } from '../../core/cache-engine.js';
import { TokenCounter } from '../../core/token-counter.js';
import { MetricsCollector } from '../../core/metrics.js';
export interface CommitInfo {
hash: string;
shortHash: string;
author: string;
email: string;
date: Date;
message: string;
subject: string;
body?: string;
files?: string[];
additions?: number;
deletions?: number;
refs?: string[];
}
export interface SmartLogOptions {
cwd?: string;
since?: string;
until?: string;
branch?: string;
author?: string;
grep?: string;
filePath?: string;
format?: 'oneline' | 'short' | 'full';
includeFiles?: boolean;
includeStats?: boolean;
includeRefs?: boolean;
fields?: Array<keyof CommitInfo>;
limit?: number;
offset?: number;
reverse?: boolean;
useCache?: boolean;
ttl?: number;
}
export interface SmartLogResult {
success: boolean;
metadata: {
totalCommits: number;
returnedCount: number;
truncated: boolean;
repository: string;
currentBranch: string;
tokensSaved: number;
tokenCount: number;
originalTokenCount: number;
compressionRatio: number;
duration: number;
cacheHit: boolean;
};
commits?: CommitInfo[];
error?: string;
}
export declare class SmartLogTool {
private cache;
private tokenCounter;
private metrics;
constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector);
/**
* Smart git log with structured output and token optimization
*/
log(options?: SmartLogOptions): Promise<SmartLogResult>;
/**
* 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 commits from git log
*/
private getCommits;
/**
* Parse git log output into structured commits
*/
private parseGitLog;
/**
* Get files changed in a commit
*/
private getCommitFiles;
/**
* Get commit statistics (additions/deletions)
*/
private getCommitStats;
/**
* Filter commit fields based on requested fields
*/
private filterFields;
/**
* Get log statistics
*/
getStats(): {
totalLogs: number;
cacheHits: number;
totalTokensSaved: number;
averageReduction: number;
};
}
/**
* Get smart log tool instance
*/
export declare function getSmartLogTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartLogTool;
/**
* CLI function - Creates resources and uses factory
*/
export declare function runSmartLog(options?: SmartLogOptions): Promise<SmartLogResult>;
/**
* MCP Tool Definition
*/
export declare const SMART_LOG_TOOL_DEFINITION: {
name: string;
description: string;
inputSchema: {
type: string;
properties: {
cwd: {
type: string;
description: string;
};
since: {
type: string;
description: string;
};
until: {
type: string;
description: string;
};
branch: {
type: string;
description: string;
};
author: {
type: string;
description: string;
};
grep: {
type: string;
description: string;
};
filePath: {
type: string;
description: string;
};
format: {
type: string;
enum: string[];
description: string;
default: string;
};
includeFiles: {
type: string;
description: string;
default: boolean;
};
includeStats: {
type: string;
description: string;
default: boolean;
};
limit: {
type: string;
description: string;
default: number;
};
offset: {
type: string;
description: string;
default: number;
};
};
};
};
//# sourceMappingURL=smart-log.d.ts.map