/** * Smart Glob Tool - 75% Token Reduction * * Achieves token reduction through: * 1. Path-only results (no file content unless requested) * 2. Smart pagination (limit results, return counts) * 3. Cached pattern results (reuse glob results) * 4. Metadata filtering (filter before returning) * 5. Intelligent sorting (most relevant first) * * Target: 75% reduction vs listing all files with content */ import { type TruncationReason } from '../shared/bounded-traversal.js'; import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; export interface FileMetadata { path: string; relativePath: string; name: string; extension: string; size: number; modified: Date; type: 'file' | 'directory'; fileType?: string; } export interface SmartGlobOptions { /** * Directory to search. The natural name for it, and the one the hook's * refusal message leads callers to pass; takes precedence over `cwd`. */ path?: string; cwd?: string; absolute?: boolean; ignore?: string[]; onlyFiles?: boolean; onlyDirectories?: boolean; extensions?: string[]; excludeExtensions?: string[]; minSize?: number; maxSize?: number; modifiedAfter?: Date; modifiedBefore?: Date; includeMetadata?: boolean; includeContent?: boolean; maxContentSize?: number; limit?: number; offset?: number; sortBy?: 'name' | 'size' | 'modified' | 'path'; sortOrder?: 'asc' | 'desc'; /** * Serve a previously cached result for the same query. * * DEFAULT FALSE, and the default is the point. A cached search is keyed on * the query, and a query does not describe the tree it ran against: create, * edit or delete a matching file and the cached answer is simply wrong. * Measured live -- a file created between two identical searches did not * appear in the second. * * Enabling it says "nothing outside this server is changing these files", * which only the caller can know. Writes made THROUGH this server are * handled either way: they bump a generation counter that forms part of the * key, so our own edits always invalidate. */ useCache?: boolean; ttl?: number; /** * Wall-clock budget for the whole call, in ms. * * Defaults to TOKEN_OPTIMIZER_TRAVERSAL_DEADLINE_MS, then to 10 s. The * search returns what it found and says it was cut short, rather than * running until the caller's own tool timeout kills it. */ deadlineMs?: number; } export interface SmartGlobResult { success: boolean; pattern: string; metadata: { totalMatches: number; returnedCount: number; truncated: boolean; tokensSaved: number; tokenCount: number; originalTokenCount: number; compressionRatio: number; duration: number; cacheHit: boolean; savingsClassification?: 'unmeasured'; savingsReason?: string; /** Real matches withheld by the ignore patterns; absent when none were. */ ignoredMatches?: number; /** Plain-language explanation of what was withheld and how to see it. */ ignoreNote?: string; /** * True when a BOUND stopped the walk, so the tree was not fully searched. * * Distinct from `truncated`, which means "more matches exist than this page * returned" and says nothing about coverage. A caller can page through a * `truncated` result and see everything; a `searchTruncated` result has * matches that were never looked for. */ searchTruncated?: boolean; /** Which bound stopped it: a result cap, or the wall-clock deadline. */ searchTruncatedBy?: TruncationReason; /** What to do about it, in the caller's terms. */ searchNote?: string; }; files?: Array; error?: string; } export declare class SmartGlobTool { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); /** * Smart glob with filtering, pagination, and minimal token output */ glob(pattern: string, options?: SmartGlobOptions): Promise; /** * Sort files by specified field */ private sortFiles; /** * Get glob statistics */ getStats(): { totalGlobs: number; cacheHits: number; totalTokensSaved: number; averageReduction: number; }; } /** * Get smart glob tool instance */ export declare function getSmartGlobTool(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartGlobTool; /** * CLI function - Creates resources and uses factory */ export declare function runSmartGlob(pattern: string, options?: SmartGlobOptions): Promise; /** * MCP Tool Definition */ export declare const SMART_GLOB_TOOL_DEFINITION: { name: string; description: string; annotations: { title: string; readOnlyHint: boolean; destructiveHint: boolean; idempotentHint: boolean; openWorldHint: boolean; }; inputSchema: { type: string; properties: { pattern: { type: string; description: string; }; path: { type: string; description: string; }; cwd: { type: string; description: string; }; includeMetadata: { type: string; description: string; default: boolean; }; includeContent: { type: string; description: string; default: boolean; }; extensions: { type: string; items: { type: string; }; description: string; }; limit: { type: string; description: string; }; sortBy: { type: string; enum: string[]; description: string; default: string; }; absolute: { type: string; description: string; default: boolean; }; deadlineMs: { type: string; description: string; }; ignore: { type: string; items: { type: string; }; description: string; default: string[]; }; onlyFiles: { type: string; description: string; default: boolean; }; onlyDirectories: { type: string; description: string; default: boolean; }; excludeExtensions: { type: string; items: { type: string; }; description: string; }; minSize: { type: string; description: string; }; maxSize: { type: string; description: string; }; modifiedAfter: { type: string; format: string; description: string; }; modifiedBefore: { type: string; format: string; description: string; }; maxContentSize: { type: string; description: string; default: number; }; offset: { type: string; description: string; default: number; }; sortOrder: { type: string; enum: string[]; description: string; default: string; }; useCache: { type: string; description: string; default: boolean; }; ttl: { type: string; description: string; default: number; }; }; required: string[]; }; }; //# sourceMappingURL=smart-glob.d.ts.map