UNPKG

aiwg

Version:

Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo

92 lines 3.27 kB
/** * Token Counter — character-based token estimation * * Provides lightweight token estimation using the 4 chars per token * heuristic, non-blank line counting, and tokens/line ratio calculation. * Benchmark target: 124 tokens/line (MetaGPT, REF-013). * * @module metrics/token-counter * @issue #173 * @schema @agentic/code/frameworks/sdlc-complete/schemas/flows/token-efficiency.yaml */ export interface TokenCount { /** Estimated token count (4 chars per token heuristic) */ tokens: number; /** Total characters in the content */ characters: number; /** Number of non-blank lines */ nonBlankLines: number; /** Total lines including blank */ totalLines: number; /** Tokens per non-blank line ratio */ tokensPerLine: number; } export interface ThresholdStatus { /** Green/Yellow/Red status */ level: 'green' | 'yellow' | 'red'; /** Human-readable status message */ message: string; /** Recommended action */ action: 'none' | 'flag_for_review' | 'generate_recommendations'; } export interface TokenEfficiencyResult extends TokenCount { /** Threshold status vs benchmark */ threshold: ThresholdStatus; /** Percentage vs benchmark (negative = better) */ vsBenchmark: number; /** Percentage vs baseline (negative = better) */ vsBaseline: number; } /** Average characters per token (GPT/Claude heuristic) */ export declare const CHARS_PER_TOKEN = 4; /** MetaGPT benchmark: 124 tokens per line (REF-013) */ export declare const BENCHMARK_TOKENS_PER_LINE = 124; /** Typical LLM baseline: ~200 tokens per line */ export declare const BASELINE_TOKENS_PER_LINE = 200; /** Green threshold: at or below benchmark */ export declare const GREEN_MAX_TOKENS_PER_LINE = 124; /** Yellow threshold: between benchmark and 150 */ export declare const YELLOW_MAX_TOKENS_PER_LINE = 150; /** * Estimate token count from text content using character-based heuristic. * * @param content - Text content to estimate tokens for * @returns Estimated token count */ export declare function estimateTokens(content: string): number; /** * Count non-blank lines in content. * * @param content - Text content * @returns Number of non-blank lines */ export declare function countNonBlankLines(content: string): number; /** * Count total lines in content. * * @param content - Text content * @returns Total line count */ export declare function countTotalLines(content: string): number; /** * Perform full token count analysis on content. * * @param content - Text content to analyze * @returns Token count with line metrics */ export declare function countTokens(content: string): TokenCount; /** * Determine threshold status for a tokens/line ratio. * * @param tokensPerLine - Tokens per non-blank line ratio * @returns Threshold status with level, message, and action */ export declare function evaluateThreshold(tokensPerLine: number): ThresholdStatus; /** * Analyze token efficiency with full benchmark comparison. * * @param content - Text content to analyze * @returns Full efficiency result with threshold and benchmark comparison */ export declare function analyzeTokenEfficiency(content: string): TokenEfficiencyResult; //# sourceMappingURL=token-counter.d.ts.map