/** * create_index Tool * * MCP tool to create a search index for the current project. Detects project root, * scans files, chunks content, generates embeddings, and stores in LanceDB. * Requires user confirmation before starting. * * Features: * - Automatic project root detection * - User confirmation before indexing * - Progress reporting during indexing * - File watcher startup after completion * - Handles existing index (offers to reindex) */ import { z } from 'zod'; import { IndexProgress } from '../engines/indexManager.js'; import type { ToolContext } from './searchCode.js'; import type { StrategyOrchestrator } from '../engines/strategyOrchestrator.js'; import type { Config } from '../storage/config.js'; /** * Input schema for create_index tool * * No required inputs - uses current directory context from the MCP client. */ export declare const CreateIndexInputSchema: z.ZodObject<{}, z.core.$strip>; /** * Inferred input type from schema */ export type CreateIndexInput = z.infer; /** * Output status for create_index tool */ export type CreateIndexStatus = 'success' | 'cancelled'; /** * Output structure for create_index tool */ export interface CreateIndexOutput { /** Result status */ status: CreateIndexStatus; /** Human-readable summary of the indexing result */ summary?: string; /** Absolute path to the project root (if successful) */ projectPath?: string; /** Number of files indexed (if successful) */ filesIndexed?: number; /** Number of chunks created (if successful) */ chunksCreated?: number; /** Duration string like "45s" or "2m 30s" (if successful) */ duration?: string; /** Total files found in project before filtering */ totalFilesInProject?: number; /** Number of files excluded by policy */ excludedFiles?: number; /** Number of code files indexed */ codeFilesIndexed?: number; /** Number of doc files indexed */ docsFilesIndexed?: number; /** Number of doc chunks created */ docsChunksCreated?: number; /** Warning about docs indexing (e.g., when 0 docs indexed despite files existing) */ docsWarning?: string; /** Compute device used for embedding generation (SMCP-083) */ computeDevice?: string; /** Chunks per second performance metric (SMCP-083) */ chunksPerSecond?: number; } /** * Progress callback type for MCP progress reporting */ export type ProgressCallback = (progress: IndexProgress) => void; /** * Extended tool context with optional progress callback */ export interface CreateIndexContext extends ToolContext { /** Optional callback for progress updates */ onProgress?: ProgressCallback; /** Whether user has confirmed the operation (for MCP confirmation flow) */ confirmed?: boolean; /** Optional strategy orchestrator for starting indexing strategy after completion */ orchestrator?: StrategyOrchestrator; /** Optional config for starting strategy (required if orchestrator is provided) */ config?: Config; } /** * Format duration in milliseconds to human-readable string * * @param ms - Duration in milliseconds * @returns Human-readable duration like "45s" or "2m 30s" * * @example * ```typescript * formatDuration(45000); // "45s" * formatDuration(150000); // "2m 30s" * formatDuration(3600000); // "1h 0m" * ``` */ export declare function formatDuration(ms: number): string; /** * Format progress message for display * * @param progress - Current progress information * @returns Human-readable progress message * * @example * ```typescript * formatProgressMessage({ phase: 'scanning', current: 100, total: 500 }) * // => "Scanning files... [100/500]" * ``` */ export declare function formatProgressMessage(progress: IndexProgress): string; /** * Format the index creation summary for display * * @param output - The index creation output data * @returns Human-readable summary string * * @example * ```typescript * formatIndexSummary({ * projectPath: '/path/to/project', * totalFilesInProject: 20085, * excludedFiles: 19830, * codeFilesIndexed: 255, * docsFilesIndexed: 103, * chunksCreated: 1196, * duration: '3m 19s' * }) * // => "Index created successfully...\n\nStatistics:\n..." * ``` */ export declare function formatIndexSummary(output: Omit): string; /** * Detect the project root for indexing * * Uses the project root detection engine to find the project root. * If not found, returns the current working directory as fallback. * * @param context - Tool context containing the project path (cwd) * @returns Detected project path * * @example * ```typescript * const projectPath = await detectProject({ projectPath: '/Users/dev/project/src' }); * // => '/Users/dev/project' (detected from .git or package.json) * ``` */ export declare function detectProject(context: ToolContext): Promise; /** * Check if an index already exists for the project * * @param projectPath - Absolute path to the project root * @returns true if an index already exists */ export declare function indexExists(projectPath: string): Promise; /** * Create a search index for the current project * * Detects the project root, scans files, chunks content, generates embeddings, * and stores in LanceDB. Returns statistics about the created index. * * Uses the IndexingLock to prevent concurrent indexing operations. * * @param input - The input (empty object, uses project context) * @param context - Tool context containing the project path and optional callbacks * @returns Index creation result with statistics * * @example * ```typescript * const result = await createIndex( * {}, * { * projectPath: '/path/to/project', * confirmed: true, * onProgress: (progress) => console.log(formatProgressMessage(progress)) * } * ); * * console.log(result.status); // 'success' * console.log(result.filesIndexed); // 150 * console.log(result.duration); // '45s' * ``` */ export declare function createIndex(input: CreateIndexInput, context: CreateIndexContext): Promise; /** * MCP tool definition for create_index * * This tool creates a search index for the current project. * It REQUIRES confirmation as it performs file system operations * and may take several minutes for large projects. */ export declare const createIndexTool: { name: string; description: string; inputSchema: { type: "object"; properties: {}; required: string[]; }; requiresConfirmation: boolean; }; /** * Get confirmation message for the tool * * Returns a user-friendly message asking for confirmation before indexing. * * @param projectPath - The detected project path * @returns Confirmation message string */ export declare function getConfirmationMessage(projectPath: string): string; //# sourceMappingURL=createIndex.d.ts.map