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

176 lines 4.66 kB
/** * Smart Environment Variable Tool - 83% Token Reduction * * Features: * - Parse and validate .env files * - Detect missing required variables * - Cache env configs with 1-hour TTL * - Environment-specific suggestions (dev/staging/prod) * - Security issue detection (exposed secrets, weak configs) * - File hash-based invalidation */ import { CacheEngine } from '../../core/cache-engine.js'; import type { TokenCounter } from '../../core/token-counter.js'; import type { MetricsCollector } from '../../core/metrics.js'; export interface SmartEnvOptions { envFile?: string; envContent?: string; checkSecurity?: boolean; suggestMissing?: boolean; environment?: 'development' | 'staging' | 'production'; requiredVars?: string[]; force?: boolean; ttl?: number; } export interface EnvVariable { key: string; value: string; line: number; hasQuotes: boolean; isEmpty: boolean; } export interface SecurityIssue { severity: 'critical' | 'high' | 'medium' | 'low'; variable: string; issue: string; recommendation: string; line?: number; } export interface MissingVariable { name: string; description: string; defaultValue?: string; required: boolean; } export interface SmartEnvResult { success: boolean; environment: string; variables: { total: number; loaded: number; empty: number; commented: number; }; parsed?: EnvVariable[]; missing?: MissingVariable[]; security?: { score: number; issues: SecurityIssue[]; hasSecrets: boolean; }; suggestions?: string[]; metadata: { fileHash?: string; filePath?: string; cached: boolean; tokensUsed: number; tokensSaved: number; executionTime: number; }; } export declare class SmartEnv { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Main entry point for environment analysis */ run(options: SmartEnvOptions): Promise<SmartEnvResult>; /** * Get environment content from file or direct input */ private getEnvContent; /** * Parse .env file content into structured variables */ private parseEnvContent; /** * Analyze environment variables and generate insights */ private analyzeEnvironment; /** * Detect environment type from variable names */ private detectEnvironment; /** * Detect missing required variables */ private detectMissingVariables; /** * Get common variables for environment type */ private getCommonVariables; /** * Analyze security issues in environment variables */ private analyzeSecurityIssues; /** * Generate helpful suggestions */ private generateSuggestions; /** * Generate cache key */ private generateCacheKey; /** * Get cached result */ private getCached; /** * Cache result */ private cacheResult; } export declare function getSmartEnv(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartEnv; export declare function runSmartEnv(options: SmartEnvOptions): Promise<string>; export declare const SMART_ENV_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { envFile: { type: string; description: string; }; envContent: { type: string; description: string; }; checkSecurity: { type: string; description: string; default: boolean; }; suggestMissing: { type: string; description: string; default: boolean; }; environment: { type: string; enum: string[]; description: string; }; requiredVars: { type: string; items: { type: string; }; description: string; }; force: { type: string; description: string; default: boolean; }; ttl: { type: string; description: string; default: number; }; }; }; }; //# sourceMappingURL=smart-env.d.ts.map