@liendev/lien 0.19.1 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/version.ts","../src/constants.ts","../src/config/schema.ts","../src/config/migration.ts","../src/config/merge.ts","../src/errors/codes.ts","../src/errors/index.ts","../src/config/service.ts","../src/git/utils.ts","../src/vectordb/version.ts","../src/indexer/scanner.ts","../src/indexer/symbol-extractor.ts","../src/indexer/ast/parser.ts","../src/indexer/ast/complexity/cyclomatic.ts","../src/indexer/ast/complexity/cognitive.ts","../src/indexer/ast/complexity/halstead.ts","../src/indexer/ast/complexity/index.ts","../src/indexer/ast/symbols.ts","../src/indexer/ast/traversers/typescript.ts","../src/indexer/ast/traversers/php.ts","../src/indexer/ast/traversers/python.ts","../src/indexer/ast/traversers/index.ts","../src/indexer/ast/chunker.ts","../src/indexer/liquid-chunker.ts","../src/indexer/json-template-chunker.ts","../src/indexer/chunker.ts","../src/embeddings/local.ts","../src/embeddings/types.ts","../src/vectordb/relevance.ts","../src/vectordb/intent-classifier.ts","../src/vectordb/boosting/types.ts","../src/vectordb/boosting/strategies.ts","../src/vectordb/boosting/composer.ts","../src/vectordb/boosting/index.ts","../src/vectordb/query.ts","../src/vectordb/batch-insert.ts","../src/vectordb/maintenance.ts","../src/vectordb/lancedb.ts","../src/indexer/manifest.ts","../src/git/tracker.ts","../src/utils/result.ts","../src/indexer/incremental.ts","../src/indexer/change-detector.ts","../src/utils/loading-messages.ts","../src/indexer/progress-tracker.ts","../src/indexer/index.ts","../src/cli/index.ts","../src/cli/init.ts","../src/utils/banner.ts","../src/config/migration-manager.ts","../src/frameworks/detector-service.ts","../src/frameworks/types.ts","../src/frameworks/nodejs/detector.ts","../src/frameworks/nodejs/config.ts","../src/frameworks/php/detector.ts","../src/frameworks/php/config.ts","../src/frameworks/laravel/detector.ts","../src/frameworks/laravel/config.ts","../src/frameworks/shopify/detector.ts","../src/frameworks/shopify/config.ts","../src/frameworks/registry.ts","../src/cli/status.ts","../src/cli/index-cmd.ts","../src/cli/serve.ts","../src/mcp/server.ts","../src/mcp/utils/zod-to-json-schema.ts","../src/mcp/schemas/search.schema.ts","../src/mcp/schemas/similarity.schema.ts","../src/mcp/schemas/file.schema.ts","../src/mcp/schemas/symbols.schema.ts","../src/mcp/schemas/dependents.schema.ts","../src/mcp/schemas/complexity.schema.ts","../src/mcp/tools.ts","../src/mcp/utils/tool-wrapper.ts","../src/mcp/handlers/semantic-search.ts","../src/mcp/handlers/find-similar.ts","../src/mcp/utils/path-matching.ts","../src/mcp/handlers/get-files-context.ts","../src/mcp/handlers/list-functions.ts","../src/mcp/handlers/get-dependents.ts","../src/mcp/handlers/get-complexity.ts","../src/insights/types.ts","../src/indexer/dependency-analyzer.ts","../src/insights/complexity-analyzer.ts","../src/mcp/handlers/index.ts","../src/watcher/index.ts","../src/cli/complexity.ts","../src/insights/formatters/text.ts","../src/insights/formatters/json.ts","../src/insights/formatters/sarif.ts","../src/insights/formatters/index.ts","../src/index.ts"],"sourcesContent":["import { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\n\n/**\n * Centralized package version loader.\n * Handles different build output structures (development vs production).\n * \n * Build scenarios:\n * - Development (ts-node): src/utils/version.ts → ../package.json\n * - Production (dist): dist/utils/version.js → ../package.json\n * - Nested builds: dist/something/version.js → ../../package.json\n */\n\n// Setup require for ESM\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson: { version: string; name?: string };\n\ntry {\n // Try relative to current file (works in most scenarios)\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n try {\n // Fallback: go up one more level (nested build output)\n packageJson = require(join(__dirname, '../../package.json'));\n } catch {\n // Last resort: hardcoded fallback (should never happen in production)\n console.warn('[Lien] Warning: Could not load package.json, using fallback version');\n packageJson = { version: '0.0.0-unknown' };\n }\n}\n\n/**\n * Get the current package version\n */\nexport function getPackageVersion(): string {\n return packageJson.version;\n}\n\n/**\n * Get the full package.json (for compatibility)\n */\nexport function getPackageInfo(): { version: string; name?: string } {\n return packageJson;\n}\n\n","/**\n * Centralized constants for the Lien project.\n * This file contains all magic numbers and configuration defaults\n * to ensure consistency across the codebase.\n */\n\nimport { getPackageVersion } from './utils/version.js';\n\n// Chunking settings\nexport const DEFAULT_CHUNK_SIZE = 75;\nexport const DEFAULT_CHUNK_OVERLAP = 10;\n\n// Concurrency and batching\nexport const DEFAULT_CONCURRENCY = 4;\nexport const DEFAULT_EMBEDDING_BATCH_SIZE = 50;\n\n// Micro-batching for event loop yielding\n// Process N embeddings at a time, then yield to event loop\n// This prevents UI freezing during CPU-intensive embedding generation\nexport const EMBEDDING_MICRO_BATCH_SIZE = 10;\n\n// Vector database batch size limits\n// Maximum batch size before splitting (prevents LanceDB errors on very large batches)\nexport const VECTOR_DB_MAX_BATCH_SIZE = 1000;\n// Minimum batch size for retry logic (stop splitting below this size)\nexport const VECTOR_DB_MIN_BATCH_SIZE = 10;\n\n// Embedding model configuration\nexport const EMBEDDING_DIMENSIONS = 384; // all-MiniLM-L6-v2\nexport const DEFAULT_EMBEDDING_MODEL = 'Xenova/all-MiniLM-L6-v2';\n\n// MCP server configuration\nexport const DEFAULT_PORT = 7133; // LIEN in leetspeak\nexport const VERSION_CHECK_INTERVAL_MS = 2000;\n\n// Git detection\nexport const DEFAULT_GIT_POLL_INTERVAL_MS = 10000; // Check every 10 seconds\n\n// File watching\nexport const DEFAULT_DEBOUNCE_MS = 1000;\n\n// Configuration version - always matches package version\n// Config format is tied to the package release that introduces it\nexport const CURRENT_CONFIG_VERSION = getPackageVersion();\n\n// Index format version - bump on ANY breaking change to indexing\n// Examples that require version bump:\n// - Chunking algorithm changes\n// - Embedding model changes (e.g., switch from all-MiniLM-L6-v2 to another model)\n// - Vector DB schema changes (new metadata fields)\n// - Metadata structure changes\n// v2: AST-based chunking + enhanced metadata (symbolName, complexity, etc.)\n// v3: Added cognitiveComplexity field to schema\n// v4: Added Halstead metrics (volume, difficulty, effort, bugs)\nexport const INDEX_FORMAT_VERSION = 4;\n\n","import {\n DEFAULT_CHUNK_SIZE,\n DEFAULT_CHUNK_OVERLAP,\n DEFAULT_CONCURRENCY,\n DEFAULT_EMBEDDING_BATCH_SIZE,\n DEFAULT_PORT,\n DEFAULT_GIT_POLL_INTERVAL_MS,\n DEFAULT_DEBOUNCE_MS,\n CURRENT_CONFIG_VERSION,\n} from '../constants.js';\n\n/**\n * Framework-specific configuration\n */\nexport interface FrameworkConfig {\n include: string[]; // File patterns relative to framework path\n exclude: string[]; // Exclude patterns relative to framework path\n}\n\n/**\n * Framework instance in a monorepo\n */\nexport interface FrameworkInstance {\n name: string; // 'nodejs', 'laravel'\n path: string; // '.', 'cognito-backend', 'packages/cli'\n enabled: boolean;\n config: FrameworkConfig;\n}\n\n/**\n * Main Lien configuration supporting monorepo setups\n */\nexport interface LienConfig {\n version: string;\n core: {\n chunkSize: number;\n chunkOverlap: number;\n concurrency: number;\n embeddingBatchSize: number;\n };\n chunking: {\n useAST: boolean; // Enable AST-based chunking (v0.13.0)\n astFallback: 'line-based' | 'error'; // Fallback strategy on AST errors\n };\n mcp: {\n port: number;\n transport: 'stdio' | 'socket';\n autoIndexOnFirstRun: boolean;\n };\n gitDetection: {\n enabled: boolean;\n pollIntervalMs: number;\n };\n fileWatching: {\n enabled: boolean;\n debounceMs: number;\n };\n complexity?: {\n enabled: boolean;\n thresholds: {\n testPaths: number; // 🔀 Max test paths per function (default: 15)\n mentalLoad: number; // 🧠 Max mental load score (default: 15)\n timeToUnderstandMinutes?: number; // ⏱️ Max minutes to understand (default: 60)\n estimatedBugs?: number; // 🐛 Max estimated bugs (default: 1.5)\n };\n // Severity multipliers are hardcoded: warning = 1x threshold, error = 2x threshold\n };\n frameworks: FrameworkInstance[];\n}\n\n/**\n * Legacy config format for backwards compatibility\n * @deprecated Use LienConfig with frameworks array instead\n */\nexport interface LegacyLienConfig {\n version: string;\n indexing: {\n exclude: string[];\n include: string[];\n chunkSize: number;\n chunkOverlap: number;\n concurrency: number;\n embeddingBatchSize: number;\n };\n mcp: {\n port: number;\n transport: 'stdio' | 'socket';\n autoIndexOnFirstRun: boolean;\n };\n gitDetection: {\n enabled: boolean;\n pollIntervalMs: number;\n };\n fileWatching: {\n enabled: boolean;\n debounceMs: number;\n };\n}\n\n/**\n * Type guard to check if a config is the legacy format\n * @param config - Config object to check\n * @returns True if config is LegacyLienConfig\n */\nexport function isLegacyConfig(\n config: LienConfig | LegacyLienConfig\n): config is LegacyLienConfig {\n return 'indexing' in config && !('frameworks' in config);\n}\n\n/**\n * Type guard to check if a config is the modern format\n * @param config - Config object to check\n * @returns True if config is LienConfig\n */\nexport function isModernConfig(\n config: LienConfig | LegacyLienConfig\n): config is LienConfig {\n return 'frameworks' in config;\n}\n\n/**\n * Default configuration with empty frameworks array\n * Frameworks should be detected and added via lien init\n */\nexport const defaultConfig: LienConfig = {\n version: CURRENT_CONFIG_VERSION,\n core: {\n chunkSize: DEFAULT_CHUNK_SIZE,\n chunkOverlap: DEFAULT_CHUNK_OVERLAP,\n concurrency: DEFAULT_CONCURRENCY,\n embeddingBatchSize: DEFAULT_EMBEDDING_BATCH_SIZE,\n },\n chunking: {\n useAST: true, // AST-based chunking enabled by default (v0.13.0)\n astFallback: 'line-based', // Fallback to line-based on errors\n },\n mcp: {\n port: DEFAULT_PORT,\n transport: 'stdio',\n autoIndexOnFirstRun: true,\n },\n gitDetection: {\n enabled: true,\n pollIntervalMs: DEFAULT_GIT_POLL_INTERVAL_MS,\n },\n fileWatching: {\n enabled: true, // Enabled by default (fast with incremental indexing!)\n debounceMs: DEFAULT_DEBOUNCE_MS,\n },\n complexity: {\n enabled: true,\n thresholds: {\n testPaths: 15, // 🔀 Max test paths per function\n mentalLoad: 15, // 🧠 Max mental load score\n timeToUnderstandMinutes: 60, // ⏱️ Functions taking >1 hour to understand\n estimatedBugs: 1.5, // 🐛 Functions estimated to have >1.5 bugs\n },\n },\n frameworks: [], // Will be populated by lien init via framework detection\n};\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { LienConfig, LegacyLienConfig, FrameworkInstance, defaultConfig } from './schema.js';\nimport { CURRENT_CONFIG_VERSION } from '../constants.js';\n\n/**\n * Checks if a config object needs migration from v0.2.0 to v0.3.0\n */\nexport function needsMigration(config: any): boolean {\n // Check if config uses old structure:\n // - Has 'indexing' field instead of 'core' and 'frameworks'\n // - Or has no 'frameworks' field at all\n // - Or version is explicitly set to something < 0.3.0\n // - Or missing 'chunking' field (v0.13.0)\n if (!config) {\n return false;\n }\n\n // If missing chunking config, needs migration to v0.13.0\n if (config.frameworks !== undefined && !config.chunking) {\n return true;\n }\n\n // If it has frameworks array and chunking, it's already in new format\n if (config.frameworks !== undefined && config.chunking !== undefined) {\n return false;\n }\n\n // If it has 'indexing' field, it's the old format\n if (config.indexing !== undefined) {\n return true;\n }\n\n // If version is explicitly < 0.3.0\n if (config.version && config.version.startsWith('0.2')) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Migrates a v0.2.0 config to v0.3.0+ format\n */\nexport function migrateConfig(oldConfig: Partial<LegacyLienConfig | LienConfig>): LienConfig {\n // Start with default config structure\n const newConfig: LienConfig = {\n version: CURRENT_CONFIG_VERSION,\n core: {\n chunkSize: (oldConfig as any).indexing?.chunkSize ?? (oldConfig as any).core?.chunkSize ?? defaultConfig.core.chunkSize,\n chunkOverlap: (oldConfig as any).indexing?.chunkOverlap ?? (oldConfig as any).core?.chunkOverlap ?? defaultConfig.core.chunkOverlap,\n concurrency: (oldConfig as any).indexing?.concurrency ?? (oldConfig as any).core?.concurrency ?? defaultConfig.core.concurrency,\n embeddingBatchSize: (oldConfig as any).indexing?.embeddingBatchSize ?? (oldConfig as any).core?.embeddingBatchSize ?? defaultConfig.core.embeddingBatchSize,\n },\n chunking: {\n useAST: (oldConfig as any).chunking?.useAST ?? defaultConfig.chunking.useAST,\n astFallback: (oldConfig as any).chunking?.astFallback ?? defaultConfig.chunking.astFallback,\n },\n mcp: {\n port: oldConfig.mcp?.port ?? defaultConfig.mcp.port,\n transport: oldConfig.mcp?.transport ?? defaultConfig.mcp.transport,\n autoIndexOnFirstRun: oldConfig.mcp?.autoIndexOnFirstRun ?? defaultConfig.mcp.autoIndexOnFirstRun,\n },\n gitDetection: {\n enabled: oldConfig.gitDetection?.enabled ?? defaultConfig.gitDetection.enabled,\n pollIntervalMs: oldConfig.gitDetection?.pollIntervalMs ?? defaultConfig.gitDetection.pollIntervalMs,\n },\n fileWatching: {\n enabled: oldConfig.fileWatching?.enabled ?? defaultConfig.fileWatching.enabled,\n debounceMs: oldConfig.fileWatching?.debounceMs ?? defaultConfig.fileWatching.debounceMs,\n },\n frameworks: (oldConfig as any).frameworks ?? [],\n };\n\n // Convert old indexing config to a single \"generic\" framework (only for legacy configs)\n if ((oldConfig as any).indexing && newConfig.frameworks.length === 0) {\n const genericFramework: FrameworkInstance = {\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: (oldConfig as any).indexing.include ?? ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: (oldConfig as any).indexing.exclude ?? [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n };\n\n newConfig.frameworks.push(genericFramework);\n } else if (newConfig.frameworks.length === 0) {\n // No indexing config and no frameworks present, use defaults for generic framework\n const genericFramework: FrameworkInstance = {\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n };\n\n newConfig.frameworks.push(genericFramework);\n }\n\n return newConfig;\n}\n\n/**\n * Migrates config file and creates backup\n */\nexport async function migrateConfigFile(rootDir: string = process.cwd()): Promise<{\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}> {\n const configPath = path.join(rootDir, '.lien.config.json');\n\n try {\n // Read existing config\n const configContent = await fs.readFile(configPath, 'utf-8');\n const oldConfig = JSON.parse(configContent);\n\n // Check if migration is needed\n if (!needsMigration(oldConfig)) {\n return {\n migrated: false,\n config: oldConfig as LienConfig,\n };\n }\n\n // Perform migration\n const newConfig = migrateConfig(oldConfig);\n\n // Create backup\n const backupPath = `${configPath}.v0.2.0.backup`;\n await fs.copyFile(configPath, backupPath);\n\n // Write migrated config\n await fs.writeFile(configPath, JSON.stringify(newConfig, null, 2) + '\\n', 'utf-8');\n\n return {\n migrated: true,\n backupPath,\n config: newConfig,\n };\n } catch (error) {\n // If config doesn't exist, return default\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return {\n migrated: false,\n config: defaultConfig,\n };\n }\n throw error;\n }\n}\n\n","import { LienConfig } from './schema.js';\n\n/**\n * Deep merges user config with defaults, preserving user customizations.\n * User values always take precedence over defaults.\n * \n * @param defaults - The default configuration\n * @param user - The user's partial configuration\n * @returns Complete merged configuration\n */\nexport function deepMergeConfig(defaults: LienConfig, user: Partial<LienConfig>): LienConfig {\n return {\n version: user.version ?? defaults.version,\n core: {\n ...defaults.core,\n ...user.core,\n },\n chunking: {\n ...defaults.chunking,\n ...user.chunking,\n },\n mcp: {\n ...defaults.mcp,\n ...user.mcp,\n },\n gitDetection: {\n ...defaults.gitDetection,\n ...user.gitDetection,\n },\n fileWatching: {\n ...defaults.fileWatching,\n ...user.fileWatching,\n },\n complexity: user.complexity ? {\n enabled: user.complexity.enabled ?? defaults.complexity?.enabled ?? true,\n thresholds: {\n ...defaults.complexity?.thresholds,\n ...(user.complexity.thresholds || {}),\n },\n } : defaults.complexity,\n frameworks: user.frameworks ?? defaults.frameworks,\n };\n}\n\n/**\n * Detects new fields that exist in the 'after' config but not in the 'before' config.\n * Returns a list of human-readable field paths.\n * \n * @param before - The existing config (potentially missing fields)\n * @param after - The complete config with all fields\n * @returns Array of new field paths (e.g., [\"mcp.autoIndexOnFirstRun\", \"gitDetection\"])\n */\nexport function detectNewFields(before: Record<string, any>, after: Record<string, any>): string[] {\n const newFields: string[] = [];\n\n // Check top-level sections\n for (const key of Object.keys(after)) {\n if (!(key in before)) {\n newFields.push(key);\n continue;\n }\n\n // Check nested fields for object sections\n if (typeof after[key] === 'object' && after[key] !== null && !Array.isArray(after[key])) {\n const beforeSection = (before[key] as Record<string, any>) || {};\n const afterSection = after[key] as Record<string, any>;\n\n for (const nestedKey of Object.keys(afterSection)) {\n if (!(nestedKey in beforeSection)) {\n newFields.push(`${key}.${nestedKey}`);\n }\n }\n }\n }\n\n return newFields;\n}\n\n","/**\n * Error codes for all Lien-specific errors.\n * Used to identify error types programmatically.\n */\nexport enum LienErrorCode {\n // Configuration\n CONFIG_NOT_FOUND = 'CONFIG_NOT_FOUND',\n CONFIG_INVALID = 'CONFIG_INVALID',\n \n // Index\n INDEX_NOT_FOUND = 'INDEX_NOT_FOUND',\n INDEX_CORRUPTED = 'INDEX_CORRUPTED',\n \n // Embeddings\n EMBEDDING_MODEL_FAILED = 'EMBEDDING_MODEL_FAILED',\n EMBEDDING_GENERATION_FAILED = 'EMBEDDING_GENERATION_FAILED',\n \n // File System\n FILE_NOT_FOUND = 'FILE_NOT_FOUND',\n FILE_NOT_READABLE = 'FILE_NOT_READABLE',\n INVALID_PATH = 'INVALID_PATH',\n \n // Tool Input\n INVALID_INPUT = 'INVALID_INPUT',\n \n // System\n INTERNAL_ERROR = 'INTERNAL_ERROR',\n}\n\n","import { LienErrorCode } from './codes.js';\n\n// Re-export for consumers\nexport { LienErrorCode } from './codes.js';\n\n/**\n * Severity levels for errors\n */\nexport type ErrorSeverity = 'low' | 'medium' | 'high' | 'critical';\n\n/**\n * Base error class for all Lien-specific errors\n */\nexport class LienError extends Error {\n constructor(\n message: string,\n public readonly code: LienErrorCode,\n public readonly context?: Record<string, unknown>,\n public readonly severity: ErrorSeverity = 'medium',\n public readonly recoverable: boolean = true,\n public readonly retryable: boolean = false\n ) {\n super(message);\n this.name = 'LienError';\n \n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n \n /**\n * Serialize error to JSON for MCP responses\n */\n toJSON() {\n return {\n error: this.message,\n code: this.code,\n severity: this.severity,\n recoverable: this.recoverable,\n context: this.context,\n };\n }\n \n /**\n * Check if this error is retryable\n */\n isRetryable(): boolean {\n return this.retryable;\n }\n \n /**\n * Check if this error is recoverable\n */\n isRecoverable(): boolean {\n return this.recoverable;\n }\n}\n\n/**\n * Configuration-related errors (loading, parsing, migration)\n */\nexport class ConfigError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.CONFIG_INVALID, context, 'medium', true, false);\n this.name = 'ConfigError';\n }\n}\n\n/**\n * Indexing-related errors (file processing, chunking)\n */\nexport class IndexingError extends LienError {\n constructor(\n message: string,\n public readonly file?: string,\n context?: Record<string, unknown>\n ) {\n super(message, LienErrorCode.INTERNAL_ERROR, { ...context, file }, 'medium', true, false);\n this.name = 'IndexingError';\n }\n}\n\n/**\n * Embedding generation errors\n */\nexport class EmbeddingError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.EMBEDDING_GENERATION_FAILED, context, 'high', true, true);\n this.name = 'EmbeddingError';\n }\n}\n\n/**\n * Vector database errors (connection, query, storage)\n */\nexport class DatabaseError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.INTERNAL_ERROR, context, 'high', true, true);\n this.name = 'DatabaseError';\n }\n}\n\n/**\n * Helper function to wrap unknown errors with context\n * @param error - Unknown error object to wrap\n * @param context - Context message describing what operation failed\n * @param additionalContext - Optional additional context data\n * @returns LienError with proper message and context\n */\nexport function wrapError(\n error: unknown,\n context: string,\n additionalContext?: Record<string, unknown>\n): LienError {\n const message = error instanceof Error ? error.message : String(error);\n const stack = error instanceof Error ? error.stack : undefined;\n \n const wrappedError = new LienError(\n `${context}: ${message}`,\n LienErrorCode.INTERNAL_ERROR,\n additionalContext\n );\n \n // Preserve original stack trace if available\n if (stack) {\n wrappedError.stack = `${wrappedError.stack}\\n\\nCaused by:\\n${stack}`;\n }\n \n return wrappedError;\n}\n\n/**\n * Type guard to check if an error is a LienError\n */\nexport function isLienError(error: unknown): error is LienError {\n return error instanceof LienError;\n}\n\n/**\n * Extract error message from unknown error type\n * @param error - Unknown error object\n * @returns Error message string\n */\nexport function getErrorMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Extract stack trace from unknown error type\n * @param error - Unknown error object\n * @returns Stack trace string or undefined\n */\nexport function getErrorStack(error: unknown): string | undefined {\n if (error instanceof Error) {\n return error.stack;\n }\n return undefined;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { LienConfig, LegacyLienConfig, defaultConfig, isLegacyConfig, isModernConfig } from './schema.js';\nimport { deepMergeConfig } from './merge.js';\nimport { needsMigration as checkNeedsMigration, migrateConfig as performMigration } from './migration.js';\nimport { ConfigError, wrapError } from '../errors/index.js';\n\n/**\n * Validation result with errors and warnings\n */\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n warnings: string[];\n}\n\n/**\n * Migration result with status and config\n */\nexport interface MigrationResult {\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}\n\n/**\n * ConfigService encapsulates all configuration operations including\n * loading, saving, migration, and validation.\n * \n * This service provides a single point of truth for config management\n * with comprehensive error handling and validation.\n */\nexport class ConfigService {\n private static readonly CONFIG_FILENAME = '.lien.config.json';\n \n /**\n * Load configuration from the specified directory.\n * Automatically handles migration if needed.\n * \n * @param rootDir - Root directory containing the config file\n * @returns Loaded and validated configuration\n * @throws {ConfigError} If config is invalid or cannot be loaded\n */\n async load(rootDir: string = process.cwd()): Promise<LienConfig> {\n const configPath = this.getConfigPath(rootDir);\n \n try {\n const configContent = await fs.readFile(configPath, 'utf-8');\n const userConfig = JSON.parse(configContent);\n \n // Check if migration is needed\n if (this.needsMigration(userConfig)) {\n console.log('🔄 Migrating config from v0.2.0 to v0.3.0...');\n \n const result = await this.migrate(rootDir);\n \n if (result.migrated && result.backupPath) {\n const backupFilename = path.basename(result.backupPath);\n console.log(`✅ Migration complete! Backup saved as ${backupFilename}`);\n console.log('📝 Your config now uses the framework-based structure.');\n }\n \n return result.config;\n }\n \n // Merge with defaults first\n const mergedConfig = deepMergeConfig(defaultConfig, userConfig as Partial<LienConfig>);\n \n // Then validate the merged config\n const validation = this.validate(mergedConfig);\n if (!validation.valid) {\n throw new ConfigError(\n `Invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors, warnings: validation.warnings }\n );\n }\n \n // Show warnings if any\n if (validation.warnings.length > 0) {\n console.warn('⚠️ Configuration warnings:');\n validation.warnings.forEach(warning => console.warn(` ${warning}`));\n }\n \n return mergedConfig;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n // Config doesn't exist, return defaults\n return defaultConfig;\n }\n \n if (error instanceof ConfigError) {\n throw error;\n }\n \n if (error instanceof SyntaxError) {\n throw new ConfigError(\n 'Failed to parse config file: Invalid JSON syntax',\n { path: configPath, originalError: error.message }\n );\n }\n \n throw wrapError(error, 'Failed to load configuration', { path: configPath });\n }\n }\n \n /**\n * Save configuration to the specified directory.\n * Validates the config before saving.\n * \n * @param rootDir - Root directory to save the config file\n * @param config - Configuration to save\n * @throws {ConfigError} If config is invalid or cannot be saved\n */\n async save(rootDir: string, config: LienConfig): Promise<void> {\n const configPath = this.getConfigPath(rootDir);\n \n // Validate before saving\n const validation = this.validate(config);\n if (!validation.valid) {\n throw new ConfigError(\n `Cannot save invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors }\n );\n }\n \n try {\n const configJson = JSON.stringify(config, null, 2) + '\\n';\n await fs.writeFile(configPath, configJson, 'utf-8');\n } catch (error) {\n throw wrapError(error, 'Failed to save configuration', { path: configPath });\n }\n }\n \n /**\n * Check if a configuration file exists in the specified directory.\n * \n * @param rootDir - Root directory to check\n * @returns True if config file exists\n */\n async exists(rootDir: string = process.cwd()): Promise<boolean> {\n const configPath = this.getConfigPath(rootDir);\n try {\n await fs.access(configPath);\n return true;\n } catch {\n return false;\n }\n }\n \n /**\n * Migrate configuration from v0.2.0 to v0.3.0 format.\n * Creates a backup of the original config file.\n * \n * @param rootDir - Root directory containing the config file\n * @returns Migration result with status and new config\n * @throws {ConfigError} If migration fails\n */\n async migrate(rootDir: string = process.cwd()): Promise<MigrationResult> {\n const configPath = this.getConfigPath(rootDir);\n \n try {\n // Read existing config\n const configContent = await fs.readFile(configPath, 'utf-8');\n const oldConfig = JSON.parse(configContent);\n \n // Check if migration is needed\n if (!this.needsMigration(oldConfig)) {\n return {\n migrated: false,\n config: oldConfig as LienConfig,\n };\n }\n \n // Perform migration\n const newConfig = performMigration(oldConfig);\n \n // Validate migrated config\n const validation = this.validate(newConfig);\n if (!validation.valid) {\n throw new ConfigError(\n `Migration produced invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors }\n );\n }\n \n // Create backup\n const backupPath = `${configPath}.v0.2.0.backup`;\n await fs.copyFile(configPath, backupPath);\n \n // Write migrated config\n await this.save(rootDir, newConfig);\n \n return {\n migrated: true,\n backupPath,\n config: newConfig,\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return {\n migrated: false,\n config: defaultConfig,\n };\n }\n \n if (error instanceof ConfigError) {\n throw error;\n }\n \n throw wrapError(error, 'Configuration migration failed', { path: configPath });\n }\n }\n \n /**\n * Check if a config object needs migration from v0.2.0 to v0.3.0.\n * \n * @param config - Config object to check\n * @returns True if migration is needed\n */\n needsMigration(config: unknown): boolean {\n return checkNeedsMigration(config);\n }\n \n /**\n * Validate a configuration object.\n * Checks all constraints and returns detailed validation results.\n * \n * @param config - Configuration to validate\n * @returns Validation result with errors and warnings\n */\n validate(config: unknown): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n \n // Type check\n if (!config || typeof config !== 'object') {\n return {\n valid: false,\n errors: ['Configuration must be an object'],\n warnings: [],\n };\n }\n \n const cfg = config as Partial<LienConfig>;\n \n // Check for required top-level fields\n if (!cfg.version) {\n errors.push('Missing required field: version');\n }\n \n // Validate based on config type\n if (isModernConfig(cfg as LienConfig | LegacyLienConfig)) {\n this.validateModernConfig(cfg as LienConfig, errors, warnings);\n } else if (isLegacyConfig(cfg as LienConfig | LegacyLienConfig)) {\n this.validateLegacyConfig(cfg as LegacyLienConfig, errors, warnings);\n } else {\n errors.push('Configuration format not recognized. Must have either \"frameworks\" or \"indexing\" field');\n }\n \n return {\n valid: errors.length === 0,\n errors,\n warnings,\n };\n }\n \n /**\n * Validate a partial configuration object.\n * Useful for validating user input before merging with defaults.\n * \n * @param config - Partial configuration to validate\n * @returns Validation result with errors and warnings\n */\n validatePartial(config: Partial<LienConfig>): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n \n // Validate core settings if present\n if (config.core) {\n this.validateCoreConfig(config.core, errors, warnings);\n }\n \n // Validate MCP settings if present\n if (config.mcp) {\n this.validateMCPConfig(config.mcp, errors, warnings);\n }\n \n // Validate git detection settings if present\n if (config.gitDetection) {\n this.validateGitDetectionConfig(config.gitDetection, errors, warnings);\n }\n \n // Validate file watching settings if present\n if (config.fileWatching) {\n this.validateFileWatchingConfig(config.fileWatching, errors, warnings);\n }\n \n // Validate frameworks if present\n if (config.frameworks) {\n this.validateFrameworks(config.frameworks, errors, warnings);\n }\n \n return {\n valid: errors.length === 0,\n errors,\n warnings,\n };\n }\n \n /**\n * Get the full path to the config file\n */\n private getConfigPath(rootDir: string): string {\n return path.join(rootDir, ConfigService.CONFIG_FILENAME);\n }\n \n /**\n * Validate modern (v0.3.0+) configuration\n */\n private validateModernConfig(\n config: LienConfig,\n errors: string[],\n warnings: string[]\n ): void {\n // Validate core settings\n if (!config.core) {\n errors.push('Missing required field: core');\n return;\n }\n this.validateCoreConfig(config.core, errors, warnings);\n \n // Validate MCP settings\n if (!config.mcp) {\n errors.push('Missing required field: mcp');\n return;\n }\n this.validateMCPConfig(config.mcp, errors, warnings);\n \n // Validate git detection settings\n if (!config.gitDetection) {\n errors.push('Missing required field: gitDetection');\n return;\n }\n this.validateGitDetectionConfig(config.gitDetection, errors, warnings);\n \n // Validate file watching settings\n if (!config.fileWatching) {\n errors.push('Missing required field: fileWatching');\n return;\n }\n this.validateFileWatchingConfig(config.fileWatching, errors, warnings);\n \n // Validate frameworks\n if (!config.frameworks) {\n errors.push('Missing required field: frameworks');\n return;\n }\n this.validateFrameworks(config.frameworks, errors, warnings);\n }\n \n /**\n * Validate legacy (v0.2.0) configuration\n */\n private validateLegacyConfig(\n config: LegacyLienConfig,\n errors: string[],\n warnings: string[]\n ): void {\n warnings.push('Using legacy configuration format. Consider running \"lien init\" to migrate to v0.3.0');\n \n // Validate indexing settings\n if (!config.indexing) {\n errors.push('Missing required field: indexing');\n return;\n }\n \n const { indexing } = config;\n \n if (typeof indexing.chunkSize !== 'number' || indexing.chunkSize <= 0) {\n errors.push('indexing.chunkSize must be a positive number');\n }\n \n if (typeof indexing.chunkOverlap !== 'number' || indexing.chunkOverlap < 0) {\n errors.push('indexing.chunkOverlap must be a non-negative number');\n }\n \n if (typeof indexing.concurrency !== 'number' || indexing.concurrency < 1 || indexing.concurrency > 16) {\n errors.push('indexing.concurrency must be between 1 and 16');\n }\n \n if (typeof indexing.embeddingBatchSize !== 'number' || indexing.embeddingBatchSize <= 0) {\n errors.push('indexing.embeddingBatchSize must be a positive number');\n }\n \n // Validate MCP settings (same for both)\n if (config.mcp) {\n this.validateMCPConfig(config.mcp, errors, warnings);\n }\n }\n \n /**\n * Validate core configuration settings\n */\n private validateCoreConfig(\n core: Partial<LienConfig['core']>,\n errors: string[],\n warnings: string[]\n ): void {\n if (core.chunkSize !== undefined) {\n if (typeof core.chunkSize !== 'number' || core.chunkSize <= 0) {\n errors.push('core.chunkSize must be a positive number');\n } else if (core.chunkSize < 50) {\n warnings.push('core.chunkSize is very small (<50 lines). This may result in poor search quality');\n } else if (core.chunkSize > 500) {\n warnings.push('core.chunkSize is very large (>500 lines). This may impact performance');\n }\n }\n \n if (core.chunkOverlap !== undefined) {\n if (typeof core.chunkOverlap !== 'number' || core.chunkOverlap < 0) {\n errors.push('core.chunkOverlap must be a non-negative number');\n }\n }\n \n if (core.concurrency !== undefined) {\n if (typeof core.concurrency !== 'number' || core.concurrency < 1 || core.concurrency > 16) {\n errors.push('core.concurrency must be between 1 and 16');\n }\n }\n \n if (core.embeddingBatchSize !== undefined) {\n if (typeof core.embeddingBatchSize !== 'number' || core.embeddingBatchSize <= 0) {\n errors.push('core.embeddingBatchSize must be a positive number');\n } else if (core.embeddingBatchSize > 100) {\n warnings.push('core.embeddingBatchSize is very large (>100). This may cause memory issues');\n }\n }\n }\n \n /**\n * Validate MCP configuration settings\n */\n private validateMCPConfig(\n mcp: Partial<LienConfig['mcp']>,\n errors: string[],\n _warnings: string[]\n ): void {\n if (mcp.port !== undefined) {\n if (typeof mcp.port !== 'number' || mcp.port < 1024 || mcp.port > 65535) {\n errors.push('mcp.port must be between 1024 and 65535');\n }\n }\n \n if (mcp.transport !== undefined) {\n if (mcp.transport !== 'stdio' && mcp.transport !== 'socket') {\n errors.push('mcp.transport must be either \"stdio\" or \"socket\"');\n }\n }\n \n if (mcp.autoIndexOnFirstRun !== undefined) {\n if (typeof mcp.autoIndexOnFirstRun !== 'boolean') {\n errors.push('mcp.autoIndexOnFirstRun must be a boolean');\n }\n }\n }\n \n /**\n * Validate git detection configuration settings\n */\n private validateGitDetectionConfig(\n gitDetection: Partial<LienConfig['gitDetection']>,\n errors: string[],\n _warnings: string[]\n ): void {\n if (gitDetection.enabled !== undefined) {\n if (typeof gitDetection.enabled !== 'boolean') {\n errors.push('gitDetection.enabled must be a boolean');\n }\n }\n \n if (gitDetection.pollIntervalMs !== undefined) {\n if (typeof gitDetection.pollIntervalMs !== 'number' || gitDetection.pollIntervalMs < 100) {\n errors.push('gitDetection.pollIntervalMs must be at least 100ms');\n } else if (gitDetection.pollIntervalMs < 1000) {\n _warnings.push('gitDetection.pollIntervalMs is very short (<1s). This may impact performance');\n }\n }\n }\n \n /**\n * Validate file watching configuration settings\n */\n private validateFileWatchingConfig(\n fileWatching: Partial<LienConfig['fileWatching']>,\n errors: string[],\n warnings: string[]\n ): void {\n if (fileWatching.enabled !== undefined) {\n if (typeof fileWatching.enabled !== 'boolean') {\n errors.push('fileWatching.enabled must be a boolean');\n }\n }\n \n if (fileWatching.debounceMs !== undefined) {\n if (typeof fileWatching.debounceMs !== 'number' || fileWatching.debounceMs < 0) {\n errors.push('fileWatching.debounceMs must be a non-negative number');\n } else if (fileWatching.debounceMs < 100) {\n warnings.push('fileWatching.debounceMs is very short (<100ms). This may cause excessive reindexing');\n }\n }\n }\n \n /**\n * Validate frameworks configuration\n */\n private validateFrameworks(\n frameworks: unknown[],\n errors: string[],\n warnings: string[]\n ): void {\n if (!Array.isArray(frameworks)) {\n errors.push('frameworks must be an array');\n return;\n }\n \n frameworks.forEach((framework, index) => {\n if (!framework || typeof framework !== 'object') {\n errors.push(`frameworks[${index}] must be an object`);\n return;\n }\n \n const fw = framework as Partial<any>;\n \n // Validate required fields\n if (!fw.name) {\n errors.push(`frameworks[${index}] missing required field: name`);\n }\n \n if (fw.path === undefined) {\n errors.push(`frameworks[${index}] missing required field: path`);\n } else if (typeof fw.path !== 'string') {\n errors.push(`frameworks[${index}].path must be a string`);\n } else if (path.isAbsolute(fw.path)) {\n errors.push(`frameworks[${index}].path must be relative, got: ${fw.path}`);\n }\n \n if (fw.enabled === undefined) {\n errors.push(`frameworks[${index}] missing required field: enabled`);\n } else if (typeof fw.enabled !== 'boolean') {\n errors.push(`frameworks[${index}].enabled must be a boolean`);\n }\n \n if (!fw.config) {\n errors.push(`frameworks[${index}] missing required field: config`);\n } else {\n this.validateFrameworkConfig(fw.config, `frameworks[${index}].config`, errors, warnings);\n }\n });\n }\n \n /**\n * Validate framework-specific configuration\n */\n private validateFrameworkConfig(\n config: any,\n prefix: string,\n errors: string[],\n _warnings: string[]\n ): void {\n if (!config || typeof config !== 'object') {\n errors.push(`${prefix} must be an object`);\n return;\n }\n \n // Validate include patterns\n if (!Array.isArray(config.include)) {\n errors.push(`${prefix}.include must be an array`);\n } else {\n config.include.forEach((pattern: unknown, i: number) => {\n if (typeof pattern !== 'string') {\n errors.push(`${prefix}.include[${i}] must be a string`);\n }\n });\n }\n \n // Validate exclude patterns\n if (!Array.isArray(config.exclude)) {\n errors.push(`${prefix}.exclude must be an array`);\n } else {\n config.exclude.forEach((pattern: unknown, i: number) => {\n if (typeof pattern !== 'string') {\n errors.push(`${prefix}.exclude[${i}] must be a string`);\n }\n });\n }\n }\n}\n\n// Export a singleton instance for convenience\nexport const configService = new ConfigService();\n\n","import { exec } from 'child_process';\nimport { promisify } from 'util';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nconst execAsync = promisify(exec);\n\n/**\n * Checks if a directory is a git repository.\n * \n * @param rootDir - Directory to check\n * @returns true if directory is a git repo, false otherwise\n */\nexport async function isGitRepo(rootDir: string): Promise<boolean> {\n try {\n const gitDir = path.join(rootDir, '.git');\n await fs.access(gitDir);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Gets the current git branch name.\n * \n * @param rootDir - Root directory of the git repository\n * @returns Branch name (e.g., \"main\", \"feature-branch\")\n * @throws Error if not a git repo or git command fails\n */\nexport async function getCurrentBranch(rootDir: string): Promise<string> {\n try {\n const { stdout } = await execAsync('git rev-parse --abbrev-ref HEAD', {\n cwd: rootDir,\n timeout: 5000, // 5 second timeout\n });\n return stdout.trim();\n } catch (error) {\n throw new Error(`Failed to get current branch: ${error}`);\n }\n}\n\n/**\n * Gets the current git commit SHA (HEAD).\n * \n * @param rootDir - Root directory of the git repository\n * @returns Commit SHA (full 40-character hash)\n * @throws Error if not a git repo or git command fails\n */\nexport async function getCurrentCommit(rootDir: string): Promise<string> {\n try {\n const { stdout } = await execAsync('git rev-parse HEAD', {\n cwd: rootDir,\n timeout: 5000,\n });\n return stdout.trim();\n } catch (error) {\n throw new Error(`Failed to get current commit: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed between two git references.\n * \n * @param rootDir - Root directory of the git repository\n * @param fromRef - Starting reference (branch name, commit SHA, or tag)\n * @param toRef - Ending reference (branch name, commit SHA, or tag)\n * @returns Array of file paths (relative to repo root) that changed\n * @throws Error if git command fails\n */\nexport async function getChangedFiles(\n rootDir: string,\n fromRef: string,\n toRef: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff --name-only ${fromRef}...${toRef}`,\n {\n cwd: rootDir,\n timeout: 10000, // 10 second timeout for diffs\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed in a specific commit.\n * \n * @param rootDir - Root directory of the git repository\n * @param commitSha - Commit SHA to check\n * @returns Array of file paths (absolute) that changed in this commit\n * @throws Error if git command fails\n */\nexport async function getChangedFilesInCommit(\n rootDir: string,\n commitSha: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff-tree --no-commit-id --name-only -r ${commitSha}`,\n {\n cwd: rootDir,\n timeout: 10000,\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files in commit: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed between two commits.\n * More efficient than getChangedFiles for commit-to-commit comparisons.\n * \n * @param rootDir - Root directory of the git repository\n * @param fromCommit - Starting commit SHA\n * @param toCommit - Ending commit SHA\n * @returns Array of file paths (absolute) that changed between commits\n * @throws Error if git command fails\n */\nexport async function getChangedFilesBetweenCommits(\n rootDir: string,\n fromCommit: string,\n toCommit: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff --name-only ${fromCommit} ${toCommit}`,\n {\n cwd: rootDir,\n timeout: 10000,\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files between commits: ${error}`);\n }\n}\n\n/**\n * Checks if git is installed and available.\n * \n * @returns true if git is available, false otherwise\n */\nexport async function isGitAvailable(): Promise<boolean> {\n try {\n await execAsync('git --version', { timeout: 3000 });\n return true;\n } catch {\n return false;\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\n\nconst VERSION_FILE = '.lien-index-version';\n\n/**\n * Writes a version timestamp file to mark when the index was last updated.\n * This file is used by the MCP server to detect when it needs to reconnect.\n * \n * @param indexPath - Path to the index directory\n */\nexport async function writeVersionFile(indexPath: string): Promise<void> {\n try {\n const versionFilePath = path.join(indexPath, VERSION_FILE);\n const timestamp = Date.now().toString();\n await fs.writeFile(versionFilePath, timestamp, 'utf-8');\n } catch (error) {\n // Don't throw - version file is a convenience feature, not critical\n console.error(`Warning: Failed to write version file: ${error}`);\n }\n}\n\n/**\n * Reads the version timestamp from the index directory.\n * Returns 0 if the file doesn't exist (e.g., old index).\n * \n * @param indexPath - Path to the index directory\n * @returns Version timestamp, or 0 if not found\n */\nexport async function readVersionFile(indexPath: string): Promise<number> {\n try {\n const versionFilePath = path.join(indexPath, VERSION_FILE);\n const content = await fs.readFile(versionFilePath, 'utf-8');\n const timestamp = parseInt(content.trim(), 10);\n return isNaN(timestamp) ? 0 : timestamp;\n } catch (error) {\n // File doesn't exist or can't be read - treat as version 0\n return 0;\n }\n}\n\n","import { glob } from 'glob';\nimport ignore from 'ignore';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { ScanOptions } from './types.js';\nimport { LienConfig, FrameworkInstance } from '../config/schema.js';\n\n/**\n * Scan codebase using framework-aware configuration\n * @param rootDir - Project root directory\n * @param config - Lien configuration with frameworks\n * @returns Array of file paths relative to rootDir\n */\nexport async function scanCodebaseWithFrameworks(\n rootDir: string,\n config: LienConfig\n): Promise<string[]> {\n const allFiles: string[] = [];\n \n // Scan each framework\n for (const framework of config.frameworks) {\n if (!framework.enabled) {\n continue;\n }\n \n const frameworkFiles = await scanFramework(rootDir, framework);\n allFiles.push(...frameworkFiles);\n }\n \n return allFiles;\n}\n\n/**\n * Scan files for a specific framework instance\n */\nasync function scanFramework(\n rootDir: string,\n framework: FrameworkInstance\n): Promise<string[]> {\n const frameworkPath = path.join(rootDir, framework.path);\n \n // Load .gitignore from framework path\n const gitignorePath = path.join(frameworkPath, '.gitignore');\n let ig = ignore();\n \n try {\n const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore in framework path, try root\n const rootGitignorePath = path.join(rootDir, '.gitignore');\n try {\n const gitignoreContent = await fs.readFile(rootGitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore at all, that's fine\n }\n }\n \n // Add framework-specific exclusions\n ig.add([\n ...framework.config.exclude,\n '.lien/**',\n ]);\n \n // Find all files matching framework patterns\n const allFiles: string[] = [];\n \n for (const pattern of framework.config.include) {\n const files = await glob(pattern, {\n cwd: frameworkPath,\n absolute: false, // Get paths relative to framework path\n nodir: true,\n ignore: framework.config.exclude,\n });\n allFiles.push(...files);\n }\n \n // Remove duplicates\n const uniqueFiles = Array.from(new Set(allFiles));\n \n // Filter using ignore patterns and prefix with framework path\n return uniqueFiles\n .filter(file => !ig.ignores(file))\n .map(file => {\n // Return path relative to root: framework.path/file\n return framework.path === '.' \n ? file \n : path.join(framework.path, file);\n });\n}\n\n/**\n * Legacy scan function for backwards compatibility\n * @deprecated Use scanCodebaseWithFrameworks instead\n */\nexport async function scanCodebase(options: ScanOptions): Promise<string[]> {\n const { rootDir, includePatterns = [], excludePatterns = [] } = options;\n \n // Load .gitignore\n const gitignorePath = path.join(rootDir, '.gitignore');\n let ig = ignore();\n \n try {\n const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore, that's fine\n }\n \n // Add default exclusions\n ig.add([\n 'node_modules/**',\n '.git/**',\n 'dist/**',\n 'build/**',\n '*.min.js',\n '*.min.css',\n '.lien/**',\n ...excludePatterns,\n ]);\n \n // Determine patterns to search for\n const patterns = includePatterns.length > 0 \n ? includePatterns \n : ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,cpp,c,cs,h,md,mdx}'];\n \n // Find all code files\n const allFiles: string[] = [];\n \n for (const pattern of patterns) {\n const files = await glob(pattern, {\n cwd: rootDir,\n absolute: true,\n nodir: true,\n ignore: ['node_modules/**', '.git/**'],\n });\n allFiles.push(...files);\n }\n \n // Remove duplicates\n const uniqueFiles = Array.from(new Set(allFiles));\n \n // Filter using ignore patterns\n return uniqueFiles.filter(file => {\n const relativePath = path.relative(rootDir, file);\n return !ig.ignores(relativePath);\n });\n}\n\nexport function detectLanguage(filepath: string): string {\n const ext = path.extname(filepath).toLowerCase();\n \n const languageMap: Record<string, string> = {\n '.ts': 'typescript',\n '.tsx': 'typescript',\n '.js': 'javascript',\n '.jsx': 'javascript',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n '.vue': 'vue',\n '.py': 'python',\n '.go': 'go',\n '.rs': 'rust',\n '.java': 'java',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.c': 'c',\n '.h': 'c',\n '.hpp': 'cpp',\n '.php': 'php',\n '.rb': 'ruby',\n '.swift': 'swift',\n '.kt': 'kotlin',\n '.cs': 'csharp',\n '.scala': 'scala',\n '.liquid': 'liquid',\n '.md': 'markdown',\n '.mdx': 'markdown',\n '.markdown': 'markdown',\n };\n \n return languageMap[ext] || 'unknown';\n}\n\n","/**\n * Symbol extraction utilities for different programming languages.\n * Extracts function, class, and interface names from code chunks for better indexing.\n */\n\nexport interface ExtractedSymbols {\n functions: string[];\n classes: string[];\n interfaces: string[];\n}\n\n/**\n * Extract symbols (functions, classes, interfaces) from code content.\n * \n * @param content - The code content to extract symbols from\n * @param language - The programming language of the content\n * @returns Extracted symbols organized by type\n */\nexport function extractSymbols(\n content: string,\n language: string\n): ExtractedSymbols {\n const symbols: ExtractedSymbols = {\n functions: [],\n classes: [],\n interfaces: [],\n };\n \n const normalizedLang = language.toLowerCase();\n \n switch (normalizedLang) {\n case 'typescript':\n case 'tsx':\n symbols.functions = extractTSFunctions(content);\n symbols.classes = extractTSClasses(content);\n symbols.interfaces = extractTSInterfaces(content);\n break;\n \n case 'javascript':\n case 'jsx':\n symbols.functions = extractJSFunctions(content);\n symbols.classes = extractJSClasses(content);\n break;\n \n case 'python':\n case 'py':\n symbols.functions = extractPythonFunctions(content);\n symbols.classes = extractPythonClasses(content);\n break;\n \n case 'php':\n symbols.functions = extractPHPFunctions(content);\n symbols.classes = extractPHPClasses(content);\n symbols.interfaces = extractPHPInterfaces(content);\n break;\n \n case 'vue':\n // Extract from <script> blocks (handles both Options API and Composition API)\n symbols.functions = extractVueFunctions(content);\n symbols.classes = extractVueComponents(content);\n break;\n \n case 'go':\n symbols.functions = extractGoFunctions(content);\n symbols.interfaces = extractGoInterfaces(content);\n break;\n \n case 'java':\n symbols.functions = extractJavaFunctions(content);\n symbols.classes = extractJavaClasses(content);\n symbols.interfaces = extractJavaInterfaces(content);\n break;\n \n case 'csharp':\n case 'cs':\n symbols.functions = extractCSharpFunctions(content);\n symbols.classes = extractCSharpClasses(content);\n symbols.interfaces = extractCSharpInterfaces(content);\n break;\n \n case 'ruby':\n case 'rb':\n symbols.functions = extractRubyFunctions(content);\n symbols.classes = extractRubyClasses(content);\n break;\n \n case 'rust':\n case 'rs':\n symbols.functions = extractRustFunctions(content);\n break;\n }\n \n return symbols;\n}\n\n// TypeScript / JavaScript Functions\nfunction extractTSFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Regular functions: function name(...) or async function name(...)\n const functionMatches = content.matchAll(/(?:async\\s+)?function\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Arrow functions: const/let/var name = (...) =>\n const arrowMatches = content.matchAll(/(?:const|let|var)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\([^)]*\\)\\s*=>/g);\n for (const match of arrowMatches) {\n names.add(match[1]);\n }\n \n // Method definitions: name(...) { or async name(...) {\n const methodMatches = content.matchAll(/(?:async\\s+)?(\\w+)\\s*\\([^)]*\\)\\s*[:{]/g);\n for (const match of methodMatches) {\n // Exclude common keywords\n if (!['if', 'for', 'while', 'switch', 'catch'].includes(match[1])) {\n names.add(match[1]);\n }\n }\n \n // Export function\n const exportMatches = content.matchAll(/export\\s+(?:async\\s+)?function\\s+(\\w+)\\s*\\(/g);\n for (const match of exportMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJSFunctions(content: string): string[] {\n return extractTSFunctions(content); // Same patterns\n}\n\nfunction extractTSClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class declarations: class Name or export class Name\n const classMatches = content.matchAll(/(?:export\\s+)?(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJSClasses(content: string): string[] {\n return extractTSClasses(content); // Same patterns\n}\n\nfunction extractTSInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface declarations: interface Name or export interface Name\n const interfaceMatches = content.matchAll(/(?:export\\s+)?interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Type aliases: type Name = or export type Name =\n const typeMatches = content.matchAll(/(?:export\\s+)?type\\s+(\\w+)\\s*=/g);\n for (const match of typeMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Python Functions\nfunction extractPythonFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: def name(...):\n const functionMatches = content.matchAll(/def\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Async functions: async def name(...):\n const asyncMatches = content.matchAll(/async\\s+def\\s+(\\w+)\\s*\\(/g);\n for (const match of asyncMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPythonClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or class Name(Base):\n const classMatches = content.matchAll(/class\\s+(\\w+)(?:\\s*\\(|:)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// PHP Functions\nfunction extractPHPFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: function name(...) or public function name(...)\n const functionMatches = content.matchAll(/(?:public|private|protected)?\\s*function\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPHPClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or abstract class Name\n const classMatches = content.matchAll(/(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPHPInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: interface Name\n const interfaceMatches = content.matchAll(/interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Trait definitions: trait Name\n const traitMatches = content.matchAll(/trait\\s+(\\w+)/g);\n for (const match of traitMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Go Functions\nfunction extractGoFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: func Name(...) or func (r *Receiver) Name(...)\n const functionMatches = content.matchAll(/func\\s+(?:\\(\\w+\\s+\\*?\\w+\\)\\s+)?(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractGoInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: type Name interface {\n const interfaceMatches = content.matchAll(/type\\s+(\\w+)\\s+interface\\s*\\{/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Struct definitions: type Name struct {\n const structMatches = content.matchAll(/type\\s+(\\w+)\\s+struct\\s*\\{/g);\n for (const match of structMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Java Functions\nfunction extractJavaFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: public/private/protected return_type name(...)\n const methodMatches = content.matchAll(/(?:public|private|protected)\\s+(?:static\\s+)?(?:\\w+(?:<[^>]+>)?)\\s+(\\w+)\\s*\\(/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJavaClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: public class Name or abstract class Name\n const classMatches = content.matchAll(/(?:public\\s+)?(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJavaInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: public interface Name\n const interfaceMatches = content.matchAll(/(?:public\\s+)?interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// C# Functions\nfunction extractCSharpFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: public/private/protected return_type Name(...)\n const methodMatches = content.matchAll(/(?:public|private|protected|internal)\\s+(?:static\\s+)?(?:async\\s+)?(?:\\w+(?:<[^>]+>)?)\\s+(\\w+)\\s*\\(/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractCSharpClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: public class Name or abstract class Name\n const classMatches = content.matchAll(/(?:public|internal)?\\s*(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractCSharpInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: public interface Name\n const interfaceMatches = content.matchAll(/(?:public|internal)?\\s*interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Ruby Functions\nfunction extractRubyFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: def name or def self.name\n const methodMatches = content.matchAll(/def\\s+(?:self\\.)?(\\w+)/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractRubyClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or class Name < Base\n const classMatches = content.matchAll(/class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n // Module definitions: module Name\n const moduleMatches = content.matchAll(/module\\s+(\\w+)/g);\n for (const match of moduleMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Rust Functions\nfunction extractRustFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: fn name(...) or pub fn name(...)\n const functionMatches = content.matchAll(/(?:pub\\s+)?fn\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Struct definitions: struct Name {\n const structMatches = content.matchAll(/(?:pub\\s+)?struct\\s+(\\w+)/g);\n for (const match of structMatches) {\n names.add(match[1]);\n }\n \n // Trait definitions: trait Name {\n const traitMatches = content.matchAll(/(?:pub\\s+)?trait\\s+(\\w+)/g);\n for (const match of traitMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Vue Functions\nfunction extractVueFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Extract script content from Vue SFC\n const scriptMatch = content.match(/<script[^>]*>([\\s\\S]*?)<\\/script>/);\n if (!scriptMatch) return [];\n \n const scriptContent = scriptMatch[1];\n \n // Composition API: const/function name = ...\n const compositionMatches = scriptContent.matchAll(/(?:const|function)\\s+(\\w+)\\s*=/g);\n for (const match of compositionMatches) {\n names.add(match[1]);\n }\n \n // Options API methods\n const methodMatches = scriptContent.matchAll(/(\\w+)\\s*\\([^)]*\\)\\s*{/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Vue Components\nfunction extractVueComponents(content: string): string[] {\n const names = new Set<string>();\n \n // Extract component name from filename convention or export\n const scriptMatch = content.match(/<script[^>]*>([\\s\\S]*?)<\\/script>/);\n if (!scriptMatch) return [];\n \n const scriptContent = scriptMatch[1];\n \n // export default { name: 'ComponentName' }\n const nameMatch = scriptContent.match(/name:\\s*['\"](\\w+)['\"]/);\n if (nameMatch) {\n names.add(nameMatch[1]);\n }\n \n // defineComponent or <script setup> components\n const defineComponentMatch = scriptContent.match(/defineComponent\\s*\\(/);\n if (defineComponentMatch) {\n names.add('VueComponent');\n }\n \n return Array.from(names);\n}\n\n","import Parser from 'tree-sitter';\nimport TypeScript from 'tree-sitter-typescript';\nimport JavaScript from 'tree-sitter-javascript';\nimport PHPParser from 'tree-sitter-php';\nimport Python from 'tree-sitter-python';\nimport { extname } from 'path';\nimport type { ASTParseResult, SupportedLanguage } from './types.js';\n\n/**\n * Cache for parser instances to avoid recreating them\n */\nconst parserCache = new Map<SupportedLanguage, Parser>();\n\n/**\n * Tree-sitter language grammar type\n * Using any here due to type incompatibility between parser packages and tree-sitter core\n */\ntype TreeSitterLanguage = any;\n\n/**\n * Language configuration mapping\n */\nconst languageConfig: Record<SupportedLanguage, TreeSitterLanguage> = {\n typescript: TypeScript.typescript,\n javascript: JavaScript,\n php: PHPParser.php, // Note: tree-sitter-php exports both 'php' (mixed HTML/PHP) and 'php_only'\n python: Python,\n};\n\n/**\n * Get or create a cached parser instance for a language\n */\nfunction getParser(language: SupportedLanguage): Parser {\n if (!parserCache.has(language)) {\n const parser = new Parser();\n const grammar = languageConfig[language];\n \n if (!grammar) {\n throw new Error(`No grammar available for language: ${language}`);\n }\n \n parser.setLanguage(grammar);\n parserCache.set(language, parser);\n }\n \n return parserCache.get(language)!;\n}\n\n/**\n * Detect language from file extension\n * Uses path.extname() to handle edge cases like multiple dots in filenames\n */\nexport function detectLanguage(filePath: string): SupportedLanguage | null {\n // extname returns extension with leading dot (e.g., '.ts')\n // Remove the dot and convert to lowercase\n const ext = extname(filePath).slice(1).toLowerCase();\n \n switch (ext) {\n case 'ts':\n case 'tsx':\n return 'typescript';\n case 'js':\n case 'jsx':\n case 'mjs':\n case 'cjs':\n return 'javascript';\n case 'php':\n return 'php';\n case 'py':\n return 'python';\n default:\n return null;\n }\n}\n\n/**\n * Check if a file is supported for AST parsing\n */\nexport function isASTSupported(filePath: string): boolean {\n return detectLanguage(filePath) !== null;\n}\n\n/**\n * Parse source code into an AST using Tree-sitter\n * \n * **Known Limitation:** Tree-sitter may throw \"Invalid argument\" errors on very large files\n * (1000+ lines). This is a limitation of Tree-sitter's internal buffer handling. When this\n * occurs, callers should fall back to line-based chunking (handled automatically by chunker.ts).\n * \n * @param content - Source code to parse\n * @param language - Programming language\n * @returns Parse result with tree or error\n */\nexport function parseAST(content: string, language: SupportedLanguage): ASTParseResult {\n try {\n const parser = getParser(language);\n const tree = parser.parse(content);\n \n // Check for parse errors (hasError is a property, not a method)\n if (tree.rootNode.hasError) {\n return {\n tree,\n error: 'Parse completed with errors',\n };\n }\n \n return { tree };\n } catch (error) {\n return {\n tree: null,\n error: error instanceof Error ? error.message : 'Unknown parse error',\n };\n }\n}\n\n/**\n * Clear parser cache (useful for testing)\n */\nexport function clearParserCache(): void {\n parserCache.clear();\n}\n\n","import type Parser from 'tree-sitter';\n\n/**\n * Decision point node types for cyclomatic complexity calculation.\n * \n * These AST node types represent branch points in code flow.\n */\nconst DECISION_POINTS = [\n // Common across languages (TypeScript/JavaScript/Python/PHP)\n 'if_statement', // if conditions\n 'while_statement', // while loops\n 'for_statement', // for loops\n 'switch_case', // switch/case statements\n 'catch_clause', // try/catch error handling\n 'ternary_expression', // Ternary operator (a ? b : c)\n 'binary_expression', // For && and || logical operators\n \n // TypeScript/JavaScript specific\n 'do_statement', // do...while loops\n 'for_in_statement', // for...in loops\n 'for_of_statement', // for...of loops\n \n // PHP specific\n 'foreach_statement', // PHP foreach loops\n \n // Python specific\n 'elif_clause', // Python elif (adds decision point)\n // Note: 'else_clause' is NOT a decision point (it's the default path)\n 'except_clause', // Python except (try/except)\n 'conditional_expression', // Python ternary (x if cond else y)\n];\n\n/**\n * Calculate cyclomatic complexity of a function\n * \n * Complexity = 1 (base) + number of decision points\n * Decision points: if, while, do...while, for, for...in, for...of, foreach, case, catch, &&, ||, ?:\n * \n * @param node - AST node to analyze (typically a function/method)\n * @returns Cyclomatic complexity score (minimum 1)\n */\nexport function calculateComplexity(node: Parser.SyntaxNode): number {\n let complexity = 1; // Base complexity\n \n function traverse(n: Parser.SyntaxNode) {\n if (DECISION_POINTS.includes(n.type)) {\n // For binary expressions, only count && and ||\n if (n.type === 'binary_expression') {\n const operator = n.childForFieldName('operator');\n if (operator && (operator.text === '&&' || operator.text === '||')) {\n complexity++;\n }\n } else {\n complexity++;\n }\n }\n \n // Traverse children\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) traverse(child);\n }\n }\n \n traverse(node);\n return complexity;\n}\n","import type Parser from 'tree-sitter';\n\n// Node types that increase complexity AND increment nesting for children\nconst NESTING_TYPES = new Set([\n 'if_statement', 'for_statement', 'while_statement', 'switch_statement',\n 'catch_clause', 'except_clause', 'do_statement', 'for_in_statement',\n 'for_of_statement', 'foreach_statement', 'match_statement',\n]);\n\n// Types that add complexity but DON'T nest (hybrid increments)\nconst NON_NESTING_TYPES = new Set([\n 'else_clause', 'elif_clause', 'ternary_expression', 'conditional_expression',\n]);\n\n// Lambda types that add complexity when nested\nconst LAMBDA_TYPES = new Set(['arrow_function', 'function_expression', 'lambda']);\n\n/** Traversal context passed to handlers */\ninterface TraversalContext {\n traverse: (n: Parser.SyntaxNode, level: number, lastOp: string | null) => void;\n}\n\n/**\n * Check if node is a logical operator and return normalized form\n */\nfunction getLogicalOperator(node: Parser.SyntaxNode): string | null {\n if (node.type !== 'binary_expression' && node.type !== 'boolean_operator') {\n return null;\n }\n const operator = node.childForFieldName('operator');\n const opText = operator?.text;\n \n if (opText === '&&' || opText === 'and') return '&&';\n if (opText === '||' || opText === 'or') return '||';\n return null;\n}\n\n/**\n * Determine nesting level for a child node based on SonarSource spec.\n */\nfunction getChildNestingLevel(\n parent: Parser.SyntaxNode,\n child: Parser.SyntaxNode,\n currentLevel: number\n): number {\n const isCondition = parent.childForFieldName('condition') === child;\n const isElseClause = NON_NESTING_TYPES.has(child.type);\n return (!isCondition && !isElseClause) ? currentLevel + 1 : currentLevel;\n}\n\n/**\n * Get complexity increment for nested lambda (only adds if already nested)\n */\nfunction getNestedLambdaIncrement(nodeType: string, nestingLevel: number): number {\n return (LAMBDA_TYPES.has(nodeType) && nestingLevel > 0) ? 1 : 0;\n}\n\n/** Traverse logical operator children, passing the operator type */\nfunction traverseLogicalChildren(\n n: Parser.SyntaxNode,\n level: number,\n op: string,\n ctx: TraversalContext\n): void {\n const operator = n.childForFieldName('operator');\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child && child !== operator) ctx.traverse(child, level, op);\n }\n}\n\n/** Traverse nesting type children with proper nesting level adjustment */\nfunction traverseNestingChildren(\n n: Parser.SyntaxNode,\n level: number,\n ctx: TraversalContext\n): void {\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) ctx.traverse(child, getChildNestingLevel(n, child, level), null);\n }\n}\n\n/** Traverse all children at specified level */\nfunction traverseAllChildren(\n n: Parser.SyntaxNode,\n level: number,\n ctx: TraversalContext\n): void {\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) ctx.traverse(child, level, null);\n }\n}\n\n/**\n * Calculate cognitive complexity of a function\n * \n * Based on SonarSource's Cognitive Complexity specification:\n * - +1 for each break from linear flow (if, for, while, catch, etc.)\n * - +1 for each nesting level when inside a control structure\n * - +1 for each logical operator sequence break (a && b || c)\n * \n * @see https://www.sonarsource.com/docs/CognitiveComplexity.pdf\n * \n * @param node - AST node to analyze (typically a function/method)\n * @returns Cognitive complexity score (minimum 0)\n */\nexport function calculateCognitiveComplexity(node: Parser.SyntaxNode): number {\n let complexity = 0;\n const ctx: TraversalContext = { traverse };\n \n function traverse(n: Parser.SyntaxNode, nestingLevel: number, lastLogicalOp: string | null): void {\n const logicalOp = getLogicalOperator(n);\n \n if (logicalOp) {\n complexity += (lastLogicalOp !== logicalOp) ? 1 : 0;\n traverseLogicalChildren(n, nestingLevel, logicalOp, ctx);\n return;\n }\n \n if (NESTING_TYPES.has(n.type)) {\n complexity += 1 + nestingLevel;\n traverseNestingChildren(n, nestingLevel, ctx);\n return;\n }\n \n if (NON_NESTING_TYPES.has(n.type)) {\n complexity += 1;\n traverseAllChildren(n, nestingLevel + 1, ctx);\n return;\n }\n \n complexity += getNestedLambdaIncrement(n.type, nestingLevel);\n traverseAllChildren(n, nestingLevel, ctx);\n }\n \n traverse(node, 0, null);\n return complexity;\n}\n","import type Parser from 'tree-sitter';\n\n/** Raw Halstead counts from AST */\nexport interface HalsteadCounts {\n n1: number; // distinct operators\n n2: number; // distinct operands\n N1: number; // total operators\n N2: number; // total operands\n operators: Map<string, number>; // operator -> count\n operands: Map<string, number>; // operand -> count\n}\n\n/** Calculated Halstead metrics */\nexport interface HalsteadMetrics {\n vocabulary: number; // n = n1 + n2\n length: number; // N = N1 + N2\n volume: number; // V = N × log₂(n)\n difficulty: number; // D = (n1/2) × (N2/n2)\n effort: number; // E = D × V\n time: number; // T = E / 18 (seconds to understand)\n bugs: number; // B = V / 3000 (estimated delivered bugs)\n}\n\n/** \n * Language-specific operator symbols.\n * These are the actual text values we match against.\n */\nconst OPERATOR_SYMBOLS: Record<string, Set<string>> = {\n typescript: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**',\n // Comparison\n '==', '===', '!=', '!==', '<', '>', '<=', '>=',\n // Logical\n '&&', '||', '!', '??',\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '&&=', '||=', '??=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>', '>>>',\n '&=', '|=', '^=', '<<=', '>>=', '>>>=',\n // Other\n '?', ':', '.', '?.', '++', '--', '...', '=>',\n // Brackets/parens (counted as operators)\n '(', ')', '[', ']', '{', '}',\n ]),\n python: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**', '//',\n // Comparison\n '==', '!=', '<', '>', '<=', '>=',\n // Logical (handled via keywords below)\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '//=',\n '&=', '|=', '^=', '<<=', '>>=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>',\n // Other\n '.', ':', '->', '@',\n '(', ')', '[', ']', '{', '}',\n ]),\n php: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**',\n // Comparison\n '==', '===', '!=', '!==', '<>', '<', '>', '<=', '>=', '<=>',\n // Logical\n '&&', '||', '!', 'and', 'or', 'xor',\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '.=',\n '&=', '|=', '^=', '<<=', '>>=', '??=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>',\n // String\n '.',\n // Other\n '?', ':', '::', '->', '=>', '??', '@',\n '(', ')', '[', ']', '{', '}',\n ]),\n};\n\n/** \n * Language-specific operator keywords.\n * These are keywords that act as operators.\n */\nconst OPERATOR_KEYWORDS: Record<string, Set<string>> = {\n typescript: new Set([\n 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default',\n 'return', 'throw', 'try', 'catch', 'finally',\n 'new', 'delete', 'typeof', 'instanceof', 'in', 'of',\n 'await', 'yield', 'break', 'continue',\n 'const', 'let', 'var', 'function', 'class', 'extends', 'implements',\n 'import', 'export', 'from', 'as',\n ]),\n python: new Set([\n 'if', 'elif', 'else', 'for', 'while', 'match', 'case',\n 'return', 'raise', 'try', 'except', 'finally',\n 'and', 'or', 'not', 'is', 'in',\n 'await', 'yield', 'break', 'continue', 'pass',\n 'def', 'class', 'lambda', 'async',\n 'import', 'from', 'as', 'with',\n 'global', 'nonlocal', 'del', 'assert',\n ]),\n php: new Set([\n 'if', 'elseif', 'else', 'for', 'foreach', 'while', 'do', 'switch', 'case', 'default', 'match',\n 'return', 'throw', 'try', 'catch', 'finally',\n 'new', 'clone', 'instanceof',\n 'yield', 'break', 'continue',\n 'function', 'class', 'extends', 'implements', 'trait', 'interface',\n 'use', 'namespace', 'as',\n 'echo', 'print', 'include', 'require', 'include_once', 'require_once',\n 'global', 'static', 'const', 'public', 'private', 'protected', 'readonly',\n ]),\n};\n\n/** \n * AST node types that represent operators (language-agnostic).\n * These are the tree-sitter node types, not the text content.\n */\nconst OPERATOR_NODE_TYPES = new Set([\n // Expression operators\n 'binary_expression',\n 'unary_expression',\n 'update_expression',\n 'assignment_expression',\n 'augmented_assignment_expression',\n 'ternary_expression',\n 'conditional_expression',\n \n // Call/access operators\n 'call_expression',\n 'method_call',\n 'member_expression',\n 'subscript_expression',\n 'attribute',\n \n // Object/array literals ([] and {} are operators)\n 'array',\n 'object',\n 'dictionary',\n 'list',\n]);\n\n/**\n * AST node types that represent operands.\n */\nconst OPERAND_NODE_TYPES = new Set([\n // Identifiers\n 'identifier',\n 'property_identifier',\n 'shorthand_property_identifier',\n 'variable_name',\n 'name',\n \n // Literals\n 'number',\n 'integer',\n 'float',\n 'string',\n 'string_fragment',\n 'template_string',\n 'true',\n 'false',\n 'null',\n 'undefined',\n 'none',\n \n // Special\n 'this',\n 'self',\n 'super',\n]);\n\n/**\n * Get the operator set for a language (with fallback to typescript)\n */\nfunction getOperatorSymbols(language: string): Set<string> {\n return OPERATOR_SYMBOLS[language] || OPERATOR_SYMBOLS.typescript;\n}\n\n/**\n * Get the keyword set for a language (with fallback to typescript)\n */\nfunction getOperatorKeywords(language: string): Set<string> {\n return OPERATOR_KEYWORDS[language] || OPERATOR_KEYWORDS.typescript;\n}\n\n/**\n * Check if a node represents an operator\n */\nfunction isOperator(node: Parser.SyntaxNode, language: string): boolean {\n const nodeType = node.type;\n const nodeText = node.text;\n \n // Check if it's an operator node type\n if (OPERATOR_NODE_TYPES.has(nodeType)) {\n return true;\n }\n \n // Check if it's an operator symbol or keyword\n const symbols = getOperatorSymbols(language);\n const keywords = getOperatorKeywords(language);\n \n return symbols.has(nodeText) || keywords.has(nodeText);\n}\n\n/**\n * Check if a node represents an operand\n */\nfunction isOperand(node: Parser.SyntaxNode): boolean {\n return OPERAND_NODE_TYPES.has(node.type);\n}\n\n/**\n * Get the canonical key for an operator (for counting distinct operators)\n */\nfunction getOperatorKey(node: Parser.SyntaxNode): string {\n // For complex expressions, use the operator type\n if (OPERATOR_NODE_TYPES.has(node.type)) {\n // For binary/unary expressions, extract the actual operator\n const operator = node.childForFieldName('operator');\n if (operator) {\n return operator.text;\n }\n return node.type;\n }\n return node.text;\n}\n\n/**\n * Get the canonical key for an operand (for counting distinct operands)\n */\nfunction getOperandKey(node: Parser.SyntaxNode): string {\n return node.text;\n}\n\n/**\n * Sum all values in a map\n */\nfunction sumValues(map: Map<string, number>): number {\n let sum = 0;\n for (const count of map.values()) {\n sum += count;\n }\n return sum;\n}\n\n/**\n * Count operators and operands in an AST node\n * \n * @param node - AST node to analyze (typically a function/method)\n * @param language - Programming language for language-specific handling\n * @returns HalsteadCounts with raw operator/operand counts\n */\nexport function countHalstead(node: Parser.SyntaxNode, language: string): HalsteadCounts {\n const operators = new Map<string, number>();\n const operands = new Map<string, number>();\n \n function traverse(n: Parser.SyntaxNode): void {\n // Check if this is an operator\n if (isOperator(n, language)) {\n const key = getOperatorKey(n);\n operators.set(key, (operators.get(key) || 0) + 1);\n }\n \n // Check if this is an operand\n if (isOperand(n)) {\n const key = getOperandKey(n);\n operands.set(key, (operands.get(key) || 0) + 1);\n }\n \n // Recurse into children\n for (const child of n.children) {\n traverse(child);\n }\n }\n \n traverse(node);\n \n return {\n n1: operators.size,\n n2: operands.size,\n N1: sumValues(operators),\n N2: sumValues(operands),\n operators,\n operands,\n };\n}\n\n/**\n * Calculate derived Halstead metrics from raw counts\n * \n * Formulas based on Maurice Halstead's \"Elements of Software Science\" (1977):\n * - Vocabulary (n) = n1 + n2\n * - Length (N) = N1 + N2\n * - Volume (V) = N × log₂(n) - size of implementation\n * - Difficulty (D) = (n1/2) × (N2/n2) - error-proneness\n * - Effort (E) = D × V - mental effort required\n * - Time (T) = E / 18 - seconds to understand (Stroud number)\n * - Bugs (B) = V / 3000 - estimated delivered bugs\n * \n * @param counts - Raw Halstead counts from countHalstead()\n * @returns Calculated HalsteadMetrics\n */\nexport function calculateHalsteadMetrics(counts: HalsteadCounts): HalsteadMetrics {\n const { n1, n2, N1, N2 } = counts;\n \n const vocabulary = n1 + n2;\n const length = N1 + N2;\n \n // Avoid log(0) and division by zero\n const volume = vocabulary > 0 ? length * Math.log2(vocabulary) : 0;\n const difficulty = n2 > 0 ? (n1 / 2) * (N2 / n2) : 0;\n const effort = difficulty * volume;\n const time = effort / 18; // Stroud number (18 mental discriminations per second)\n const bugs = volume / 3000;\n \n return {\n vocabulary: Math.round(vocabulary),\n length: Math.round(length),\n volume: Math.round(volume * 100) / 100,\n difficulty: Math.round(difficulty * 100) / 100,\n effort: Math.round(effort),\n time: Math.round(time),\n bugs: Math.round(bugs * 1000) / 1000,\n };\n}\n\n/**\n * Calculate Halstead metrics for an AST node in one call\n * \n * Convenience function that combines countHalstead and calculateHalsteadMetrics.\n * \n * @param node - AST node to analyze\n * @param language - Programming language\n * @returns Calculated HalsteadMetrics\n */\nexport function calculateHalstead(node: Parser.SyntaxNode, language: string): HalsteadMetrics {\n const counts = countHalstead(node, language);\n return calculateHalsteadMetrics(counts);\n}\n","/**\n * Complexity metrics module\n * \n * This module provides various code complexity metrics:\n * - Cyclomatic complexity: Counts decision points (branches) in code\n * - Cognitive complexity: Measures mental effort to understand code (SonarSource spec)\n * - Halstead metrics: Measures complexity based on operators/operands\n */\n\nexport { calculateComplexity } from './cyclomatic.js';\nexport { calculateCognitiveComplexity } from './cognitive.js';\nexport { \n countHalstead, \n calculateHalsteadMetrics, \n calculateHalstead,\n} from './halstead.js';\nexport type { HalsteadCounts, HalsteadMetrics } from './halstead.js';\n","import type Parser from 'tree-sitter';\nimport type { SymbolInfo } from './types.js';\nimport { calculateComplexity } from './complexity/index.js';\n\n/**\n * Type for symbol extractor functions\n */\ntype SymbolExtractor = (\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n) => SymbolInfo | null;\n\n/**\n * Extract function declaration info (function_declaration, function)\n */\nfunction extractFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n returnType: extractReturnType(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract arrow function or function expression info\n */\nfunction extractArrowFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n // Try to find variable name for arrow functions\n const parent = node.parent;\n let name = 'anonymous';\n \n if (parent?.type === 'variable_declarator') {\n const nameNode = parent.childForFieldName('name');\n name = nameNode?.text || 'anonymous';\n }\n \n return {\n name,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract method definition info\n */\nfunction extractMethodInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'method',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n returnType: extractReturnType(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract class declaration info\n */\nfunction extractClassInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'class',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `class ${nameNode.text}`,\n };\n }\n \n/**\n * Extract interface declaration info (TypeScript)\n */\nfunction extractInterfaceInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'interface',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `interface ${nameNode.text}`,\n };\n }\n\n/**\n * Extract Python function info (def and async def)\n */\nfunction extractPythonFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n complexity: calculateComplexity(node),\n };\n }\n\n/**\n * Extract Python class info\n */\nfunction extractPythonClassInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'class',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `class ${nameNode.text}`,\n };\n }\n \n/**\n * Map of AST node types to their specialized extractors\n * \n * Note: There is intentional overlap in node type names across languages:\n * - 'function_definition': Used by both PHP and Python\n * - 'class_declaration': Used by TypeScript/JavaScript\n * - 'class_definition': Used by Python\n * \n * This is handled correctly because each file is parsed with its specific language parser.\n */\nconst symbolExtractors: Record<string, SymbolExtractor> = {\n // TypeScript/JavaScript\n 'function_declaration': extractFunctionInfo,\n 'function': extractFunctionInfo,\n 'arrow_function': extractArrowFunctionInfo,\n 'function_expression': extractArrowFunctionInfo,\n 'method_definition': extractMethodInfo,\n 'class_declaration': extractClassInfo,\n 'interface_declaration': extractInterfaceInfo,\n \n // PHP\n 'function_definition': extractFunctionInfo, // PHP functions (Python handled via language check in extractSymbolInfo)\n 'method_declaration': extractMethodInfo, // PHP methods\n \n // Python\n 'async_function_definition': extractPythonFunctionInfo, // Python async functions\n 'class_definition': extractPythonClassInfo, // Python classes\n // Note: Python regular functions use 'function_definition' (same as PHP)\n // They are dispatched to extractPythonFunctionInfo via language check in extractSymbolInfo()\n};\n\n/**\n * Extract symbol information from an AST node using specialized extractors\n * \n * @param node - AST node to extract info from\n * @param content - Source code content\n * @param parentClass - Parent class name if this is a method\n * @param language - Programming language (for disambiguating shared node types)\n * @returns Symbol information or null\n */\nexport function extractSymbolInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string,\n language?: string\n): SymbolInfo | null {\n // Handle ambiguous node types that are shared between languages\n // PHP and Python both use 'function_definition', but need different extractors\n if (node.type === 'function_definition' && language === 'python') {\n return extractPythonFunctionInfo(node, content, parentClass);\n }\n \n const extractor = symbolExtractors[node.type];\n return extractor ? extractor(node, content, parentClass) : null;\n}\n\n/**\n * Extract function/method signature\n */\nfunction extractSignature(node: Parser.SyntaxNode, content: string): string {\n // Get the first line of the function (up to opening brace or arrow)\n const startLine = node.startPosition.row;\n const lines = content.split('\\n');\n let signature = lines[startLine] || '';\n \n // If signature spans multiple lines, try to get up to the opening brace\n let currentLine = startLine;\n while (currentLine < node.endPosition.row && !signature.includes('{') && !signature.includes('=>')) {\n currentLine++;\n signature += ' ' + (lines[currentLine] || '');\n }\n \n // Clean up signature\n signature = signature.split('{')[0].split('=>')[0].trim();\n \n // Limit length\n if (signature.length > 200) {\n signature = signature.substring(0, 197) + '...';\n }\n \n return signature;\n}\n\n/**\n * Extract parameter list from function node\n * \n * Note: The `_content` parameter is unused in this function, but is kept for API consistency\n * with other extract functions (e.g., extractSignature).\n */\nfunction extractParameters(node: Parser.SyntaxNode, _content: string): string[] {\n const parameters: string[] = [];\n \n // Find parameters node\n const paramsNode = node.childForFieldName('parameters');\n if (!paramsNode) return parameters;\n \n // Traverse parameter nodes\n for (let i = 0; i < paramsNode.namedChildCount; i++) {\n const param = paramsNode.namedChild(i);\n if (param) {\n parameters.push(param.text);\n }\n }\n \n return parameters;\n}\n\n/**\n * Extract return type from function node (TypeScript)\n * \n * Note: The `_content` parameter is unused in this function, but is kept for API consistency\n * with other extract functions (e.g., extractSignature).\n */\nfunction extractReturnType(node: Parser.SyntaxNode, _content: string): string | undefined {\n const returnTypeNode = node.childForFieldName('return_type');\n if (!returnTypeNode) return undefined;\n \n return returnTypeNode.text;\n}\n\n/**\n * Extract import statements from a file\n */\nexport function extractImports(rootNode: Parser.SyntaxNode): string[] {\n const imports: string[] = [];\n \n function traverse(node: Parser.SyntaxNode) {\n // Handle import statements (shared node type between languages)\n if (node.type === 'import_statement') {\n // TypeScript/JavaScript: Extract just the module path from 'source' field\n const sourceNode = node.childForFieldName('source');\n if (sourceNode) {\n // TS/JS import with source field\n const importPath = sourceNode.text.replace(/['\"]/g, '');\n imports.push(importPath);\n } else {\n // Python import without source field (e.g., \"import os\")\n const importText = node.text.split('\\n')[0];\n imports.push(importText);\n }\n }\n // Python-specific: from...import statements\n else if (node.type === 'import_from_statement') {\n // Python: Get the entire import line (first line only)\n const importText = node.text.split('\\n')[0];\n imports.push(importText);\n }\n \n // Only traverse top-level nodes for imports\n if (node === rootNode) {\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) traverse(child);\n }\n }\n }\n \n traverse(rootNode);\n return imports;\n}\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * TypeScript/JavaScript AST traverser\n * \n * Handles TypeScript and JavaScript AST node types and traversal patterns.\n * Both languages share the same AST structure (via tree-sitter-typescript).\n */\nexport class TypeScriptTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_declaration',\n 'function',\n 'interface_declaration',\n 'method_definition',\n 'lexical_declaration', // For const/let with arrow functions\n 'variable_declaration', // For var with functions\n ];\n \n containerTypes = [\n 'class_declaration', // We extract methods, not the class itself\n ];\n \n declarationTypes = [\n 'lexical_declaration', // const/let\n 'variable_declaration', // var\n ];\n \n functionTypes = [\n 'arrow_function',\n 'function_expression',\n 'function',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(node: Parser.SyntaxNode): boolean {\n return this.declarationTypes.includes(node.type);\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_declaration') {\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'program' || \n node.type === 'export_statement' ||\n node.type === 'class_body';\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_declaration') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n /**\n * Check if a declaration node contains a function (arrow, function expression, etc.)\n */\n findFunctionInDeclaration(node: Parser.SyntaxNode): DeclarationFunctionInfo {\n const search = (n: Parser.SyntaxNode, depth: number): Parser.SyntaxNode | null => {\n if (depth > 3) return null; // Don't search too deep\n \n if (this.functionTypes.includes(n.type)) {\n return n;\n }\n \n for (let i = 0; i < n.childCount; i++) {\n const child = n.child(i);\n if (child) {\n const result = search(child, depth + 1);\n if (result) return result;\n }\n }\n \n return null;\n };\n \n const functionNode = search(node, 0);\n return {\n hasFunction: functionNode !== null,\n functionNode,\n };\n }\n}\n\n/**\n * JavaScript uses the same traverser as TypeScript\n */\nexport class JavaScriptTraverser extends TypeScriptTraverser {}\n\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * PHP AST traverser\n * \n * Handles PHP AST node types and traversal patterns.\n * PHP uses tree-sitter-php grammar.\n */\nexport class PHPTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_definition', // function foo() {}\n 'method_declaration', // public function bar() {}\n ];\n \n containerTypes = [\n 'class_declaration', // We extract methods, not the class itself\n 'trait_declaration', // PHP traits\n 'interface_declaration', // PHP interfaces (for interface methods)\n ];\n \n declarationTypes = [\n // PHP doesn't have arrow functions or const/let like JS\n // Functions are always defined with 'function' keyword\n ];\n \n functionTypes = [\n 'function_definition',\n 'method_declaration',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean {\n // PHP doesn't have variable declarations with functions like JS/TS\n // Functions are always defined with 'function' keyword\n return false;\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_declaration' || \n node.type === 'trait_declaration' ||\n node.type === 'interface_declaration') {\n // In PHP, the body is called 'declaration_list'\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'program' || // Top-level PHP file\n node.type === 'php' || // PHP block\n node.type === 'declaration_list'; // Body of class/trait/interface\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_declaration' || \n current.type === 'trait_declaration') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo {\n // PHP doesn't have this pattern\n return {\n hasFunction: false,\n functionNode: null,\n };\n }\n}\n\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * Python AST traverser\n * \n * Handles Python AST node types and traversal patterns.\n * Python has a simpler structure than TypeScript/JavaScript:\n * - Functions are defined with 'def' or 'async def'\n * - No variable declarations with functions (unlike JS const x = () => {})\n * - Classes contain methods (which are just functions)\n */\nexport class PythonTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_definition',\n 'async_function_definition',\n ];\n \n containerTypes = [\n 'class_definition', // We extract methods, not the class itself\n ];\n \n declarationTypes = [\n // Python doesn't have const/let/var declarations like JS/TS\n // Functions are always defined with 'def' or 'async def'\n ];\n \n functionTypes = [\n 'function_definition',\n 'async_function_definition',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean {\n // Python doesn't have variable declarations with functions like JS/TS\n // Functions are always defined with 'def' or 'async def'\n return false;\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_definition') {\n // In Python, the class body is called 'block'\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'module' || // Top-level Python file\n node.type === 'block'; // Body of class/function\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_definition') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n /**\n * Python doesn't have this pattern (const x = () => {})\n * Functions are always defined with 'def' or 'async def'\n */\n findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo {\n return {\n hasFunction: false,\n functionNode: null,\n };\n }\n}\n\n","import type { SupportedLanguage } from '../types.js';\nimport type { LanguageTraverser } from './types.js';\nimport { TypeScriptTraverser, JavaScriptTraverser } from './typescript.js';\nimport { PHPTraverser } from './php.js';\nimport { PythonTraverser } from './python.js';\n\nexport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * Registry of language traversers\n * \n * Maps each supported language to its traverser implementation.\n * When adding a new language:\n * 1. Create a new traverser class implementing LanguageTraverser\n * 2. Add it to this registry\n * 3. Update SupportedLanguage type in ../types.ts\n */\nconst traverserRegistry: Record<SupportedLanguage, LanguageTraverser> = {\n typescript: new TypeScriptTraverser(),\n javascript: new JavaScriptTraverser(),\n php: new PHPTraverser(),\n python: new PythonTraverser(),\n};\n\n/**\n * Get the traverser for a specific language\n * \n * @param language - Programming language\n * @returns Language-specific traverser\n * @throws Error if language is not supported\n */\nexport function getTraverser(language: SupportedLanguage): LanguageTraverser {\n const traverser = traverserRegistry[language];\n \n if (!traverser) {\n throw new Error(`No traverser available for language: ${language}`);\n }\n \n return traverser;\n}\n\n/**\n * Check if a language has a traverser implementation\n * \n * @param language - Programming language\n * @returns True if traverser exists\n */\nexport function hasTraverser(language: SupportedLanguage): boolean {\n return language in traverserRegistry;\n}\n\n","import type Parser from 'tree-sitter';\nimport type { ASTChunk } from './types.js';\nimport { parseAST, detectLanguage, isASTSupported } from './parser.js';\nimport { extractSymbolInfo, extractImports } from './symbols.js';\nimport { calculateCognitiveComplexity, calculateHalstead } from './complexity/index.js';\nimport { getTraverser } from './traversers/index.js';\n\nexport interface ASTChunkOptions {\n maxChunkSize?: number; // Reserved for future use (smart splitting of large functions)\n minChunkSize?: number;\n}\n\n/**\n * Chunk a file using AST-based semantic boundaries\n * \n * Uses Tree-sitter to parse code into an AST and extract semantic chunks\n * (functions, classes, methods) that respect code structure.\n * \n * **Known Limitations:**\n * - Tree-sitter may fail with \"Invalid argument\" error on very large files (1000+ lines)\n * - When this occurs, Lien automatically falls back to line-based chunking\n * - Configure fallback behavior via `chunking.astFallback` ('line-based' or 'error')\n * \n * @param filepath - Path to the file\n * @param content - File content\n * @param options - Chunking options\n * @returns Array of AST-aware chunks\n * @throws Error if AST parsing fails and astFallback is 'error'\n */\nexport function chunkByAST(\n filepath: string,\n content: string,\n options: ASTChunkOptions = {}\n): ASTChunk[] {\n const { minChunkSize = 5 } = options;\n \n // Check if AST is supported for this file\n const language = detectLanguage(filepath);\n if (!language) {\n throw new Error(`Unsupported language for file: ${filepath}`);\n }\n \n // Parse the file\n const parseResult = parseAST(content, language);\n \n // If parsing failed, throw error (caller should fallback to line-based)\n if (!parseResult.tree) {\n throw new Error(`Failed to parse ${filepath}: ${parseResult.error}`);\n }\n \n const chunks: ASTChunk[] = [];\n const lines = content.split('\\n');\n const rootNode = parseResult.tree.rootNode;\n \n // Get language-specific traverser\n const traverser = getTraverser(language);\n \n // Extract file-level imports once\n const fileImports = extractImports(rootNode);\n \n // Find all top-level function and class declarations\n const topLevelNodes = findTopLevelNodes(rootNode, traverser);\n \n for (const node of topLevelNodes) {\n // For variable declarations, try to find the function inside\n let actualNode = node;\n if (traverser.isDeclarationWithFunction(node)) {\n const declInfo = traverser.findFunctionInDeclaration(node);\n if (declInfo.functionNode) {\n actualNode = declInfo.functionNode;\n }\n }\n \n // For methods, find the parent container name (e.g., class name)\n const parentClassName = traverser.findParentContainerName(actualNode);\n \n const symbolInfo = extractSymbolInfo(actualNode, content, parentClassName, language);\n \n // Extract the code for this node (use original node for full declaration)\n const nodeContent = getNodeContent(node, lines);\n \n // Create a chunk for this semantic unit\n // Note: Large functions are kept as single chunks (may exceed maxChunkSize)\n // This preserves semantic boundaries - better than splitting mid-function\n chunks.push(createChunk(filepath, node, nodeContent, symbolInfo, fileImports, language));\n }\n \n // Handle remaining code (imports, exports, top-level statements)\n const coveredRanges = topLevelNodes.map(n => ({\n start: n.startPosition.row,\n end: n.endPosition.row,\n }));\n \n const uncoveredChunks = extractUncoveredCode(\n lines,\n coveredRanges,\n filepath,\n minChunkSize,\n fileImports,\n language\n );\n \n chunks.push(...uncoveredChunks);\n \n // Sort chunks by line number\n chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n \n return chunks;\n}\n\n/** Check if node is a function-containing declaration at top level */\nfunction isFunctionDeclaration(\n node: Parser.SyntaxNode,\n depth: number,\n traverser: ReturnType<typeof getTraverser>\n): boolean {\n if (depth !== 0 || !traverser.isDeclarationWithFunction(node)) return false;\n return traverser.findFunctionInDeclaration(node).hasFunction;\n}\n\n/** Check if node is a target type at valid depth */\nfunction isTargetNode(\n node: Parser.SyntaxNode,\n depth: number,\n traverser: ReturnType<typeof getTraverser>\n): boolean {\n return depth <= 1 && traverser.targetNodeTypes.includes(node.type);\n}\n\n/**\n * Find all top-level nodes that should become chunks\n * \n * Uses a language-specific traverser to handle different AST structures.\n * This function is now language-agnostic - all language-specific logic\n * is delegated to the traverser.\n * \n * @param rootNode - Root AST node\n * @param traverser - Language-specific traverser\n * @returns Array of nodes to extract as chunks\n */\nfunction findTopLevelNodes(\n rootNode: Parser.SyntaxNode,\n traverser: ReturnType<typeof getTraverser>\n): Parser.SyntaxNode[] {\n const nodes: Parser.SyntaxNode[] = [];\n \n function traverse(node: Parser.SyntaxNode, depth: number): void {\n // Capture function declarations and target nodes\n if (isFunctionDeclaration(node, depth, traverser) || isTargetNode(node, depth, traverser)) {\n nodes.push(node);\n return;\n }\n \n // Handle containers - traverse body at increased depth\n if (traverser.shouldExtractChildren(node)) {\n const body = traverser.getContainerBody(node);\n if (body) traverse(body, depth + 1);\n return;\n }\n \n // Traverse children of traversable nodes\n if (!traverser.shouldTraverseChildren(node)) return;\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) traverse(child, depth);\n }\n }\n \n traverse(rootNode, 0);\n return nodes;\n}\n\n/**\n * Extract content for a specific AST node\n */\nfunction getNodeContent(node: Parser.SyntaxNode, lines: string[]): string {\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n \n return lines.slice(startLine, endLine + 1).join('\\n');\n}\n\n/** Maps symbol types to legacy symbol array keys */\nconst SYMBOL_TYPE_TO_ARRAY: Record<string, 'functions' | 'classes' | 'interfaces'> = {\n function: 'functions',\n method: 'functions',\n class: 'classes',\n interface: 'interfaces',\n};\n\n/** Symbol types that have meaningful complexity metrics */\nconst COMPLEXITY_SYMBOL_TYPES = new Set(['function', 'method']);\n\n/**\n * Build legacy symbols object for backward compatibility\n */\nfunction buildLegacySymbols(symbolInfo: ReturnType<typeof extractSymbolInfo>): {\n functions: string[];\n classes: string[];\n interfaces: string[];\n} {\n const symbols = { functions: [] as string[], classes: [] as string[], interfaces: [] as string[] };\n \n if (symbolInfo?.name && symbolInfo.type) {\n const arrayKey = SYMBOL_TYPE_TO_ARRAY[symbolInfo.type];\n if (arrayKey) symbols[arrayKey].push(symbolInfo.name);\n }\n \n return symbols;\n}\n\n/**\n * Determine chunk type from symbol info\n */\nfunction getChunkType(symbolInfo: ReturnType<typeof extractSymbolInfo>): 'block' | 'class' | 'function' {\n if (!symbolInfo) return 'block';\n return symbolInfo.type === 'class' ? 'class' : 'function';\n}\n\n/**\n * Create a chunk from an AST node\n */\nfunction createChunk(\n filepath: string,\n node: Parser.SyntaxNode,\n content: string,\n symbolInfo: ReturnType<typeof extractSymbolInfo>,\n imports: string[],\n language: string\n): ASTChunk {\n const symbols = buildLegacySymbols(symbolInfo);\n const shouldCalcComplexity = symbolInfo?.type && COMPLEXITY_SYMBOL_TYPES.has(symbolInfo.type);\n \n // Calculate complexity metrics only for functions and methods\n const cognitiveComplexity = shouldCalcComplexity\n ? calculateCognitiveComplexity(node)\n : undefined;\n \n // Calculate Halstead metrics only for functions and methods\n const halstead = shouldCalcComplexity\n ? calculateHalstead(node, language)\n : undefined;\n \n return {\n content,\n metadata: {\n file: filepath,\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n type: getChunkType(symbolInfo),\n language,\n symbols,\n symbolName: symbolInfo?.name,\n symbolType: symbolInfo?.type,\n parentClass: symbolInfo?.parentClass,\n complexity: symbolInfo?.complexity,\n cognitiveComplexity,\n parameters: symbolInfo?.parameters,\n signature: symbolInfo?.signature,\n imports,\n // Halstead metrics\n halsteadVolume: halstead?.volume,\n halsteadDifficulty: halstead?.difficulty,\n halsteadEffort: halstead?.effort,\n halsteadBugs: halstead?.bugs,\n },\n };\n}\n\n/**\n * Represents a range of lines in a file\n */\ninterface LineRange {\n start: number;\n end: number;\n}\n\n/**\n * Find gaps between covered ranges (uncovered code)\n */\nfunction findUncoveredRanges(\n coveredRanges: LineRange[],\n totalLines: number\n): LineRange[] {\n const uncoveredRanges: LineRange[] = [];\n let currentStart = 0;\n \n // Sort covered ranges\n const sortedRanges = [...coveredRanges].sort((a, b) => a.start - b.start);\n \n for (const range of sortedRanges) {\n if (currentStart < range.start) {\n // There's a gap before this range\n uncoveredRanges.push({\n start: currentStart,\n end: range.start - 1,\n });\n }\n currentStart = range.end + 1;\n }\n \n // Handle remaining code after last covered range\n if (currentStart < totalLines) {\n uncoveredRanges.push({\n start: currentStart,\n end: totalLines - 1,\n });\n }\n \n return uncoveredRanges;\n}\n\n/**\n * Create a chunk from a line range\n */\nfunction createChunkFromRange(\n range: LineRange,\n lines: string[],\n filepath: string,\n language: string,\n imports: string[]\n): ASTChunk {\n const uncoveredLines = lines.slice(range.start, range.end + 1);\n const content = uncoveredLines.join('\\n').trim();\n \n return {\n content,\n metadata: {\n file: filepath,\n startLine: range.start + 1,\n endLine: range.end + 1,\n type: 'block',\n language,\n // Empty symbols for uncovered code (imports, exports, etc.)\n symbols: { functions: [], classes: [], interfaces: [] },\n imports,\n },\n };\n}\n\n/**\n * Validate that a chunk meets the minimum size requirements\n */\nfunction isValidChunk(chunk: ASTChunk, minChunkSize: number): boolean {\n const lineCount = chunk.metadata.endLine - chunk.metadata.startLine + 1;\n return chunk.content.length > 0 && lineCount >= minChunkSize;\n}\n\n/**\n * Extract code that wasn't covered by function/class chunks\n * (imports, exports, top-level statements)\n */\nfunction extractUncoveredCode(\n lines: string[],\n coveredRanges: Array<{ start: number; end: number }>,\n filepath: string,\n minChunkSize: number,\n imports: string[],\n language: string\n): ASTChunk[] {\n const uncoveredRanges = findUncoveredRanges(coveredRanges, lines.length);\n \n return uncoveredRanges\n .map(range => createChunkFromRange(range, lines, filepath, language, imports))\n .filter(chunk => isValidChunk(chunk, minChunkSize));\n}\n\n/**\n * Check if AST chunking should be used for a file\n */\nexport function shouldUseAST(filepath: string): boolean {\n return isASTSupported(filepath);\n}\n\n","import type { CodeChunk } from './types.js';\n\n/**\n * Liquid-specific chunking for Shopify themes\n * \n * Uses regex to identify special Liquid blocks (schema, style, javascript)\n * and keeps them as single semantic units\n */\n\ninterface LiquidBlock {\n type: 'schema' | 'style' | 'javascript' | 'template';\n startLine: number;\n endLine: number;\n content: string;\n}\n\n/**\n * Extract schema name from JSON content\n * \n * Extracts the \"name\" field from Shopify schema JSON.\n * Uses JSON.parse to properly handle escaped quotes and other JSON edge cases.\n * \n * Example:\n * {% schema %}\n * {\n * \"name\": \"My \\\"Special\\\" Section\",\n * \"settings\": []\n * }\n * {% endschema %}\n * \n * Returns: 'My \"Special\" Section' (with literal quotes, unescaped)\n */\nfunction extractSchemaName(schemaContent: string): string | undefined {\n try {\n // Remove Liquid tags to isolate JSON content\n // Replace {% schema %} and {% endschema %} (with optional whitespace control)\n let jsonContent = schemaContent\n .replace(/\\{%-?\\s*schema\\s*-?%\\}/g, '')\n .replace(/\\{%-?\\s*endschema\\s*-?%\\}/g, '')\n .trim();\n \n // Parse the JSON\n const schema = JSON.parse(jsonContent);\n // Ensure name is a string before returning\n return typeof schema.name === 'string' ? schema.name : undefined;\n } catch (error) {\n // Invalid JSON - return undefined\n // This is acceptable: schema blocks with invalid JSON won't have names extracted\n }\n return undefined;\n}\n\n/**\n * Remove Liquid comment blocks from content to avoid extracting tags from comments\n * \n * Example:\n * {% comment %}Don't use {% render 'old-snippet' %}{% endcomment %}\n * → (removed)\n */\nfunction removeComments(content: string): string {\n // Remove {% comment %}...{% endcomment %} blocks (with optional whitespace control)\n return content.replace(/\\{%-?\\s*comment\\s*-?%\\}[\\s\\S]*?\\{%-?\\s*endcomment\\s*-?%\\}/g, '');\n}\n\n/**\n * Extract dependencies from {% render %}, {% include %}, and {% section %} tags\n * \n * Examples:\n * - {% render 'product-card' %} → 'product-card'\n * - {% render \"cart-item\", product: product %} → 'cart-item'\n * - {% include 'snippets/header' %} → 'snippets/header'\n * - {% section 'announcement-bar' %} → 'announcement-bar'\n * \n * Limitations:\n * - Does not handle escaped quotes in snippet names (e.g., {% render 'name\\'s' %})\n * - This is acceptable because Shopify snippet names map to filenames, and\n * filesystem restrictions prevent quotes in filenames (snippets/name's.liquid is invalid)\n * - In practice, Shopify snippet names use only alphanumeric, dash, and underscore\n * \n * Note: Expects content with comments already removed for performance\n * \n * @param contentWithoutComments - Content with Liquid comments already removed\n */\nfunction extractRenderTags(contentWithoutComments: string): string[] {\n const dependencies = new Set<string>();\n \n // Match {% render 'snippet-name' %} or {% render \"snippet-name\" %}\n // Note: Does not handle escaped quotes - see function docs for rationale\n const renderPattern = /\\{%-?\\s*render\\s+['\"]([^'\"]+)['\"]/g;\n let match;\n \n while ((match = renderPattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n // Match {% include 'snippet-name' %} or {% include \"snippet-name\" %}\n const includePattern = /\\{%-?\\s*include\\s+['\"]([^'\"]+)['\"]/g;\n \n while ((match = includePattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n // Match {% section 'section-name' %} or {% section \"section-name\" %}\n const sectionPattern = /\\{%-?\\s*section\\s+['\"]([^'\"]+)['\"]/g;\n \n while ((match = sectionPattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n return Array.from(dependencies);\n}\n\n/**\n * Find all special Liquid blocks in the template\n * \n * Limitation: Does not support nested blocks of the same type.\n * - Matches first start tag with first end tag\n * - This is acceptable because Shopify Liquid does not allow nested blocks\n * - Example invalid: {% schema %}...{% schema %}...{% endschema %} (Shopify rejects this)\n * - If malformed input contains nested blocks, only outermost block is extracted\n */\nfunction findLiquidBlocks(content: string): LiquidBlock[] {\n const lines = content.split('\\n');\n const blocks: LiquidBlock[] = [];\n \n // Regex patterns for Liquid blocks\n // Note: Matches first start → first end (no nesting support, which is correct for Shopify)\n const blockPatterns = [\n { type: 'schema' as const, start: /\\{%-?\\s*schema\\s*-?%\\}/, end: /\\{%-?\\s*endschema\\s*-?%\\}/ },\n { type: 'style' as const, start: /\\{%-?\\s*style\\s*-?%\\}/, end: /\\{%-?\\s*endstyle\\s*-?%\\}/ },\n { type: 'javascript' as const, start: /\\{%-?\\s*javascript\\s*-?%\\}/, end: /\\{%-?\\s*endjavascript\\s*-?%\\}/ },\n ];\n \n for (const pattern of blockPatterns) {\n let searchStart = 0;\n \n while (searchStart < lines.length) {\n // Find start tag\n const startIdx = lines.findIndex((line, idx) => \n idx >= searchStart && pattern.start.test(line)\n );\n \n if (startIdx === -1) break;\n \n // Find end tag (allow same line for single-line blocks)\n const endIdx = lines.findIndex((line, idx) => \n idx >= startIdx && pattern.end.test(line)\n );\n \n if (endIdx === -1) {\n // No end tag found, treat rest as template\n break;\n }\n \n // Extract block content\n const blockContent = lines.slice(startIdx, endIdx + 1).join('\\n');\n \n blocks.push({\n type: pattern.type,\n startLine: startIdx,\n endLine: endIdx,\n content: blockContent,\n });\n \n searchStart = endIdx + 1;\n }\n }\n \n return blocks.sort((a, b) => a.startLine - b.startLine);\n}\n\n/**\n * Chunk a Liquid template file\n * \n * Special handling for:\n * - {% schema %} blocks (kept together, extract section name)\n * - {% style %} blocks (kept together) \n * - {% javascript %} blocks (kept together)\n * - {% render %}, {% include %}, and {% section %} tags (tracked as imports)\n * - Regular template content (chunked by lines)\n */\nexport function chunkLiquidFile(\n filepath: string,\n content: string,\n chunkSize: number = 75,\n chunkOverlap: number = 10\n): CodeChunk[] {\n const lines = content.split('\\n');\n const blocks = findLiquidBlocks(content);\n const chunks: CodeChunk[] = [];\n \n // Remove comments once for performance (avoids repeated regex operations)\n const contentWithoutComments = removeComments(content);\n const linesWithoutComments = contentWithoutComments.split('\\n');\n \n // Track which lines are covered by special blocks\n const coveredLines = new Set<number>();\n \n // Create chunks for special blocks\n for (const block of blocks) {\n // Mark lines as covered\n for (let i = block.startLine; i <= block.endLine; i++) {\n coveredLines.add(i);\n }\n \n // Extract metadata\n let symbolName: string | undefined;\n if (block.type === 'schema') {\n symbolName = extractSchemaName(block.content);\n }\n \n // Extract render/include tags from cleaned content (comments already removed)\n const blockContentWithoutComments = linesWithoutComments\n .slice(block.startLine, block.endLine + 1)\n .join('\\n');\n const imports = extractRenderTags(blockContentWithoutComments);\n \n const blockLineCount = block.endLine - block.startLine + 1;\n const maxBlockSize = chunkSize * 3; // Allow blocks up to 3x chunk size before splitting\n \n // If block is reasonably sized, keep it as one chunk\n if (blockLineCount <= maxBlockSize) {\n chunks.push({\n content: block.content,\n metadata: {\n file: filepath,\n startLine: block.startLine + 1, // 1-indexed\n endLine: block.endLine + 1,\n language: 'liquid',\n type: 'block',\n symbolName,\n symbolType: block.type,\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n } else {\n // Block is too large - split it into multiple chunks with overlap\n const blockLines = block.content.split('\\n');\n \n for (let offset = 0; offset < blockLines.length; offset += chunkSize - chunkOverlap) {\n const endOffset = Math.min(offset + chunkSize, blockLines.length);\n const chunkContent = blockLines.slice(offset, endOffset).join('\\n');\n \n if (chunkContent.trim().length > 0) {\n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: block.startLine + offset + 1, // 1-indexed\n endLine: block.startLine + endOffset, // 1-indexed (endOffset already accounts for exclusivity)\n language: 'liquid',\n type: 'block',\n symbolName, // Preserve symbol name for all split chunks\n symbolType: block.type,\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n if (endOffset >= blockLines.length) break;\n }\n }\n }\n \n // Chunk uncovered template content\n let currentChunk: string[] = [];\n let chunkStartLine = 0;\n \n for (let i = 0; i < lines.length; i++) {\n // Skip lines covered by special blocks\n if (coveredLines.has(i)) {\n // Flush current chunk if any\n if (currentChunk.length > 0) {\n const chunkContent = currentChunk.join('\\n');\n \n // Only push non-empty chunks\n if (chunkContent.trim().length > 0) {\n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, i).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: i,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n currentChunk = [];\n }\n continue;\n }\n \n // Start new chunk if needed\n if (currentChunk.length === 0) {\n chunkStartLine = i;\n }\n \n currentChunk.push(lines[i]);\n \n // Flush if chunk is full\n if (currentChunk.length >= chunkSize) {\n const chunkContent = currentChunk.join('\\n');\n \n // Only push non-empty chunks\n if (chunkContent.trim().length > 0) {\n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, i + 1).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: i + 1,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n // Add overlap for next chunk\n currentChunk = currentChunk.slice(-chunkOverlap);\n chunkStartLine = Math.max(0, i + 1 - chunkOverlap);\n }\n }\n \n // Flush remaining chunk\n if (currentChunk.length > 0) {\n const chunkContent = currentChunk.join('\\n');\n \n // Skip empty or whitespace-only chunks\n if (chunkContent.trim().length === 0) {\n return chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n }\n \n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, lines.length).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: lines.length,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n // Sort by line number\n return chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n}\n\n","import type { CodeChunk } from './types.js';\n\n/**\n * Shopify JSON template chunking\n * \n * JSON template files define which sections appear on a template page.\n * We extract section references to track dependencies.\n * \n * Example structure:\n * {\n * \"sections\": {\n * \"main\": { \"type\": \"main-product\", \"settings\": {...} },\n * \"recommendations\": { \"type\": \"product-recommendations\", \"settings\": {...} }\n * },\n * \"order\": [\"main\", \"recommendations\"]\n * }\n */\n\n/**\n * Extract section types from a Shopify JSON template\n * \n * These are the actual section file names (e.g., \"main-product\" → sections/main-product.liquid)\n */\nfunction extractSectionReferences(jsonContent: string): string[] {\n try {\n const template = JSON.parse(jsonContent);\n const sectionTypes = new Set<string>();\n \n // Extract from sections object\n if (template.sections && typeof template.sections === 'object') {\n for (const section of Object.values(template.sections)) {\n if (\n typeof section === 'object' && \n section !== null && \n 'type' in section && \n typeof section.type === 'string'\n ) {\n sectionTypes.add(section.type);\n }\n }\n }\n \n return Array.from(sectionTypes);\n } catch (error) {\n // Invalid JSON - return empty array\n console.warn(`[Lien] Failed to parse JSON template: ${error instanceof Error ? error.message : String(error)}`);\n return [];\n }\n}\n\n/**\n * Extract the template name from the filepath\n * \n * templates/customers/account.json → \"customers/account\"\n * templates/product.json → \"product\"\n */\nfunction extractTemplateName(filepath: string): string | undefined {\n // Match everything after templates/ up to .json\n const match = filepath.match(/templates\\/(.+)\\.json$/);\n return match ? match[1] : undefined;\n}\n\n/**\n * Chunk a Shopify JSON template file\n * \n * JSON templates are typically small (define section layout),\n * so we keep them as a single chunk and extract section references.\n */\nexport function chunkJSONTemplate(\n filepath: string,\n content: string\n): CodeChunk[] {\n // Skip empty files\n if (content.trim().length === 0) {\n return [];\n }\n \n const lines = content.split('\\n');\n const templateName = extractTemplateName(filepath);\n const sectionReferences = extractSectionReferences(content);\n \n return [{\n content,\n metadata: {\n file: filepath,\n startLine: 1,\n endLine: lines.length,\n language: 'json',\n type: 'template',\n symbolName: templateName,\n symbolType: 'template',\n imports: sectionReferences.length > 0 ? sectionReferences : undefined,\n },\n }];\n}\n\n","import { CodeChunk } from './types.js';\nimport { detectLanguage } from './scanner.js';\nimport { extractSymbols } from './symbol-extractor.js';\nimport { shouldUseAST, chunkByAST } from './ast/chunker.js';\nimport { chunkLiquidFile } from './liquid-chunker.js';\nimport { chunkJSONTemplate } from './json-template-chunker.js';\n\nexport interface ChunkOptions {\n chunkSize?: number;\n chunkOverlap?: number;\n useAST?: boolean; // Flag to enable AST-based chunking\n astFallback?: 'line-based' | 'error'; // How to handle AST parsing errors\n}\n\nexport function chunkFile(\n filepath: string,\n content: string,\n options: ChunkOptions = {}\n): CodeChunk[] {\n const { chunkSize = 75, chunkOverlap = 10, useAST = true, astFallback = 'line-based' } = options;\n \n // Special handling for Liquid files\n if (filepath.endsWith('.liquid')) {\n return chunkLiquidFile(filepath, content, chunkSize, chunkOverlap);\n }\n \n // Special handling for Shopify JSON template files (templates/**/*.json)\n // Use regex to ensure 'templates/' is a path segment, not part of another name\n // Matches: templates/product.json OR some-path/templates/customers/account.json\n // Rejects: my-templates/config.json OR node_modules/pkg/templates/file.json (filtered by scanner)\n if (filepath.endsWith('.json') && /(?:^|\\/)templates\\//.test(filepath)) {\n return chunkJSONTemplate(filepath, content);\n }\n \n // Try AST-based chunking for supported languages\n if (useAST && shouldUseAST(filepath)) {\n try {\n return chunkByAST(filepath, content, {\n minChunkSize: Math.floor(chunkSize / 10),\n });\n } catch (error) {\n // Handle AST errors based on configuration\n if (astFallback === 'error') {\n // Throw error if user wants strict AST-only behavior\n throw new Error(`AST chunking failed for ${filepath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n // Otherwise fallback to line-based chunking\n console.warn(`AST chunking failed for ${filepath}, falling back to line-based:`, error);\n }\n }\n \n // Line-based chunking (original implementation)\n return chunkByLines(filepath, content, chunkSize, chunkOverlap);\n}\n\n/**\n * Original line-based chunking implementation\n */\nfunction chunkByLines(\n filepath: string,\n content: string,\n chunkSize: number,\n chunkOverlap: number\n): CodeChunk[] {\n const lines = content.split('\\n');\n const chunks: CodeChunk[] = [];\n const language = detectLanguage(filepath);\n \n // Handle empty files\n if (lines.length === 0 || (lines.length === 1 && lines[0].trim() === '')) {\n return chunks;\n }\n \n // Chunk by lines with overlap\n for (let i = 0; i < lines.length; i += chunkSize - chunkOverlap) {\n const endLine = Math.min(i + chunkSize, lines.length);\n const chunkLines = lines.slice(i, endLine);\n const chunkContent = chunkLines.join('\\n');\n \n // Skip empty chunks\n if (chunkContent.trim().length === 0) {\n continue;\n }\n \n // Extract symbols from the chunk\n const symbols = extractSymbols(chunkContent, language);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: i + 1,\n endLine: endLine,\n type: 'block', // MVP: all chunks are 'block' type\n language,\n symbols,\n },\n });\n \n // If we've reached the end, break\n if (endLine >= lines.length) {\n break;\n }\n }\n \n return chunks;\n}\n\nexport function chunkText(text: string, options: ChunkOptions = {}): string[] {\n const { chunkSize = 75, chunkOverlap = 10 } = options;\n \n const lines = text.split('\\n');\n const chunks: string[] = [];\n \n for (let i = 0; i < lines.length; i += chunkSize - chunkOverlap) {\n const endLine = Math.min(i + chunkSize, lines.length);\n const chunkLines = lines.slice(i, endLine);\n const chunkContent = chunkLines.join('\\n');\n \n if (chunkContent.trim().length > 0) {\n chunks.push(chunkContent);\n }\n \n if (endLine >= lines.length) {\n break;\n }\n }\n \n return chunks;\n}\n\n","import { pipeline, env, type FeatureExtractionPipeline } from '@xenova/transformers';\nimport { EmbeddingService } from './types.js';\nimport { EmbeddingError, wrapError } from '../errors/index.js';\nimport { DEFAULT_EMBEDDING_MODEL } from '../constants.js';\n\n// Configure transformers.js to cache models locally\nenv.allowRemoteModels = true;\nenv.allowLocalModels = true;\n\nexport class LocalEmbeddings implements EmbeddingService {\n private extractor: FeatureExtractionPipeline | null = null;\n private readonly modelName = DEFAULT_EMBEDDING_MODEL;\n private initPromise: Promise<void> | null = null;\n \n async initialize(): Promise<void> {\n // Prevent multiple simultaneous initializations\n if (this.initPromise) {\n return this.initPromise;\n }\n \n if (this.extractor) {\n return;\n }\n \n this.initPromise = (async () => {\n try {\n // This downloads ~100MB on first run, then caches in ~/.cache/huggingface\n this.extractor = await pipeline('feature-extraction', this.modelName) as FeatureExtractionPipeline;\n } catch (error: unknown) {\n this.initPromise = null;\n throw wrapError(error, 'Failed to initialize embedding model');\n }\n })();\n \n return this.initPromise;\n }\n \n async embed(text: string): Promise<Float32Array> {\n await this.initialize();\n \n if (!this.extractor) {\n throw new EmbeddingError('Embedding model not initialized');\n }\n \n try {\n const output = await this.extractor(text, {\n pooling: 'mean',\n normalize: true,\n });\n \n return output.data as Float32Array;\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to generate embedding', { textLength: text.length });\n }\n }\n \n async embedBatch(texts: string[]): Promise<Float32Array[]> {\n await this.initialize();\n \n if (!this.extractor) {\n throw new EmbeddingError('Embedding model not initialized');\n }\n \n try {\n // Process embeddings with Promise.all for concurrent execution\n // Each call is sequential but Promise.all allows task interleaving\n const results = await Promise.all(\n texts.map(text => this.embed(text))\n );\n return results;\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to generate batch embeddings', { batchSize: texts.length });\n }\n }\n}\n\n","import { EMBEDDING_DIMENSIONS } from '../constants.js';\n\nexport interface EmbeddingService {\n initialize(): Promise<void>;\n embed(text: string): Promise<Float32Array>;\n embedBatch(texts: string[]): Promise<Float32Array[]>;\n}\n\nexport const EMBEDDING_DIMENSION = EMBEDDING_DIMENSIONS;\n\n","/**\n * Relevance category based on semantic similarity score\n */\nexport type RelevanceCategory = 'highly_relevant' | 'relevant' | 'loosely_related' | 'not_relevant';\n\n/**\n * Calculate relevance category from cosine distance score.\n * \n * Lower scores indicate higher similarity (closer in vector space).\n * Thresholds based on observed score distributions from dogfooding.\n * \n * @param score - Cosine distance score from vector search\n * @returns Human-readable relevance category\n */\nexport function calculateRelevance(score: number): RelevanceCategory {\n if (score < 1.0) return 'highly_relevant';\n if (score < 1.3) return 'relevant';\n if (score < 1.5) return 'loosely_related';\n return 'not_relevant';\n}\n\n","/**\n * Query Intent Classification\n * \n * Classifies user search queries into three categories to apply\n * appropriate relevance boosting strategies:\n * \n * - LOCATION: \"Where is X?\" - User wants to find specific files/code\n * - CONCEPTUAL: \"How does X work?\" - User wants to understand concepts\n * - IMPLEMENTATION: \"How is X implemented?\" - User wants implementation details\n * \n * Examples:\n * - \"where is the auth handler\" → LOCATION\n * - \"how does authentication work\" → CONCEPTUAL\n * - \"how is authentication implemented\" → IMPLEMENTATION\n */\n\n/**\n * Query intent types for semantic search\n */\nexport enum QueryIntent {\n /** User wants to locate specific files or code (e.g., \"where is X\") */\n LOCATION = 'location',\n \n /** User wants to understand concepts/processes (e.g., \"how does X work\") */\n CONCEPTUAL = 'conceptual',\n \n /** User wants implementation details (e.g., \"how is X implemented\") */\n IMPLEMENTATION = 'implementation',\n}\n\n/**\n * Intent classification rule with patterns and priority\n */\nexport interface IntentRule {\n intent: QueryIntent;\n patterns: RegExp[];\n priority: number;\n}\n\n/**\n * Intent classification rules.\n * Rules are checked in priority order (higher priority first).\n */\nconst INTENT_RULES: IntentRule[] = [\n // LOCATION intent (highest priority - most specific)\n {\n intent: QueryIntent.LOCATION,\n priority: 3,\n patterns: [\n /where\\s+(is|are|does|can\\s+i\\s+find)/,\n /find\\s+the\\s+/,\n /locate\\s+/,\n ],\n },\n \n // CONCEPTUAL intent (medium priority)\n {\n intent: QueryIntent.CONCEPTUAL,\n priority: 2,\n patterns: [\n /how\\s+does\\s+.*\\s+work/,\n /what\\s+(is|are|does)/,\n /explain\\s+/,\n /understand\\s+/,\n /\\b(process|workflow|architecture)\\b/,\n ],\n },\n \n // IMPLEMENTATION intent (low priority - catches \"how is X implemented\")\n {\n intent: QueryIntent.IMPLEMENTATION,\n priority: 1,\n patterns: [\n /how\\s+(is|are)\\s+.*\\s+(implemented|built|coded)/,\n /implementation\\s+of/,\n /source\\s+code\\s+for/,\n ],\n },\n];\n\n/**\n * Capture the initial number of built-in rules.\n * This is used by resetIntentRules() to distinguish built-in rules from custom rules.\n */\nconst INITIAL_RULE_COUNT = INTENT_RULES.length;\n\n/**\n * Cached sorted rules to avoid re-sorting on every query.\n * Invalidated when rules are modified via addIntentRule() or resetIntentRules().\n */\nlet cachedSortedRules: IntentRule[] | null = null;\n\n/**\n * Get sorted rules (cached).\n * Lazy-computes and caches the sorted array on first access.\n */\nfunction getSortedRules(): IntentRule[] {\n if (cachedSortedRules === null) {\n cachedSortedRules = [...INTENT_RULES].sort((a, b) => b.priority - a.priority);\n }\n return cachedSortedRules;\n}\n\n/**\n * Invalidate the sorted rules cache.\n * Called when rules are modified.\n */\nfunction invalidateSortedRulesCache(): void {\n cachedSortedRules = null;\n}\n\n/**\n * Classifies a search query into one of three intent categories.\n * \n * Uses data-driven pattern matching to detect query intent.\n * Rules are checked in priority order, with the first match winning.\n * \n * @param query - The search query string\n * @returns The detected query intent (defaults to IMPLEMENTATION)\n * \n * @example\n * classifyQueryIntent(\"where is the user controller\") // → LOCATION\n * classifyQueryIntent(\"how does authentication work\") // → CONCEPTUAL\n * classifyQueryIntent(\"how is the API implemented\") // → IMPLEMENTATION\n */\nexport function classifyQueryIntent(query: string): QueryIntent {\n const lower = query.toLowerCase().trim();\n \n // Use cached sorted rules to avoid re-sorting on every query\n const sortedRules = getSortedRules();\n \n for (const rule of sortedRules) {\n if (rule.patterns.some(pattern => pattern.test(lower))) {\n return rule.intent;\n }\n }\n \n // Default to IMPLEMENTATION for ambiguous queries\n // This is the most common use case for code search\n return QueryIntent.IMPLEMENTATION;\n}\n\n/**\n * Add a custom intent rule (useful for testing or extensions).\n * \n * Returns a cleanup function that removes the added rule.\n * This prevents test pollution and allows proper cleanup.\n * \n * @param rule - The intent rule to add\n * @returns A cleanup function that removes the added rule\n * \n * @example\n * const cleanup = addIntentRule({\n * intent: QueryIntent.LOCATION,\n * priority: 4,\n * patterns: [/custom pattern/]\n * });\n * // ... use the rule ...\n * cleanup(); // removes the rule\n */\nexport function addIntentRule(rule: IntentRule): () => void {\n INTENT_RULES.push(rule);\n \n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n \n // Return cleanup function to remove the rule\n return () => {\n const idx = INTENT_RULES.indexOf(rule);\n if (idx !== -1) {\n INTENT_RULES.splice(idx, 1);\n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n }\n };\n}\n\n/**\n * Get all patterns for a specific intent (useful for debugging).\n * \n * @param intent - The intent to get patterns for\n * @returns Array of regex patterns for the intent\n * \n * @example\n * const locationPatterns = getPatternsForIntent(QueryIntent.LOCATION);\n */\nexport function getPatternsForIntent(intent: QueryIntent): RegExp[] {\n return INTENT_RULES\n .filter(rule => rule.intent === intent)\n .flatMap(rule => rule.patterns);\n}\n\n/**\n * Get all intent rules (useful for testing/debugging).\n * \n * @returns A copy of the current intent rules\n */\nexport function getIntentRules(): IntentRule[] {\n return [...INTENT_RULES];\n}\n\n/**\n * Reset intent rules to initial state.\n * \n * WARNING: This function is intended for testing only.\n * It removes all custom rules added via addIntentRule().\n * The original built-in rules are preserved.\n * \n * @example\n * // In test cleanup\n * afterEach(() => {\n * resetIntentRules();\n * });\n */\nexport function resetIntentRules(): void {\n // Remove all custom rules, preserving only the original built-in rules\n INTENT_RULES.splice(INITIAL_RULE_COUNT);\n \n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n}\n\n","/**\n * Boosting strategy interface.\n * \n * Each strategy applies a specific relevance boosting technique\n * to search results based on file characteristics.\n */\nexport interface BoostingStrategy {\n /** Name of the strategy (for debugging/logging) */\n name: string;\n \n /**\n * Apply the boosting strategy to a score.\n * \n * @param query - The search query string\n * @param filepath - The file path being scored\n * @param baseScore - The base relevance score from vector similarity\n * @returns The boosted score (lower is better, following LanceDB distance metric)\n */\n apply(query: string, filepath: string, baseScore: number): number;\n}\n\n","import type { BoostingStrategy } from './types.js';\nimport path from 'path';\nimport { QueryIntent } from '../intent-classifier.js';\n\n/**\n * File type detection helpers\n */\n\nfunction isDocumentationFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n const filename = path.basename(filepath).toLowerCase();\n \n if (filename.startsWith('readme')) return true;\n if (filename.startsWith('changelog')) return true;\n if (filename.endsWith('.md') || filename.endsWith('.mdx') || filename.endsWith('.markdown')) {\n return true;\n }\n if (\n lower.includes('/docs/') ||\n lower.includes('/documentation/') ||\n lower.includes('/wiki/') ||\n lower.includes('/.github/')\n ) {\n return true;\n }\n if (\n lower.includes('architecture') ||\n lower.includes('workflow') ||\n lower.includes('/flow/')\n ) {\n return true;\n }\n \n return false;\n}\n\nfunction isTestFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n \n if (\n lower.includes('/test/') ||\n lower.includes('/tests/') ||\n lower.includes('/__tests__/')\n ) {\n return true;\n }\n \n if (\n lower.includes('.test.') ||\n lower.includes('.spec.') ||\n lower.includes('_test.') ||\n lower.includes('_spec.')\n ) {\n return true;\n }\n \n return false;\n}\n\nfunction isUtilityFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n \n if (\n lower.includes('/utils/') ||\n lower.includes('/utilities/') ||\n lower.includes('/helpers/') ||\n lower.includes('/lib/')\n ) {\n return true;\n }\n \n if (\n lower.includes('.util.') ||\n lower.includes('.helper.') ||\n lower.includes('-util.') ||\n lower.includes('-helper.')\n ) {\n return true;\n }\n \n return false;\n}\n\n/**\n * Boosting Strategies\n */\n\n/**\n * Boosts relevance based on path segment matching.\n * Files with query tokens in their path are boosted.\n */\nexport class PathBoostingStrategy implements BoostingStrategy {\n name = 'path-matching';\n \n apply(query: string, filepath: string, baseScore: number): number {\n const queryTokens = query.toLowerCase().split(/\\s+/);\n const pathSegments = filepath.toLowerCase().split('/');\n \n let boostFactor = 1.0;\n \n for (const token of queryTokens) {\n if (token.length <= 2) continue;\n if (pathSegments.some(seg => seg.includes(token))) {\n boostFactor *= 0.9; // Reduce distance = increase relevance\n }\n }\n \n return baseScore * boostFactor;\n }\n}\n\n/**\n * Boosts relevance based on filename matching.\n * Files with query tokens in their filename are strongly boosted.\n */\nexport class FilenameBoostingStrategy implements BoostingStrategy {\n name = 'filename-matching';\n \n apply(query: string, filepath: string, baseScore: number): number {\n const filename = path.basename(filepath, path.extname(filepath)).toLowerCase();\n const queryTokens = query.toLowerCase().split(/\\s+/);\n \n let boostFactor = 1.0;\n \n for (const token of queryTokens) {\n if (token.length <= 2) continue;\n \n if (filename === token) {\n boostFactor *= 0.70; // Strong boost for exact match\n } else if (filename.includes(token)) {\n boostFactor *= 0.80; // Moderate boost for partial match\n }\n }\n \n return baseScore * boostFactor;\n }\n}\n\n/**\n * Boosts relevance based on file type and query intent.\n * Different file types are boosted for different query intents.\n * \n * Note: This strategy focuses on file-type-specific boosting (test files,\n * documentation files, utility files, etc.). Path and filename boosting\n * are handled separately by PathBoostingStrategy and FilenameBoostingStrategy\n * in the BoostingComposer to avoid double-boosting.\n */\nexport class FileTypeBoostingStrategy implements BoostingStrategy {\n name = 'file-type';\n \n constructor(private intent: QueryIntent) {}\n \n apply(query: string, filepath: string, baseScore: number): number {\n switch (this.intent) {\n case QueryIntent.LOCATION:\n return this.applyLocationBoosting(query, filepath, baseScore);\n \n case QueryIntent.CONCEPTUAL:\n return this.applyConceptualBoosting(query, filepath, baseScore);\n \n case QueryIntent.IMPLEMENTATION:\n return this.applyImplementationBoosting(query, filepath, baseScore);\n \n default:\n return baseScore;\n }\n }\n \n private applyLocationBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for location queries.\n \n // Slightly deprioritize test files (users want implementation location, not tests)\n if (isTestFile(filepath)) {\n score *= 1.10;\n }\n \n return score;\n }\n \n private applyConceptualBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for conceptual queries.\n \n // Strong boost for documentation files\n if (isDocumentationFile(filepath)) {\n score *= 0.65;\n \n const lower = filepath.toLowerCase();\n if (\n lower.includes('architecture') ||\n lower.includes('workflow') ||\n lower.includes('flow')\n ) {\n score *= 0.90; // Extra boost for architectural docs\n }\n }\n \n // Slight boost for utility files (often contain reusable logic)\n if (isUtilityFile(filepath)) {\n score *= 0.95;\n }\n \n return score;\n }\n \n private applyImplementationBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for implementation queries.\n \n // Slightly deprioritize test files (user wants implementation, not tests)\n if (isTestFile(filepath)) {\n score *= 1.10;\n }\n \n return score;\n }\n}\n\n","import type { BoostingStrategy } from './types.js';\n\n/**\n * Composes multiple boosting strategies into a single pipeline.\n * \n * Strategies are applied sequentially, with each strategy\n * receiving the output of the previous strategy as input.\n * \n * @example\n * ```typescript\n * const composer = new BoostingComposer()\n * .addStrategy(new PathBoostingStrategy())\n * .addStrategy(new FilenameBoostingStrategy())\n * .addStrategy(new FileTypeBoostingStrategy(intent));\n * \n * const boostedScore = composer.apply(query, filepath, baseScore);\n * ```\n */\nexport class BoostingComposer {\n private strategies: BoostingStrategy[] = [];\n \n /**\n * Add a boosting strategy to the pipeline.\n * Strategies are applied in the order they are added.\n * \n * @param strategy - The strategy to add\n * @returns This composer for chaining\n */\n addStrategy(strategy: BoostingStrategy): this {\n this.strategies.push(strategy);\n return this;\n }\n \n /**\n * Apply all strategies to a base score.\n * \n * @param query - The search query\n * @param filepath - The file path being scored\n * @param baseScore - The initial score from vector similarity\n * @returns The final boosted score after all strategies\n */\n apply(query: string, filepath: string, baseScore: number): number {\n let score = baseScore;\n \n for (const strategy of this.strategies) {\n score = strategy.apply(query, filepath, score);\n }\n \n return score;\n }\n \n /**\n * Get the names of all strategies in this composer.\n * Useful for debugging and logging.\n */\n getStrategyNames(): string[] {\n return this.strategies.map(s => s.name);\n }\n \n /**\n * Get the number of strategies in this composer.\n */\n getStrategyCount(): number {\n return this.strategies.length;\n }\n \n /**\n * Clear all strategies from this composer.\n */\n clear(): void {\n this.strategies = [];\n }\n}\n\n","/**\n * Composable boosting strategies for semantic search relevance.\n * \n * This module provides a strategy pattern implementation for applying\n * relevance boosting to search results. Strategies can be composed\n * together to create complex boosting pipelines.\n * \n * @example\n * ```typescript\n * import { BoostingComposer, PathBoostingStrategy, FilenameBoostingStrategy } from './boosting';\n * \n * const composer = new BoostingComposer()\n * .addStrategy(new PathBoostingStrategy())\n * .addStrategy(new FilenameBoostingStrategy());\n * \n * const boostedScore = composer.apply(query, filepath, baseScore);\n * ```\n */\n\nexport * from './types.js';\nexport * from './strategies.js';\nexport * from './composer.js';\n\n","import { SearchResult } from './types.js';\nimport { EMBEDDING_DIMENSION } from '../embeddings/types.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport { calculateRelevance } from './relevance.js';\nimport { classifyQueryIntent, QueryIntent } from './intent-classifier.js';\nimport { BoostingComposer, PathBoostingStrategy, FilenameBoostingStrategy, FileTypeBoostingStrategy } from './boosting/index.js';\n\n// TODO: Replace with proper type from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// See: https://github.com/getlien/lien/issues/XXX\ntype LanceDBTable = any;\n\n/**\n * Cached strategy instances to avoid repeated instantiation overhead.\n * These strategies are stateless and can be safely reused across queries.\n */\nconst PATH_STRATEGY = new PathBoostingStrategy();\nconst FILENAME_STRATEGY = new FilenameBoostingStrategy();\n\n/**\n * Cached FileTypeBoostingStrategy instances for each intent.\n * Since there are only three possible intents, we can cache all three.\n */\nconst FILE_TYPE_STRATEGIES = {\n [QueryIntent.LOCATION]: new FileTypeBoostingStrategy(QueryIntent.LOCATION),\n [QueryIntent.CONCEPTUAL]: new FileTypeBoostingStrategy(QueryIntent.CONCEPTUAL),\n [QueryIntent.IMPLEMENTATION]: new FileTypeBoostingStrategy(QueryIntent.IMPLEMENTATION),\n};\n\n/**\n * Cached BoostingComposer instances for each intent.\n * Pre-configured with the appropriate strategy pipeline for each intent type.\n * This avoids creating a new composer instance on every search result.\n */\nconst BOOSTING_COMPOSERS = {\n [QueryIntent.LOCATION]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.LOCATION]),\n [QueryIntent.CONCEPTUAL]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.CONCEPTUAL]),\n [QueryIntent.IMPLEMENTATION]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.IMPLEMENTATION]),\n};\n\n/**\n * Database record structure as stored in LanceDB\n */\ninterface DBRecord {\n vector: number[];\n content: string;\n file: string;\n startLine: number;\n endLine: number;\n type: string;\n language: string;\n functionNames: string[];\n classNames: string[];\n interfaceNames: string[];\n // AST-derived metadata (v0.13.0)\n symbolName?: string;\n symbolType?: string;\n parentClass?: string;\n complexity?: number;\n cognitiveComplexity?: number;\n parameters?: string[];\n signature?: string;\n imports?: string[];\n // Halstead metrics (v0.19.0)\n halsteadVolume?: number;\n halsteadDifficulty?: number;\n halsteadEffort?: number;\n halsteadBugs?: number;\n _distance?: number; // Added by LanceDB for search results\n}\n\n/**\n * Check if a DB record has valid content and file path.\n * Used to filter out empty/invalid records from query results.\n */\nfunction isValidRecord(r: DBRecord): boolean {\n return Boolean(\n r.content && \n r.content.trim().length > 0 &&\n r.file && \n r.file.length > 0\n );\n}\n\n/**\n * Check if an array field has valid (non-empty) entries.\n * LanceDB stores empty arrays as [''] which we need to filter out.\n */\nfunction hasValidArrayEntries(arr: string[] | undefined): boolean {\n return Boolean(arr && arr.length > 0 && arr[0] !== '');\n}\n\n/**\n * Get symbols for a specific type from a DB record.\n * Consolidates the symbol extraction logic used across query functions.\n */\nfunction getSymbolsForType(\n r: DBRecord, \n symbolType?: 'function' | 'class' | 'interface'\n): string[] {\n if (symbolType === 'function') return r.functionNames || [];\n if (symbolType === 'class') return r.classNames || [];\n if (symbolType === 'interface') return r.interfaceNames || [];\n return [\n ...(r.functionNames || []),\n ...(r.classNames || []),\n ...(r.interfaceNames || []),\n ];\n}\n\n/**\n * Convert a DB record to base SearchResult metadata.\n * Shared between all query functions to avoid duplication.\n */\nfunction buildSearchResultMetadata(r: DBRecord): SearchResult['metadata'] {\n return {\n file: r.file,\n startLine: r.startLine,\n endLine: r.endLine,\n type: r.type as 'function' | 'class' | 'block',\n language: r.language,\n symbolName: r.symbolName || undefined,\n symbolType: r.symbolType as 'function' | 'method' | 'class' | 'interface' | undefined,\n parentClass: r.parentClass || undefined,\n complexity: r.complexity || undefined,\n cognitiveComplexity: r.cognitiveComplexity || undefined,\n parameters: hasValidArrayEntries(r.parameters) ? r.parameters : undefined,\n signature: r.signature || undefined,\n imports: hasValidArrayEntries(r.imports) ? r.imports : undefined,\n // Halstead metrics (v0.19.0) - use explicit null check to preserve valid 0 values\n halsteadVolume: r.halsteadVolume != null ? r.halsteadVolume : undefined,\n halsteadDifficulty: r.halsteadDifficulty != null ? r.halsteadDifficulty : undefined,\n halsteadEffort: r.halsteadEffort != null ? r.halsteadEffort : undefined,\n halsteadBugs: r.halsteadBugs != null ? r.halsteadBugs : undefined,\n };\n}\n\n/**\n * Apply relevance boosting strategies to a search score.\n * \n * Uses composable boosting strategies based on query intent:\n * - Path matching: Boost files with query tokens in path\n * - Filename matching: Boost files with query tokens in filename\n * - File type boosting: Intent-specific boosting (docs for conceptual, etc.)\n */\nfunction applyRelevanceBoosting(\n query: string | undefined,\n filepath: string,\n baseScore: number\n): number {\n if (!query) {\n return baseScore;\n }\n \n const intent = classifyQueryIntent(query);\n \n // Use cached composer instance configured for this intent\n return BOOSTING_COMPOSERS[intent].apply(query, filepath, baseScore);\n}\n\n/**\n * Convert a DBRecord to a SearchResult\n */\nfunction dbRecordToSearchResult(\n r: DBRecord,\n query?: string\n): SearchResult {\n const baseScore = r._distance ?? 0;\n const boostedScore = applyRelevanceBoosting(query, r.file, baseScore);\n \n return {\n content: r.content,\n metadata: buildSearchResultMetadata(r),\n score: boostedScore,\n relevance: calculateRelevance(boostedScore),\n };\n}\n\n/**\n * Search the vector database\n */\nexport async function search(\n table: LanceDBTable,\n queryVector: Float32Array,\n limit: number = 5,\n query?: string\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n const results = await table\n .search(Array.from(queryVector))\n .limit(limit + 20)\n .toArray();\n \n const filtered = (results as unknown as DBRecord[])\n .filter(isValidRecord)\n .map((r: DBRecord) => dbRecordToSearchResult(r, query))\n .sort((a, b) => a.score - b.score)\n .slice(0, limit);\n \n return filtered;\n } catch (error) {\n const errorMsg = String(error);\n \n // Detect corrupted index\n if (errorMsg.includes('Not found:') || errorMsg.includes('.lance')) {\n throw new DatabaseError(\n `Index appears corrupted or outdated. Please restart the MCP server or run 'lien reindex' in the project directory.`,\n { originalError: error }\n );\n }\n \n throw wrapError(error, 'Failed to search vector database');\n }\n}\n\n/**\n * Scan the database with filters\n */\nexport async function scanWithFilter(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n limit?: number;\n }\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n const { language, pattern, limit = 100 } = options;\n \n try {\n const zeroVector = Array(EMBEDDING_DIMENSION).fill(0);\n const query = table.search(zeroVector)\n .where('file != \"\"')\n .limit(Math.max(limit * 5, 200));\n \n const results = await query.toArray();\n \n let filtered = (results as unknown as DBRecord[]).filter(isValidRecord);\n \n if (language) {\n filtered = filtered.filter((r: DBRecord) => \n r.language && r.language.toLowerCase() === language.toLowerCase()\n );\n }\n \n if (pattern) {\n const regex = new RegExp(pattern, 'i');\n filtered = filtered.filter((r: DBRecord) =>\n regex.test(r.content) || regex.test(r.file)\n );\n }\n \n return filtered.slice(0, limit).map((r: DBRecord) => ({\n content: r.content,\n metadata: buildSearchResultMetadata(r),\n score: 0,\n relevance: calculateRelevance(0),\n }));\n } catch (error) {\n throw wrapError(error, 'Failed to scan with filter');\n }\n}\n\n/**\n * Helper to check if a record matches the requested symbol type\n */\n/** Maps query symbolType to acceptable AST symbolType values */\nconst SYMBOL_TYPE_MATCHES: Record<string, Set<string>> = {\n function: new Set(['function', 'method']),\n class: new Set(['class']),\n interface: new Set(['interface']),\n};\n\nfunction matchesSymbolType(\n record: DBRecord,\n symbolType: 'function' | 'class' | 'interface',\n symbols: string[]\n): boolean {\n // If AST-based symbolType exists, use lookup table\n if (record.symbolType) {\n return SYMBOL_TYPE_MATCHES[symbolType]?.has(record.symbolType) ?? false;\n }\n\n // Fallback: check if pre-AST symbols array has valid entries\n return symbols.length > 0 && symbols.some((s: string) => s.length > 0 && s !== '');\n}\n\ninterface SymbolQueryOptions {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n}\n\n/**\n * Check if a record matches the symbol query filters.\n * Extracted to reduce complexity of querySymbols.\n */\nfunction matchesSymbolFilter(\n r: DBRecord, \n { language, pattern, symbolType }: SymbolQueryOptions\n): boolean {\n // Language filter\n if (language && (!r.language || r.language.toLowerCase() !== language.toLowerCase())) {\n return false;\n }\n \n const symbols = getSymbolsForType(r, symbolType);\n const astSymbolName = r.symbolName || '';\n \n // Must have at least one symbol (legacy or AST-based)\n if (symbols.length === 0 && !astSymbolName) {\n return false;\n }\n \n // Pattern filter (if provided)\n if (pattern) {\n const regex = new RegExp(pattern, 'i');\n const nameMatches = symbols.some((s: string) => regex.test(s)) || regex.test(astSymbolName);\n if (!nameMatches) return false;\n }\n \n // Symbol type filter (if provided)\n if (symbolType) {\n return matchesSymbolType(r, symbolType, symbols);\n }\n \n return true;\n}\n\n/**\n * Build legacy symbols object for backwards compatibility.\n */\nfunction buildLegacySymbols(r: DBRecord) {\n return {\n functions: hasValidArrayEntries(r.functionNames) ? r.functionNames : [],\n classes: hasValidArrayEntries(r.classNames) ? r.classNames : [],\n interfaces: hasValidArrayEntries(r.interfaceNames) ? r.interfaceNames : [],\n };\n}\n\n/**\n * Query symbols (functions, classes, interfaces)\n */\nexport async function querySymbols(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n limit?: number;\n }\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n const { language, pattern, symbolType, limit = 50 } = options;\n const filterOpts: SymbolQueryOptions = { language, pattern, symbolType };\n \n try {\n const zeroVector = Array(EMBEDDING_DIMENSION).fill(0);\n const query = table.search(zeroVector)\n .where('file != \"\"')\n .limit(Math.max(limit * 10, 500));\n \n const results = await query.toArray();\n \n const filtered = (results as unknown as DBRecord[])\n .filter((r) => isValidRecord(r) && matchesSymbolFilter(r, filterOpts));\n \n return filtered.slice(0, limit).map((r: DBRecord) => ({\n content: r.content,\n metadata: {\n ...buildSearchResultMetadata(r),\n symbols: buildLegacySymbols(r),\n },\n score: 0,\n relevance: calculateRelevance(0),\n }));\n } catch (error) {\n throw wrapError(error, 'Failed to query symbols');\n }\n}\n\n/**\n * Scan all chunks in the database\n * First gets the total count, then fetches all with a single query\n * This is more efficient than pagination for local/embedded databases like LanceDB\n */\nexport async function scanAll(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n } = {}\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // Get total row count to determine limit\n const totalRows = await table.countRows();\n \n // Fetch all rows in one query (LanceDB is local, this is efficient)\n // Note: scanWithFilter internally fetches 5x the limit to handle filtering overhead,\n // then caps output to 'limit'. We pass totalRows so we get all rows back after\n // filtering. The 5x overfetch is acceptable overhead for local DBs.\n const MIN_SCAN_LIMIT = 1000;\n const results = await scanWithFilter(table, {\n ...options,\n limit: Math.max(totalRows, MIN_SCAN_LIMIT),\n });\n \n return results;\n } catch (error) {\n throw wrapError(error, 'Failed to scan all chunks');\n }\n}\n","import { ChunkMetadata } from '../indexer/types.js';\nimport { DatabaseError } from '../errors/index.js';\nimport { VECTOR_DB_MAX_BATCH_SIZE, VECTOR_DB_MIN_BATCH_SIZE } from '../constants.js';\n\n// TODO: Replace with proper types from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// Proper types: Awaited<ReturnType<typeof lancedb.connect>> and Awaited<ReturnType<Connection['openTable']>>\ntype LanceDBConnection = any;\ntype LanceDBTable = any;\n\n/**\n * Batch of data to be inserted into the vector database\n */\ninterface BatchToProcess {\n vectors: Float32Array[];\n metadatas: ChunkMetadata[];\n contents: string[];\n}\n\n/**\n * Database record format for LanceDB storage\n */\ninterface DatabaseRecord {\n vector: number[];\n content: string;\n file: string;\n startLine: number;\n endLine: number;\n type: string;\n language: string;\n functionNames: string[];\n classNames: string[];\n interfaceNames: string[];\n symbolName: string;\n symbolType: string;\n parentClass: string;\n complexity: number;\n cognitiveComplexity: number;\n parameters: string[];\n signature: string;\n imports: string[];\n // Halstead metrics (v0.19.0)\n halsteadVolume: number;\n halsteadDifficulty: number;\n halsteadEffort: number;\n halsteadBugs: number;\n}\n\n/**\n * Transform a chunk's data into a database record.\n * Handles missing/empty metadata by providing defaults for Arrow type inference.\n */\nfunction transformChunkToRecord(\n vector: Float32Array,\n content: string,\n metadata: ChunkMetadata\n): DatabaseRecord {\n return {\n vector: Array.from(vector),\n content,\n file: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n type: metadata.type,\n language: metadata.language,\n // Ensure arrays have at least empty string for Arrow type inference\n functionNames: getNonEmptyArray(metadata.symbols?.functions),\n classNames: getNonEmptyArray(metadata.symbols?.classes),\n interfaceNames: getNonEmptyArray(metadata.symbols?.interfaces),\n // AST-derived metadata (v0.13.0)\n symbolName: metadata.symbolName || '',\n symbolType: metadata.symbolType || '',\n parentClass: metadata.parentClass || '',\n complexity: metadata.complexity || 0,\n cognitiveComplexity: metadata.cognitiveComplexity || 0,\n parameters: getNonEmptyArray(metadata.parameters),\n signature: metadata.signature || '',\n imports: getNonEmptyArray(metadata.imports),\n // Halstead metrics (v0.19.0)\n halsteadVolume: metadata.halsteadVolume || 0,\n halsteadDifficulty: metadata.halsteadDifficulty || 0,\n halsteadEffort: metadata.halsteadEffort || 0,\n halsteadBugs: metadata.halsteadBugs || 0,\n };\n}\n\n/**\n * Returns the array if non-empty, otherwise returns [''] for Arrow type inference\n */\nfunction getNonEmptyArray(arr: string[] | undefined): string[] {\n return arr && arr.length > 0 ? arr : [''];\n}\n\n/**\n * Split a batch in half for retry logic\n */\nfunction splitBatchInHalf(batch: BatchToProcess): [BatchToProcess, BatchToProcess] {\n const half = Math.floor(batch.vectors.length / 2);\n return [\n {\n vectors: batch.vectors.slice(0, half),\n metadatas: batch.metadatas.slice(0, half),\n contents: batch.contents.slice(0, half),\n },\n {\n vectors: batch.vectors.slice(half),\n metadatas: batch.metadatas.slice(half),\n contents: batch.contents.slice(half),\n },\n ];\n}\n\n/**\n * Transform all chunks in a batch to database records\n */\nfunction transformBatchToRecords(batch: BatchToProcess): DatabaseRecord[] {\n return batch.vectors.map((vector, i) =>\n transformChunkToRecord(vector, batch.contents[i], batch.metadatas[i])\n );\n}\n\n/**\n * Insert a batch of vectors into the database\n * \n * @returns The table instance after insertion, or null only when:\n * - vectors.length === 0 AND table === null (no-op case)\n * For non-empty batches, always returns a valid table or throws.\n * @throws {DatabaseError} If database not initialized or insertion fails\n */\nexport async function insertBatch(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable | null> {\n if (!db) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n if (vectors.length !== metadatas.length || vectors.length !== contents.length) {\n throw new DatabaseError('Vectors, metadatas, and contents arrays must have the same length', {\n vectorsLength: vectors.length,\n metadatasLength: metadatas.length,\n contentsLength: contents.length,\n });\n }\n \n // Handle empty batch gracefully - return table as-is (could be null)\n if (vectors.length === 0) {\n return table;\n }\n \n // Split large batches into smaller chunks\n if (vectors.length > VECTOR_DB_MAX_BATCH_SIZE) {\n let currentTable = table;\n for (let i = 0; i < vectors.length; i += VECTOR_DB_MAX_BATCH_SIZE) {\n const batchVectors = vectors.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n const batchMetadata = metadatas.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n const batchContents = contents.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n \n currentTable = await insertBatchInternal(db, currentTable, tableName, batchVectors, batchMetadata, batchContents);\n }\n if (!currentTable) {\n throw new DatabaseError('Failed to create table during batch insert');\n }\n return currentTable;\n } else {\n return insertBatchInternal(db, table, tableName, vectors, metadatas, contents);\n }\n}\n\n/**\n * Internal method to insert a single batch with iterative retry logic.\n * Uses a queue-based approach to handle batch splitting on failure.\n * \n * @returns Always returns a valid LanceDBTable or throws DatabaseError\n */\nasync function insertBatchInternal(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable> {\n const queue: BatchToProcess[] = [{ vectors, metadatas, contents }];\n const failedBatches: BatchToProcess[] = [];\n let currentTable = table;\n let lastError: Error | undefined;\n \n while (queue.length > 0) {\n const batch = queue.shift()!;\n const insertResult = await tryInsertBatch(db, currentTable, tableName, batch);\n \n if (insertResult.success) {\n currentTable = insertResult.table;\n } else {\n lastError = insertResult.error;\n handleBatchFailure(batch, queue, failedBatches);\n }\n }\n \n throwIfBatchesFailed(failedBatches, lastError);\n \n if (!currentTable) {\n throw new DatabaseError('Failed to create table during batch insert');\n }\n \n return currentTable;\n}\n\n/**\n * Result of attempting to insert a batch\n */\ninterface InsertResult {\n success: boolean;\n table: LanceDBTable | null;\n error?: Error;\n}\n\n/**\n * Attempt to insert a batch of records into the database.\n * Errors are captured and returned (not thrown) to support retry logic.\n */\nasync function tryInsertBatch(\n db: LanceDBConnection,\n currentTable: LanceDBTable | null,\n tableName: string,\n batch: BatchToProcess\n): Promise<InsertResult> {\n try {\n const records = transformBatchToRecords(batch);\n \n if (!currentTable) {\n const newTable = await db.createTable(tableName, records);\n return { success: true, table: newTable };\n } else {\n await currentTable.add(records);\n return { success: true, table: currentTable };\n }\n } catch (error) {\n // Error is captured for retry logic - will be included in final error if all retries fail\n return { success: false, table: currentTable, error: error as Error };\n }\n}\n\n/**\n * Handle a failed batch insertion by either splitting and retrying or marking as failed\n */\nfunction handleBatchFailure(\n batch: BatchToProcess,\n queue: BatchToProcess[],\n failedBatches: BatchToProcess[]\n): void {\n if (batch.vectors.length > VECTOR_DB_MIN_BATCH_SIZE) {\n // Split and retry\n const [firstHalf, secondHalf] = splitBatchInHalf(batch);\n queue.push(firstHalf, secondHalf);\n } else {\n // Can't split further, mark as failed\n failedBatches.push(batch);\n }\n}\n\n/**\n * Throw an error if any batches failed after all retry attempts.\n * Includes the last error encountered for debugging.\n */\nfunction throwIfBatchesFailed(failedBatches: BatchToProcess[], lastError?: Error): void {\n if (failedBatches.length === 0) return;\n \n const totalFailed = failedBatches.reduce((sum, batch) => sum + batch.vectors.length, 0);\n throw new DatabaseError(\n `Failed to insert ${totalFailed} record(s) after retry attempts`,\n {\n failedBatches: failedBatches.length,\n totalRecords: totalFailed,\n sampleFile: failedBatches[0].metadatas[0].file,\n lastError: lastError?.message,\n }\n );\n}\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport { writeVersionFile } from './version.js';\nimport { insertBatch } from './batch-insert.js';\n\n// TODO: Replace with proper types from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// Proper types: Awaited<ReturnType<typeof lancedb.connect>> and Awaited<ReturnType<Connection['openTable']>>\ntype LanceDBConnection = any;\ntype LanceDBTable = any;\n\n/**\n * Clear all data from the vector database.\n * Drops the table AND cleans up the .lance directory to prevent corrupted state.\n */\nexport async function clear(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n dbPath?: string\n): Promise<void> {\n if (!db) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // Drop table if it exists\n if (table) {\n await db.dropTable(tableName);\n }\n \n // Clean up the .lance directory if dbPath provided\n // This prevents corrupted state after dropTable\n if (dbPath) {\n const lanceDir = path.join(dbPath, `${tableName}.lance`);\n try {\n await fs.rm(lanceDir, { recursive: true, force: true });\n } catch {\n // Ignore errors - directory may not exist\n }\n }\n } catch (error) {\n throw wrapError(error, 'Failed to clear vector database');\n }\n}\n\n/**\n * Delete all chunks from a specific file\n */\nexport async function deleteByFile(\n table: LanceDBTable,\n filepath: string\n): Promise<void> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n await table.delete(`file = \"${filepath}\"`);\n } catch (error) {\n throw wrapError(error, 'Failed to delete file from vector database');\n }\n}\n\n/**\n * Update a file in the index by atomically deleting old chunks and inserting new ones\n */\nexport async function updateFile(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n dbPath: string,\n filepath: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // 1. Delete old chunks from this file\n await deleteByFile(table, filepath);\n \n // 2. Insert new chunks (if any)\n let updatedTable = table;\n if (vectors.length > 0) {\n updatedTable = await insertBatch(db, table, tableName, vectors, metadatas, contents);\n if (!updatedTable) {\n throw new DatabaseError('insertBatch unexpectedly returned null');\n }\n }\n \n // 3. Update version file to trigger MCP reconnection\n await writeVersionFile(dbPath);\n \n return updatedTable;\n } catch (error) {\n throw wrapError(error, 'Failed to update file in vector database');\n }\n}\n\n","import * as lancedb from '@lancedb/lancedb';\nimport path from 'path';\nimport os from 'os';\nimport crypto from 'crypto';\nimport { SearchResult, VectorDBInterface } from './types.js';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { EMBEDDING_DIMENSION } from '../embeddings/types.js';\nimport { readVersionFile } from './version.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport * as queryOps from './query.js';\nimport * as batchOps from './batch-insert.js';\nimport * as maintenanceOps from './maintenance.js';\n\ntype LanceDBConnection = Awaited<ReturnType<typeof lancedb.connect>>;\ntype LanceDBTable = Awaited<ReturnType<LanceDBConnection['openTable']>>;\n\nexport class VectorDB implements VectorDBInterface {\n private db: LanceDBConnection | null = null;\n private table: LanceDBTable | null = null;\n public readonly dbPath: string;\n private readonly tableName = 'code_chunks';\n private lastVersionCheck: number = 0;\n private currentVersion: number = 0;\n \n constructor(projectRoot: string) {\n // Store in user's home directory under ~/.lien/indices/{projectName-hash}\n const projectName = path.basename(projectRoot);\n \n // Create unique identifier from full path to prevent collisions\n const pathHash = crypto\n .createHash('md5')\n .update(projectRoot)\n .digest('hex')\n .substring(0, 8);\n \n this.dbPath = path.join(\n os.homedir(),\n '.lien',\n 'indices',\n `${projectName}-${pathHash}`\n );\n }\n \n async initialize(): Promise<void> {\n try {\n this.db = await lancedb.connect(this.dbPath);\n \n try {\n this.table = await this.db.openTable(this.tableName);\n } catch {\n // Table doesn't exist yet - will be created on first insert\n this.table = null;\n }\n \n // Read and cache the current version\n try {\n this.currentVersion = await readVersionFile(this.dbPath);\n } catch {\n // Version file doesn't exist yet, will be created on first index\n this.currentVersion = 0;\n }\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to initialize vector database', { dbPath: this.dbPath });\n }\n }\n \n async insertBatch(\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n ): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database not initialized');\n }\n // Note: insertBatch may return null for empty batches when table is null\n // This is correct behavior - empty batches are no-ops and don't create tables\n this.table = await batchOps.insertBatch(\n this.db,\n this.table,\n this.tableName,\n vectors,\n metadatas,\n contents\n );\n }\n \n async search(\n queryVector: Float32Array,\n limit: number = 5,\n query?: string\n ): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n return await queryOps.search(this.table, queryVector, limit, query);\n } catch (error) {\n const errorMsg = String(error);\n \n // Detect corrupted index or missing data files\n if (errorMsg.includes('Not found:') || errorMsg.includes('.lance')) {\n // Attempt to reconnect - index may have been rebuilt\n try {\n await this.initialize();\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized after reconnection');\n }\n return await queryOps.search(this.table, queryVector, limit, query);\n } catch (retryError: unknown) {\n throw new DatabaseError(\n `Index appears corrupted or outdated. Please restart the MCP server or run 'lien reindex' in the project directory.`,\n { originalError: retryError }\n );\n }\n }\n \n throw error;\n }\n }\n \n async scanWithFilter(options: {\n language?: string;\n pattern?: string;\n limit?: number;\n }): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.scanWithFilter(this.table, options);\n }\n \n /**\n * Scan all chunks in the database\n * Fetches total count first, then retrieves all chunks in a single optimized query\n * @param options - Filter options (language, pattern)\n * @returns All matching chunks\n */\n async scanAll(options: {\n language?: string;\n pattern?: string;\n } = {}): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.scanAll(this.table, options);\n }\n \n async querySymbols(options: {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n limit?: number;\n }): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.querySymbols(this.table, options);\n }\n \n async clear(): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database not initialized');\n }\n await maintenanceOps.clear(this.db, this.table, this.tableName, this.dbPath);\n this.table = null;\n }\n \n async deleteByFile(filepath: string): Promise<void> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n await maintenanceOps.deleteByFile(this.table, filepath);\n }\n \n async updateFile(\n filepath: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n ): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database connection not initialized');\n }\n if (!this.table) {\n throw new DatabaseError('Vector database table not initialized');\n }\n this.table = await maintenanceOps.updateFile(\n this.db,\n this.table,\n this.tableName,\n this.dbPath,\n filepath,\n vectors,\n metadatas,\n contents\n );\n }\n \n async checkVersion(): Promise<boolean> {\n const now = Date.now();\n \n // Cache version checks for 1 second to minimize I/O\n if (now - this.lastVersionCheck < 1000) {\n return false;\n }\n \n this.lastVersionCheck = now;\n \n try {\n const version = await readVersionFile(this.dbPath);\n \n if (version > this.currentVersion) {\n this.currentVersion = version;\n return true;\n }\n \n return false;\n } catch (error) {\n // If we can't read version file, don't reconnect\n return false;\n }\n }\n \n async reconnect(): Promise<void> {\n try {\n // Close existing connections to force reload from disk\n this.table = null;\n this.db = null;\n \n // Reinitialize with fresh connection\n await this.initialize();\n } catch (error) {\n throw wrapError(error, 'Failed to reconnect to vector database');\n }\n }\n \n getCurrentVersion(): number {\n return this.currentVersion;\n }\n \n getVersionDate(): string {\n if (this.currentVersion === 0) {\n return 'Unknown';\n }\n return new Date(this.currentVersion).toLocaleString();\n }\n \n async hasData(): Promise<boolean> {\n if (!this.table) {\n return false;\n }\n \n try {\n const count = await this.table.countRows();\n \n if (count === 0) {\n return false;\n }\n \n // Sample a few rows to verify they contain real data\n const sample = await this.table\n .search(Array(EMBEDDING_DIMENSION).fill(0))\n .limit(Math.min(count, 5))\n .toArray();\n \n const hasRealData = (sample as unknown as any[]).some((r: any) => \n r.content && \n r.content.trim().length > 0\n );\n \n return hasRealData;\n } catch {\n // If any error occurs, assume no data\n return false;\n }\n }\n \n static async load(projectRoot: string): Promise<VectorDB> {\n const db = new VectorDB(projectRoot);\n await db.initialize();\n return db;\n }\n}\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { INDEX_FORMAT_VERSION } from '../constants.js';\nimport { GitState } from '../git/tracker.js';\nimport { getPackageVersion } from '../utils/version.js';\n\nconst MANIFEST_FILE = 'manifest.json';\n\n/**\n * Represents a single file in the index manifest\n */\nexport interface FileEntry {\n filepath: string;\n lastModified: number;\n chunkCount: number;\n}\n\n/**\n * Index manifest tracking all indexed files and version information\n */\nexport interface IndexManifest {\n formatVersion: number; // Index format version for compatibility checking\n lienVersion: string; // Lien package version (for reference)\n lastIndexed: number; // Timestamp of last indexing operation\n gitState?: GitState; // Last known git state\n files: Record<string, FileEntry>; // Map of filepath -> FileEntry (stored as object for JSON)\n}\n\n/**\n * Manages the index manifest file, tracking which files are indexed\n * and their metadata for incremental indexing support.\n * \n * The manifest includes version checking to invalidate indices when\n * Lien's indexing format changes (e.g., new chunking algorithm,\n * different embedding model, schema changes).\n */\nexport class ManifestManager {\n private manifestPath: string;\n private indexPath: string;\n \n /**\n * Promise-based lock to prevent race conditions during concurrent updates.\n * Ensures read-modify-write operations are atomic.\n */\n private updateLock = Promise.resolve();\n \n /**\n * Creates a new ManifestManager\n * @param indexPath - Path to the index directory (same as VectorDB path)\n */\n constructor(indexPath: string) {\n this.indexPath = indexPath;\n this.manifestPath = path.join(indexPath, MANIFEST_FILE);\n }\n \n /**\n * Loads the manifest from disk.\n * Returns null if:\n * - Manifest doesn't exist (first run)\n * - Manifest is corrupt\n * - Format version is incompatible (triggers full reindex)\n * \n * @returns Loaded manifest or null\n */\n async load(): Promise<IndexManifest | null> {\n try {\n const content = await fs.readFile(this.manifestPath, 'utf-8');\n const manifest = JSON.parse(content) as IndexManifest;\n \n // VERSION CHECK: Invalidate if format version doesn't match\n if (manifest.formatVersion !== INDEX_FORMAT_VERSION) {\n console.error(\n `[Lien] Index format v${manifest.formatVersion} is incompatible with current v${INDEX_FORMAT_VERSION}`\n );\n console.error(`[Lien] Full reindex required after Lien upgrade`);\n \n // Clear old manifest and return null (triggers full reindex)\n await this.clear();\n return null;\n }\n \n return manifest;\n } catch (error) {\n // File doesn't exist or is invalid - return null for first run\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n \n // Corrupt manifest - log warning and return null\n console.error(`[Lien] Warning: Failed to load manifest: ${error}`);\n return null;\n }\n }\n \n /**\n * Saves the manifest to disk.\n * Always saves with current format and package versions.\n * \n * @param manifest - Manifest to save\n */\n async save(manifest: IndexManifest): Promise<void> {\n try {\n // Ensure index directory exists\n await fs.mkdir(this.indexPath, { recursive: true });\n \n // Always save with current versions\n const manifestToSave: IndexManifest = {\n ...manifest,\n formatVersion: INDEX_FORMAT_VERSION,\n lienVersion: getPackageVersion(),\n lastIndexed: Date.now(),\n };\n \n const content = JSON.stringify(manifestToSave, null, 2);\n await fs.writeFile(this.manifestPath, content, 'utf-8');\n } catch (error) {\n // Don't throw - manifest is best-effort\n console.error(`[Lien] Warning: Failed to save manifest: ${error}`);\n }\n }\n \n /**\n * Adds or updates a file entry in the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param filepath - Path to the file\n * @param entry - File entry metadata\n */\n async updateFile(filepath: string, entry: FileEntry): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n manifest.files[filepath] = entry;\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update manifest for ${filepath}: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Removes a file entry from the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * Note: If the manifest doesn't exist, this is a no-op (not an error).\n * This can happen legitimately after clearing the index or on fresh installs.\n * \n * @param filepath - Path to the file to remove\n */\n async removeFile(filepath: string): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load();\n if (!manifest) {\n // No manifest exists - nothing to remove from (expected in some scenarios)\n return;\n }\n \n delete manifest.files[filepath];\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to remove manifest entry for ${filepath}: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Updates multiple files at once (more efficient than individual updates).\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param entries - Array of file entries to update\n */\n async updateFiles(entries: FileEntry[]): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n \n for (const entry of entries) {\n manifest.files[entry.filepath] = entry;\n }\n \n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update manifest for ${entries.length} files: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Updates the git state in the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param gitState - Current git state\n */\n async updateGitState(gitState: GitState): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n \n manifest.gitState = gitState;\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update git state in manifest: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Gets the list of files currently in the manifest\n * \n * @returns Array of filepaths\n */\n async getIndexedFiles(): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) return [];\n \n return Object.keys(manifest.files);\n }\n \n /**\n * Detects which files have changed based on mtime comparison\n * \n * @param currentFiles - Map of current files with their mtimes\n * @returns Array of filepaths that have changed\n */\n async getChangedFiles(currentFiles: Map<string, number>): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) {\n // No manifest = all files are \"changed\" (need full index)\n return Array.from(currentFiles.keys());\n }\n \n const changedFiles: string[] = [];\n \n for (const [filepath, mtime] of currentFiles) {\n const entry = manifest.files[filepath];\n \n if (!entry) {\n // New file\n changedFiles.push(filepath);\n } else if (entry.lastModified < mtime) {\n // File modified since last index\n changedFiles.push(filepath);\n }\n }\n \n return changedFiles;\n }\n \n /**\n * Gets files that are in the manifest but not in the current file list\n * (i.e., deleted files)\n * \n * @param currentFiles - Set of current file paths\n * @returns Array of deleted file paths\n */\n async getDeletedFiles(currentFiles: Set<string>): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) return [];\n \n const deletedFiles: string[] = [];\n \n for (const filepath of Object.keys(manifest.files)) {\n if (!currentFiles.has(filepath)) {\n deletedFiles.push(filepath);\n }\n }\n \n return deletedFiles;\n }\n \n /**\n * Clears the manifest file\n */\n async clear(): Promise<void> {\n try {\n await fs.unlink(this.manifestPath);\n } catch (error) {\n // Ignore error if file doesn't exist\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n console.error(`[Lien] Warning: Failed to clear manifest: ${error}`);\n }\n }\n }\n \n /**\n * Creates an empty manifest with current version information\n * \n * @returns Empty manifest\n */\n private createEmpty(): IndexManifest {\n return {\n formatVersion: INDEX_FORMAT_VERSION,\n lienVersion: getPackageVersion(),\n lastIndexed: Date.now(),\n files: {},\n };\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport {\n isGitRepo,\n getCurrentBranch,\n getCurrentCommit,\n getChangedFiles,\n getChangedFilesBetweenCommits,\n} from './utils.js';\n\nexport interface GitState {\n branch: string;\n commit: string;\n timestamp: number;\n}\n\n/**\n * Tracks git state (branch and commit) and detects changes.\n * Persists state to disk to survive server restarts.\n */\nexport class GitStateTracker {\n private stateFile: string;\n private rootDir: string;\n private currentState: GitState | null = null;\n \n constructor(rootDir: string, indexPath: string) {\n this.rootDir = rootDir;\n this.stateFile = path.join(indexPath, '.git-state.json');\n }\n \n /**\n * Loads the last known git state from disk.\n * Returns null if no state file exists (first run).\n */\n private async loadState(): Promise<GitState | null> {\n try {\n const content = await fs.readFile(this.stateFile, 'utf-8');\n return JSON.parse(content);\n } catch {\n // File doesn't exist or is invalid - this is fine for first run\n return null;\n }\n }\n \n /**\n * Saves the current git state to disk.\n */\n private async saveState(state: GitState): Promise<void> {\n try {\n const content = JSON.stringify(state, null, 2);\n await fs.writeFile(this.stateFile, content, 'utf-8');\n } catch (error) {\n // Log but don't throw - state persistence is best-effort\n console.error(`[Lien] Warning: Failed to save git state: ${error}`);\n }\n }\n \n /**\n * Gets the current git state from the repository.\n * \n * @returns Current git state\n * @throws Error if git commands fail\n */\n private async getCurrentGitState(): Promise<GitState> {\n const branch = await getCurrentBranch(this.rootDir);\n const commit = await getCurrentCommit(this.rootDir);\n \n return {\n branch,\n commit,\n timestamp: Date.now(),\n };\n }\n \n /**\n * Initializes the tracker by loading saved state and checking current state.\n * Should be called once when MCP server starts.\n * \n * @returns Array of changed files if state changed, null if no changes or first run\n */\n async initialize(): Promise<string[] | null> {\n // Check if this is a git repo\n const isRepo = await isGitRepo(this.rootDir);\n if (!isRepo) {\n return null;\n }\n \n try {\n // Get current state\n this.currentState = await this.getCurrentGitState();\n \n // Load previous state\n const previousState = await this.loadState();\n \n if (!previousState) {\n // First run - save current state\n await this.saveState(this.currentState);\n return null;\n }\n \n // Check if state changed\n const branchChanged = previousState.branch !== this.currentState.branch;\n const commitChanged = previousState.commit !== this.currentState.commit;\n \n if (!branchChanged && !commitChanged) {\n // No changes\n return null;\n }\n \n // State changed - get list of changed files\n let changedFiles: string[] = [];\n \n if (branchChanged) {\n // Branch changed - compare current branch with previous branch\n try {\n changedFiles = await getChangedFiles(\n this.rootDir,\n previousState.branch,\n this.currentState.branch\n );\n } catch (error) {\n // If branches diverged too much or don't exist, fall back to commit diff\n console.error(`[Lien] Branch diff failed, using commit diff: ${error}`);\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n previousState.commit,\n this.currentState.commit\n );\n }\n } else if (commitChanged) {\n // Same branch, different commit\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n previousState.commit,\n this.currentState.commit\n );\n }\n \n // Save new state\n await this.saveState(this.currentState);\n \n return changedFiles;\n } catch (error) {\n console.error(`[Lien] Failed to initialize git tracker: ${error}`);\n return null;\n }\n }\n \n /**\n * Checks for git state changes since last check.\n * This is called periodically by the MCP server.\n * \n * @returns Array of changed files if state changed, null if no changes\n */\n async detectChanges(): Promise<string[] | null> {\n // Check if this is a git repo\n const isRepo = await isGitRepo(this.rootDir);\n if (!isRepo) {\n return null;\n }\n \n try {\n // Get current state\n const newState = await this.getCurrentGitState();\n \n // If we don't have a previous state, just save current and return\n if (!this.currentState) {\n this.currentState = newState;\n await this.saveState(newState);\n return null;\n }\n \n // Check if state changed\n const branchChanged = this.currentState.branch !== newState.branch;\n const commitChanged = this.currentState.commit !== newState.commit;\n \n if (!branchChanged && !commitChanged) {\n // No changes\n return null;\n }\n \n // State changed - get list of changed files\n let changedFiles: string[] = [];\n \n if (branchChanged) {\n // Branch changed\n try {\n changedFiles = await getChangedFiles(\n this.rootDir,\n this.currentState.branch,\n newState.branch\n );\n } catch (error) {\n // Fall back to commit diff\n console.error(`[Lien] Branch diff failed, using commit diff: ${error}`);\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n this.currentState.commit,\n newState.commit\n );\n }\n } else if (commitChanged) {\n // Same branch, different commit\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n this.currentState.commit,\n newState.commit\n );\n }\n \n // Update current state\n this.currentState = newState;\n await this.saveState(newState);\n \n return changedFiles;\n } catch (error) {\n console.error(`[Lien] Failed to detect git changes: ${error}`);\n return null;\n }\n }\n \n /**\n * Gets the current git state.\n * Useful for status display.\n */\n getState(): GitState | null {\n return this.currentState;\n }\n \n /**\n * Manually updates the saved state.\n * Useful after manual reindexing to sync state.\n */\n async updateState(): Promise<void> {\n try {\n this.currentState = await this.getCurrentGitState();\n await this.saveState(this.currentState);\n } catch (error) {\n console.error(`[Lien] Failed to update git state: ${error}`);\n }\n }\n}\n\n","/**\n * Result type for explicit error handling.\n * \n * Provides a type-safe alternative to throwing exceptions, making error\n * handling explicit in function signatures.\n * \n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n * \n * const result = divide(10, 2);\n * if (isOk(result)) {\n * console.log(result.value); // 5\n * } else {\n * console.error(result.error);\n * }\n * ```\n */\n\n/**\n * Result type representing either success (Ok) or failure (Err)\n */\nexport type Result<T, E = Error> = \n | { ok: true; value: T }\n | { ok: false; error: E };\n\n/**\n * Creates a successful Result containing a value\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/**\n * Creates a failed Result containing an error\n */\nexport function Err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n\n/**\n * Type guard to check if a Result is Ok\n */\nexport function isOk<T, E>(result: Result<T, E>): result is { ok: true; value: T } {\n return result.ok;\n}\n\n/**\n * Type guard to check if a Result is Err\n */\nexport function isErr<T, E>(result: Result<T, E>): result is { ok: false; error: E } {\n return !result.ok;\n}\n\n/**\n * Unwraps a Result, throwing if it's an error\n * @throws {E} The error if Result is Err\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n if (isOk(result)) {\n return result.value;\n }\n throw result.error;\n}\n\n/**\n * Unwraps a Result or returns a default value if it's an error\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n if (isOk(result)) {\n return result.value;\n }\n return defaultValue;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { chunkFile } from './chunker.js';\nimport { EmbeddingService } from '../embeddings/types.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { LienConfig, LegacyLienConfig, isModernConfig, isLegacyConfig } from '../config/schema.js';\nimport { ManifestManager } from './manifest.js';\nimport { EMBEDDING_MICRO_BATCH_SIZE } from '../constants.js';\nimport { CodeChunk } from './types.js';\nimport { Result, Ok, Err, isOk } from '../utils/result.js';\n\n/**\n * Normalize a file path to a consistent relative format.\n * This ensures paths from different sources (git diff, scanner, etc.)\n * are stored and queried consistently in the index.\n * \n * @param filepath - Absolute or relative file path\n * @param rootDir - Workspace root directory (defaults to cwd)\n * @returns Relative path from rootDir\n */\nexport function normalizeToRelativePath(filepath: string, rootDir?: string): string {\n // Normalize root and strip trailing slash to ensure consistent comparison\n const root = (rootDir || process.cwd()).replace(/\\\\/g, '/').replace(/\\/$/, '');\n const normalized = filepath.replace(/\\\\/g, '/');\n \n // If already relative, return as-is\n if (!path.isAbsolute(filepath)) {\n return normalized;\n }\n \n // Convert absolute to relative\n if (normalized.startsWith(root + '/')) {\n return normalized.slice(root.length + 1);\n }\n if (normalized.startsWith(root)) {\n return normalized.slice(root.length);\n }\n \n // Fallback: use path.relative\n return path.relative(root, filepath).replace(/\\\\/g, '/');\n}\n\nexport interface IncrementalIndexOptions {\n verbose?: boolean;\n}\n\n/**\n * Result of processing a file's content into chunks and embeddings.\n */\ninterface ProcessFileResult {\n chunkCount: number;\n vectors: Float32Array[];\n chunks: CodeChunk[];\n texts: string[];\n}\n\n/**\n * Result of processing a single file for incremental indexing.\n */\ninterface FileProcessResult {\n filepath: string;\n result: ProcessFileResult | null; // null for empty files\n mtime: number;\n}\n\n/**\n * Shared helper that processes file content into chunks and embeddings.\n * This is the core logic shared between indexSingleFile and indexMultipleFiles.\n * \n * Returns null for empty files (0 chunks), which callers should handle appropriately.\n * \n * @param filepath - Path to the file being processed\n * @param content - File content\n * @param embeddings - Embeddings service\n * @param config - Lien configuration\n * @param verbose - Whether to log verbose output\n * @returns ProcessFileResult for non-empty files, null for empty files\n */\nasync function processFileContent(\n filepath: string,\n content: string,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n verbose: boolean\n): Promise<ProcessFileResult | null> {\n // Get chunk settings (support both v0.3.0 and legacy v0.2.0 configs)\n const chunkSize = isModernConfig(config)\n ? config.core.chunkSize\n : (isLegacyConfig(config) ? config.indexing.chunkSize : 75);\n const chunkOverlap = isModernConfig(config)\n ? config.core.chunkOverlap\n : (isLegacyConfig(config) ? config.indexing.chunkOverlap : 10);\n const useAST = isModernConfig(config)\n ? config.chunking.useAST\n : true;\n const astFallback = isModernConfig(config)\n ? config.chunking.astFallback\n : 'line-based';\n \n // Chunk the file\n const chunks = chunkFile(filepath, content, {\n chunkSize,\n chunkOverlap,\n useAST,\n astFallback,\n });\n \n if (chunks.length === 0) {\n // Empty file - return null so caller can handle appropriately\n if (verbose) {\n console.error(`[Lien] Empty file: ${filepath}`);\n }\n return null;\n }\n \n // Generate embeddings for all chunks\n // Use micro-batching to prevent event loop blocking\n const texts = chunks.map(c => c.content);\n const vectors: Float32Array[] = [];\n \n for (let j = 0; j < texts.length; j += EMBEDDING_MICRO_BATCH_SIZE) {\n const microBatch = texts.slice(j, Math.min(j + EMBEDDING_MICRO_BATCH_SIZE, texts.length));\n const microResults = await embeddings.embedBatch(microBatch);\n vectors.push(...microResults);\n \n // Yield to event loop for responsiveness\n if (texts.length > EMBEDDING_MICRO_BATCH_SIZE) {\n await new Promise(resolve => setImmediate(resolve));\n }\n }\n \n return {\n chunkCount: chunks.length,\n vectors,\n chunks,\n texts,\n };\n}\n\n/**\n * Indexes a single file incrementally by updating its chunks in the vector database.\n * This is the core function for incremental reindexing - it handles file changes,\n * deletions, and additions.\n * \n * @param filepath - Absolute path to the file to index\n * @param vectorDB - Initialized VectorDB instance\n * @param embeddings - Initialized embeddings service\n * @param config - Lien configuration\n * @param options - Optional settings\n */\nexport async function indexSingleFile(\n filepath: string,\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IncrementalIndexOptions = {}\n): Promise<void> {\n const { verbose } = options;\n \n // Normalize to relative path for consistent storage and queries\n // This ensures paths from git diff (absolute) match paths from scanner (relative)\n const normalizedPath = normalizeToRelativePath(filepath);\n \n try {\n // Check if file exists (use original filepath for filesystem operations)\n try {\n await fs.access(filepath);\n } catch {\n // File doesn't exist - delete from index and manifest using normalized path\n if (verbose) {\n console.error(`[Lien] File deleted: ${normalizedPath}`);\n }\n await vectorDB.deleteByFile(normalizedPath);\n \n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(normalizedPath);\n return;\n }\n \n // Read file content\n const content = await fs.readFile(filepath, 'utf-8');\n \n // Process file content (chunking + embeddings) - use normalized path for storage\n const result = await processFileContent(normalizedPath, content, embeddings, config, verbose || false);\n \n // Get actual file mtime for manifest\n const stats = await fs.stat(filepath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n \n if (result === null) {\n // Empty file - remove from vector DB but keep in manifest with chunkCount: 0\n await vectorDB.deleteByFile(normalizedPath);\n await manifest.updateFile(normalizedPath, {\n filepath: normalizedPath,\n lastModified: stats.mtimeMs,\n chunkCount: 0,\n });\n return;\n }\n \n // Non-empty file - update in database (atomic: delete old + insert new)\n await vectorDB.updateFile(\n normalizedPath,\n result.vectors,\n result.chunks.map(c => c.metadata),\n result.texts\n );\n \n // Update manifest after successful indexing\n await manifest.updateFile(normalizedPath, {\n filepath: normalizedPath,\n lastModified: stats.mtimeMs,\n chunkCount: result.chunkCount,\n });\n \n if (verbose) {\n console.error(`[Lien] ✓ Updated ${normalizedPath} (${result.chunkCount} chunks)`);\n }\n } catch (error) {\n // Log error but don't throw - we want to continue with other files\n console.error(`[Lien] ⚠️ Failed to index ${normalizedPath}: ${error}`);\n }\n}\n\n/**\n * Process a single file, returning a Result type.\n * This helper makes error handling explicit and testable.\n * \n * @param filepath - Original filepath (may be absolute)\n * @param normalizedPath - Normalized relative path for storage\n */\nasync function processSingleFileForIndexing(\n filepath: string,\n normalizedPath: string,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n verbose: boolean\n): Promise<Result<FileProcessResult, string>> {\n try {\n // Read file stats and content using original path (for filesystem access)\n const stats = await fs.stat(filepath);\n const content = await fs.readFile(filepath, 'utf-8');\n \n // Process content using normalized path (for storage)\n const result = await processFileContent(normalizedPath, content, embeddings, config, verbose);\n \n return Ok({\n filepath: normalizedPath, // Store normalized path\n result,\n mtime: stats.mtimeMs,\n });\n } catch (error) {\n return Err(`Failed to process ${normalizedPath}: ${error}`);\n }\n}\n\n/**\n * Indexes multiple files incrementally.\n * Processes files sequentially for simplicity and reliability.\n * \n * Uses Result type for explicit error handling, making it easier to test\n * and reason about failure modes.\n * \n * Note: This function counts both successfully indexed files AND successfully\n * handled deletions (files that don't exist but were removed from the index).\n * \n * @param filepaths - Array of absolute file paths to index\n * @param vectorDB - Initialized VectorDB instance\n * @param embeddings - Initialized embeddings service\n * @param config - Lien configuration\n * @param options - Optional settings\n * @returns Number of successfully processed files (indexed or deleted)\n */\nexport async function indexMultipleFiles(\n filepaths: string[],\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IncrementalIndexOptions = {}\n): Promise<number> {\n const { verbose } = options;\n let processedCount = 0;\n \n // Batch manifest updates for performance\n const manifestEntries: Array<{ filepath: string; chunkCount: number; mtime: number }> = [];\n \n // Process each file sequentially (simple and reliable)\n for (const filepath of filepaths) {\n // Normalize to relative path for consistent storage and queries\n // This ensures paths from git diff (absolute) match paths from scanner (relative)\n const normalizedPath = normalizeToRelativePath(filepath);\n \n const result = await processSingleFileForIndexing(filepath, normalizedPath, embeddings, config, verbose || false);\n \n if (isOk(result)) {\n const { filepath: storedPath, result: processResult, mtime } = result.value;\n \n if (processResult === null) {\n // Empty file - remove from vector DB but keep in manifest with chunkCount: 0\n try {\n await vectorDB.deleteByFile(storedPath);\n } catch (error) {\n // Ignore errors if file wasn't in index\n }\n \n // Update manifest immediately for empty files (not batched)\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFile(storedPath, {\n filepath: storedPath,\n lastModified: mtime,\n chunkCount: 0,\n });\n \n processedCount++;\n continue;\n }\n \n // Non-empty file - delete old chunks if they exist\n try {\n await vectorDB.deleteByFile(storedPath);\n } catch (error) {\n // Ignore - file might not be in index yet\n }\n \n // Insert new chunks\n await vectorDB.insertBatch(\n processResult.vectors,\n processResult.chunks.map(c => c.metadata),\n processResult.texts\n );\n \n // Queue manifest update (batch at end)\n manifestEntries.push({\n filepath: storedPath,\n chunkCount: processResult.chunkCount,\n mtime,\n });\n \n if (verbose) {\n console.error(`[Lien] ✓ Updated ${storedPath} (${processResult.chunkCount} chunks)`);\n }\n \n processedCount++;\n } else {\n // File doesn't exist or couldn't be read - handle deletion\n if (verbose) {\n console.error(`[Lien] ${result.error}`);\n }\n \n try {\n await vectorDB.deleteByFile(normalizedPath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(normalizedPath);\n } catch (error) {\n // Ignore errors if file wasn't in index\n if (verbose) {\n console.error(`[Lien] Note: ${normalizedPath} not in index`);\n }\n }\n \n // Count as processed regardless of deletion success/failure\n processedCount++;\n }\n }\n \n // Batch update manifest at the end (much faster than updating after each file)\n if (manifestEntries.length > 0) {\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFiles(\n manifestEntries.map(entry => ({\n filepath: entry.filepath,\n lastModified: entry.mtime, // Use actual file mtime for accurate change detection\n chunkCount: entry.chunkCount,\n }))\n );\n }\n \n return processedCount;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { ManifestManager, IndexManifest } from './manifest.js';\nimport { scanCodebase, scanCodebaseWithFrameworks } from './scanner.js';\nimport { LienConfig, LegacyLienConfig, isModernConfig, isLegacyConfig } from '../config/schema.js';\nimport { GitStateTracker } from '../git/tracker.js';\nimport { isGitAvailable, isGitRepo, getChangedFiles } from '../git/utils.js';\nimport { normalizeToRelativePath } from './incremental.js';\n\n/**\n * Result of change detection, categorized by type of change\n */\nexport interface ChangeDetectionResult {\n added: string[]; // New files not in previous index\n modified: string[]; // Existing files that have been modified\n deleted: string[]; // Files that were indexed but no longer exist\n reason: 'mtime' | 'full' | 'git-state-changed'; // How changes were detected\n}\n\n/**\n * Check if git state has changed (branch switch, new commits).\n */\nasync function hasGitStateChanged(\n rootDir: string,\n dbPath: string,\n savedGitState: IndexManifest['gitState']\n): Promise<{ changed: boolean; currentState?: ReturnType<GitStateTracker['getState']> }> {\n if (!savedGitState) return { changed: false };\n\n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n if (!gitAvailable || !isRepo) return { changed: false };\n\n const gitTracker = new GitStateTracker(rootDir, dbPath);\n await gitTracker.initialize();\n const currentState = gitTracker.getState();\n\n if (!currentState) return { changed: false };\n\n const changed = currentState.branch !== savedGitState.branch ||\n currentState.commit !== savedGitState.commit;\n\n return { changed, currentState };\n}\n\n/**\n * Categorize files from git diff into added, modified, deleted.\n */\nfunction categorizeChangedFiles(\n changedFilesPaths: string[],\n currentFileSet: Set<string>,\n normalizedManifestFiles: Set<string>,\n allFiles: string[]\n): { added: string[]; modified: string[]; deleted: string[] } {\n const changedFilesSet = new Set(changedFilesPaths);\n const added: string[] = [];\n const modified: string[] = [];\n const deleted: string[] = [];\n\n // Categorize files from git diff\n for (const filepath of changedFilesPaths) {\n if (currentFileSet.has(filepath)) {\n if (normalizedManifestFiles.has(filepath)) {\n modified.push(filepath);\n } else {\n added.push(filepath);\n }\n }\n }\n\n // Find truly new files (not in git diff, but not in old manifest)\n for (const filepath of allFiles) {\n if (!normalizedManifestFiles.has(filepath) && !changedFilesSet.has(filepath)) {\n added.push(filepath);\n }\n }\n\n // Find deleted files (in old manifest but not in current)\n for (const normalizedPath of normalizedManifestFiles) {\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n\n return { added, modified, deleted };\n}\n\n/**\n * Build normalized set of manifest file paths for comparison.\n */\nfunction normalizeManifestPaths(\n manifestFiles: IndexManifest['files'],\n rootDir: string\n): Set<string> {\n const normalized = new Set<string>();\n for (const filepath of Object.keys(manifestFiles)) {\n normalized.add(normalizeToRelativePath(filepath, rootDir));\n }\n return normalized;\n}\n\n/**\n * Detect changes using git diff between commits.\n */\nasync function detectGitBasedChanges(\n rootDir: string,\n savedManifest: IndexManifest,\n currentCommit: string,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const changedFilesAbsolute = await getChangedFiles(\n rootDir,\n savedManifest.gitState!.commit,\n currentCommit\n );\n const changedFilesPaths = changedFilesAbsolute.map(fp => normalizeToRelativePath(fp, rootDir));\n\n const allFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(allFiles);\n const normalizedManifestFiles = normalizeManifestPaths(savedManifest.files, rootDir);\n\n const { added, modified, deleted } = categorizeChangedFiles(\n changedFilesPaths,\n currentFileSet,\n normalizedManifestFiles,\n allFiles\n );\n\n return { added, modified, deleted, reason: 'git-state-changed' };\n}\n\n/**\n * Fall back to full reindex when git diff fails.\n */\nasync function fallbackToFullReindex(\n rootDir: string,\n savedManifest: IndexManifest,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const allFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(allFiles);\n\n const deleted: string[] = [];\n for (const filepath of Object.keys(savedManifest.files)) {\n const normalizedPath = normalizeToRelativePath(filepath, rootDir);\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n\n return { added: allFiles, modified: [], deleted, reason: 'git-state-changed' };\n}\n\n/**\n * Detects which files have changed since last indexing.\n * Uses git state detection to handle branch switches, then falls back to mtime.\n */\nexport async function detectChanges(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const manifest = new ManifestManager(vectorDB.dbPath);\n const savedManifest = await manifest.load();\n\n // No manifest = first run = full index\n if (!savedManifest) {\n const allFiles = await getAllFiles(rootDir, config);\n return { added: allFiles, modified: [], deleted: [], reason: 'full' };\n }\n\n // Check if git state has changed\n const gitCheck = await hasGitStateChanged(rootDir, vectorDB.dbPath, savedManifest.gitState);\n\n if (gitCheck.changed && gitCheck.currentState) {\n try {\n return await detectGitBasedChanges(rootDir, savedManifest, gitCheck.currentState.commit, config);\n } catch (error) {\n console.warn(`[Lien] Git diff failed, falling back to full reindex: ${error}`);\n return await fallbackToFullReindex(rootDir, savedManifest, config);\n }\n }\n\n // Use mtime-based detection for file-level changes\n return await mtimeBasedDetection(rootDir, savedManifest, config);\n}\n\n/**\n * Gets all files in the project based on configuration.\n * Always returns relative paths for consistent comparison with manifest and git diff.\n */\nasync function getAllFiles(\n rootDir: string,\n config: LienConfig | LegacyLienConfig\n): Promise<string[]> {\n let files: string[];\n \n if (isModernConfig(config) && config.frameworks.length > 0) {\n files = await scanCodebaseWithFrameworks(rootDir, config);\n } else if (isLegacyConfig(config)) {\n files = await scanCodebase({\n rootDir,\n includePatterns: config.indexing.include,\n excludePatterns: config.indexing.exclude,\n });\n } else {\n files = await scanCodebase({\n rootDir,\n includePatterns: [],\n excludePatterns: [],\n });\n }\n \n // Normalize all paths to relative for consistent comparison\n return files.map(fp => normalizeToRelativePath(fp, rootDir));\n}\n\n/**\n * Detects changes by comparing file modification times\n */\nasync function mtimeBasedDetection(\n rootDir: string,\n savedManifest: IndexManifest,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const added: string[] = [];\n const modified: string[] = [];\n const deleted: string[] = [];\n \n // Get all current files (already normalized to relative paths by getAllFiles)\n const currentFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(currentFiles);\n \n // Build a normalized map of manifest files for comparison\n // This handles cases where manifest has absolute paths (from tests or legacy data)\n const normalizedManifestFiles = new Map<string, typeof savedManifest.files[string]>();\n for (const [filepath, entry] of Object.entries(savedManifest.files)) {\n const normalizedPath = normalizeToRelativePath(filepath, rootDir);\n normalizedManifestFiles.set(normalizedPath, entry);\n }\n \n // Get mtimes for all current files\n // Note: need to construct absolute path for fs.stat since currentFiles are relative\n const fileStats = new Map<string, number>();\n \n for (const filepath of currentFiles) {\n try {\n // Construct absolute path for filesystem access (use path.join for cross-platform)\n const absolutePath = path.isAbsolute(filepath) ? filepath : path.join(rootDir, filepath);\n const stats = await fs.stat(absolutePath);\n fileStats.set(filepath, stats.mtimeMs);\n } catch {\n // Ignore files we can't stat\n continue;\n }\n }\n \n // Check for new and modified files\n for (const [filepath, mtime] of fileStats) {\n const entry = normalizedManifestFiles.get(filepath);\n \n if (!entry) {\n // New file\n added.push(filepath);\n } else if (entry.lastModified < mtime) {\n // File modified since last index\n modified.push(filepath);\n }\n }\n \n // Check for deleted files (use normalized manifest paths)\n for (const normalizedPath of normalizedManifestFiles.keys()) {\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n \n return {\n added,\n modified,\n deleted,\n reason: 'mtime',\n };\n}\n\n","/**\n * Witty loading messages to keep users entertained during long operations.\n * Inspired by tools like npm, yarn, and other personality-driven CLIs.\n */\n\nconst INDEXING_MESSAGES = [\n 'Teaching AI to read your spaghetti code...',\n 'Convincing the LLM that your variable names make sense...',\n 'Indexing your TODO comments (so many TODOs)...',\n 'Building semantic links faster than you can say \"grep\"...',\n 'Making your codebase searchable (the good, the bad, and the ugly)...',\n 'Chunking code like a boss...',\n \"Feeding your code to the neural network (it's hungry)...\",\n \"Creating embeddings (it's like compression, but fancier)...\",\n 'Teaching machines to understand your midnight commits...',\n 'Vectorizing your technical debt...',\n \"Indexing... because Ctrl+F wasn't cutting it anymore...\",\n 'Making semantic connections (unlike your last refactor)...',\n 'Processing files faster than your CI pipeline...',\n 'Embedding wisdom from your comments (all 3 of them)...',\n 'Analyzing code semantics (yes, even that one function)...',\n 'Building search index (now with 100% more AI)...',\n \"Crunching vectors like it's nobody's business...\",\n 'Linking code fragments across the spacetime continuum...',\n 'Teaching transformers about your coding style...',\n 'Preparing for semantic search domination...',\n 'Indexing your genius (and that hacky workaround from 2019)...',\n \"Making your codebase AI-readable (you're welcome, future you)...\",\n 'Converting code to math (engineers love this trick)...',\n \"Building the neural net's mental model of your app...\",\n 'Chunking files like a lumberjack, but for code...',\n];\n\nconst EMBEDDING_MESSAGES = [\n 'Generating embeddings (math is happening)...',\n 'Teaching transformers about your forEach loops...',\n 'Converting code to 384-dimensional space (wild, right?)...',\n 'Running the neural network (the Matrix, but for code)...',\n 'Creating semantic vectors (fancy word for AI magic)...',\n 'Embedding your code into hyperspace...',\n 'Teaching the model what \"clean code\" means in your codebase...',\n 'Generating vectors faster than you can say \"AI\"...',\n 'Making math from your methods...',\n 'Transforming code into numbers (the AI way)...',\n 'Processing with transformers.js (yes, it runs locally!)...',\n \"Embedding semantics (your code's hidden meaning)...\",\n 'Vectorizing variables (alliteration achieved)...',\n 'Teaching AI the difference between foo and bar...',\n 'Creating embeddings (384 dimensions of awesome)...',\n];\n\nconst MODEL_LOADING_MESSAGES = [\n 'Waking up the neural network...',\n 'Loading transformer model (patience, young padawan)...',\n 'Downloading AI brain (first run only, promise!)...',\n 'Initializing the semantic search engine...',\n 'Booting up the language model (coffee break recommended)...',\n 'Loading 100MB of pure AI goodness...',\n 'Preparing the transformer for action...',\n 'Model loading (this is why we run locally)...',\n 'Spinning up the embedding generator...',\n 'Getting the AI ready for your codebase...',\n];\n\nlet currentIndexingIndex = 0;\nlet currentEmbeddingIndex = 0;\nlet currentModelIndex = 0;\n\n/**\n * Get the next witty message for the indexing process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getIndexingMessage(): string {\n const message = INDEXING_MESSAGES[currentIndexingIndex % INDEXING_MESSAGES.length];\n currentIndexingIndex++;\n return message;\n}\n\n/**\n * Get the next witty message for the embedding generation process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getEmbeddingMessage(): string {\n const message = EMBEDDING_MESSAGES[currentEmbeddingIndex % EMBEDDING_MESSAGES.length];\n currentEmbeddingIndex++;\n return message;\n}\n\n/**\n * Get the next witty message for the model loading process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getModelLoadingMessage(): string {\n const message = MODEL_LOADING_MESSAGES[currentModelIndex % MODEL_LOADING_MESSAGES.length];\n currentModelIndex++;\n return message;\n}\n\n/**\n * Reset all message counters (useful for testing)\n */\nexport function resetMessageCounters(): void {\n currentIndexingIndex = 0;\n currentEmbeddingIndex = 0;\n currentModelIndex = 0;\n}\n\n","import type { Ora } from 'ora';\nimport { getIndexingMessage } from '../utils/loading-messages.js';\n\n/**\n * Manages progress tracking and spinner updates during indexing.\n * \n * Handles:\n * - Periodic progress updates (files processed count)\n * - Message rotation (witty messages every 8 seconds)\n * - Clean separation from business logic\n * \n * @example\n * ```typescript\n * const tracker = new IndexingProgressTracker(1000, spinner);\n * tracker.start();\n * \n * // ... process files ...\n * tracker.incrementFiles();\n * \n * tracker.setMessage('Generating embeddings...');\n * tracker.stop();\n * ```\n */\nexport class IndexingProgressTracker {\n private processedFiles = 0;\n private totalFiles: number;\n private wittyMessage: string;\n private spinner: Ora;\n private updateInterval?: NodeJS.Timeout;\n \n // Configuration constants\n private static readonly SPINNER_UPDATE_INTERVAL_MS = 200; // How often to update spinner\n private static readonly MESSAGE_ROTATION_INTERVAL_MS = 8000; // How often to rotate message\n \n constructor(totalFiles: number, spinner: Ora) {\n this.totalFiles = totalFiles;\n this.spinner = spinner;\n this.wittyMessage = getIndexingMessage();\n }\n \n /**\n * Start the progress tracker.\n * Sets up periodic updates for spinner and message rotation.\n * \n * Safe to call multiple times - will not create duplicate intervals.\n */\n start(): void {\n // Prevent creating multiple intervals (resource leak)\n if (this.updateInterval) {\n return;\n }\n \n const MESSAGE_ROTATION_TICKS = Math.floor(\n IndexingProgressTracker.MESSAGE_ROTATION_INTERVAL_MS / \n IndexingProgressTracker.SPINNER_UPDATE_INTERVAL_MS\n );\n \n let spinnerTick = 0;\n this.updateInterval = setInterval(() => {\n // Rotate witty message periodically\n spinnerTick++;\n if (spinnerTick >= MESSAGE_ROTATION_TICKS) {\n this.wittyMessage = getIndexingMessage();\n spinnerTick = 0; // Reset counter to prevent unbounded growth\n }\n \n // Update spinner text with current progress\n this.spinner.text = `${this.processedFiles}/${this.totalFiles} files | ${this.wittyMessage}`;\n }, IndexingProgressTracker.SPINNER_UPDATE_INTERVAL_MS);\n }\n \n /**\n * Increment the count of processed files.\n * \n * Safe for async operations in Node.js's single-threaded event loop.\n * Note: Not thread-safe for true concurrent operations (e.g., worker threads).\n */\n incrementFiles(): void {\n this.processedFiles++;\n }\n \n /**\n * Set a custom message (e.g., for special operations like embedding generation).\n * The message will be displayed until the next automatic rotation.\n */\n setMessage(message: string): void {\n this.wittyMessage = message;\n }\n \n /**\n * Stop the progress tracker and clean up intervals.\n * Must be called when indexing completes or fails.\n */\n stop(): void {\n if (this.updateInterval) {\n clearInterval(this.updateInterval);\n this.updateInterval = undefined;\n }\n }\n \n /**\n * Get the current count of processed files.\n */\n getProcessedCount(): number {\n return this.processedFiles;\n }\n \n /**\n * Get the total number of files to process.\n */\n getTotalFiles(): number {\n return this.totalFiles;\n }\n \n /**\n * Get the current message being displayed.\n */\n getCurrentMessage(): string {\n return this.wittyMessage;\n }\n}\n\n","import fs from 'fs/promises';\nimport ora, { type Ora } from 'ora';\nimport chalk from 'chalk';\nimport pLimit from 'p-limit';\nimport { scanCodebase, scanCodebaseWithFrameworks } from './scanner.js';\nimport { chunkFile } from './chunker.js';\nimport { LocalEmbeddings } from '../embeddings/local.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { configService } from '../config/service.js';\nimport { CodeChunk } from './types.js';\nimport { writeVersionFile } from '../vectordb/version.js';\nimport { isLegacyConfig, isModernConfig, type LienConfig, type LegacyLienConfig } from '../config/schema.js';\nimport { ManifestManager } from './manifest.js';\nimport { detectChanges } from './change-detector.js';\nimport { indexMultipleFiles } from './incremental.js';\nimport { getIndexingMessage, getEmbeddingMessage, getModelLoadingMessage } from '../utils/loading-messages.js';\nimport { EMBEDDING_MICRO_BATCH_SIZE } from '../constants.js';\nimport { IndexingProgressTracker } from './progress-tracker.js';\nimport type { EmbeddingService } from '../embeddings/types.js';\n\nexport interface IndexingOptions {\n rootDir?: string;\n verbose?: boolean;\n force?: boolean; // Force full reindex, skip incremental\n}\n\ninterface ChunkWithContent {\n chunk: CodeChunk;\n content: string;\n}\n\n/** Extracted config values with defaults for indexing */\ninterface IndexingConfig {\n concurrency: number;\n embeddingBatchSize: number;\n chunkSize: number;\n chunkOverlap: number;\n useAST: boolean;\n astFallback: 'line-based' | 'error';\n}\n\n/** Extract indexing config values with defaults */\nfunction getIndexingConfig(config: LienConfig | LegacyLienConfig): IndexingConfig {\n if (isModernConfig(config)) {\n return {\n concurrency: config.core.concurrency,\n embeddingBatchSize: config.core.embeddingBatchSize,\n chunkSize: config.core.chunkSize,\n chunkOverlap: config.core.chunkOverlap,\n useAST: config.chunking.useAST,\n astFallback: config.chunking.astFallback,\n };\n }\n // Legacy defaults\n return {\n concurrency: 4,\n embeddingBatchSize: 50,\n chunkSize: 75,\n chunkOverlap: 10,\n useAST: true,\n astFallback: 'line-based',\n };\n}\n\n/** Scan files based on config type */\nasync function scanFilesToIndex(\n rootDir: string,\n config: LienConfig | LegacyLienConfig\n): Promise<string[]> {\n if (isModernConfig(config) && config.frameworks.length > 0) {\n return scanCodebaseWithFrameworks(rootDir, config);\n }\n if (isLegacyConfig(config)) {\n return scanCodebase({\n rootDir,\n includePatterns: config.indexing.include,\n excludePatterns: config.indexing.exclude,\n });\n }\n return scanCodebase({ rootDir, includePatterns: [], excludePatterns: [] });\n}\n\n/** Process embeddings in micro-batches to prevent event loop blocking */\nasync function processEmbeddingMicroBatches(\n texts: string[],\n embeddings: EmbeddingService\n): Promise<Float32Array[]> {\n const results: Float32Array[] = [];\n for (let j = 0; j < texts.length; j += EMBEDDING_MICRO_BATCH_SIZE) {\n const microBatch = texts.slice(j, Math.min(j + EMBEDDING_MICRO_BATCH_SIZE, texts.length));\n const microResults = await embeddings.embedBatch(microBatch);\n results.push(...microResults);\n await new Promise(resolve => setImmediate(resolve));\n }\n return results;\n}\n\n/**\n * Helper functions extracted from indexCodebase\n * These make the main function more readable and testable\n */\n\n/**\n * Update git state after indexing (if in a git repo).\n */\nasync function updateGitState(\n rootDir: string,\n vectorDB: VectorDB,\n manifest: ManifestManager\n): Promise<void> {\n const { isGitAvailable, isGitRepo } = await import('../git/utils.js');\n const { GitStateTracker } = await import('../git/tracker.js');\n \n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n \n if (!gitAvailable || !isRepo) {\n return;\n }\n \n const gitTracker = new GitStateTracker(rootDir, vectorDB.dbPath);\n await gitTracker.initialize();\n const gitState = gitTracker.getState();\n \n if (gitState) {\n await manifest.updateGitState(gitState);\n }\n}\n\n/**\n * Handle file deletions during incremental indexing.\n */\nasync function handleDeletions(\n deletedFiles: string[],\n vectorDB: VectorDB,\n manifest: ManifestManager,\n spinner: Ora\n): Promise<void> {\n if (deletedFiles.length === 0) {\n return;\n }\n \n spinner.start(`Removing ${deletedFiles.length} deleted files...`);\n let removedCount = 0;\n \n for (const filepath of deletedFiles) {\n try {\n await vectorDB.deleteByFile(filepath);\n await manifest.removeFile(filepath);\n removedCount++;\n } catch (err) {\n spinner.warn(\n `Failed to remove file \"${filepath}\": ${err instanceof Error ? err.message : String(err)}`\n );\n }\n }\n \n spinner.succeed(`Removed ${removedCount}/${deletedFiles.length} deleted files`);\n}\n\n/**\n * Handle file updates (additions and modifications) during incremental indexing.\n */\nasync function handleUpdates(\n addedFiles: string[],\n modifiedFiles: string[],\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<void> {\n const filesToIndex = [...addedFiles, ...modifiedFiles];\n \n if (filesToIndex.length === 0) {\n return;\n }\n \n spinner.start(`Reindexing ${filesToIndex.length} changed files...`);\n const count = await indexMultipleFiles(\n filesToIndex,\n vectorDB,\n embeddings,\n config,\n { verbose: options.verbose }\n );\n \n await writeVersionFile(vectorDB.dbPath);\n spinner.succeed(\n `Incremental reindex complete: ${count}/${filesToIndex.length} files indexed successfully`\n );\n}\n\n/**\n * Try incremental indexing if a manifest exists.\n * Returns true if incremental indexing completed, false if full index needed.\n */\nasync function tryIncrementalIndex(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<boolean> {\n spinner.text = 'Checking for changes...';\n const manifest = new ManifestManager(vectorDB.dbPath);\n const savedManifest = await manifest.load();\n \n if (!savedManifest) {\n return false; // No manifest, need full index\n }\n \n const changes = await detectChanges(rootDir, vectorDB, config);\n \n if (changes.reason === 'full') {\n spinner.text = 'Full reindex required...';\n return false;\n }\n \n const totalChanges = changes.added.length + changes.modified.length;\n const totalDeleted = changes.deleted.length;\n \n if (totalChanges === 0 && totalDeleted === 0) {\n spinner.succeed('No changes detected - index is up to date!');\n return true;\n }\n \n spinner.succeed(\n `Detected changes: ${totalChanges} files to index, ${totalDeleted} to remove (${changes.reason} detection)`\n );\n \n // Initialize embeddings for incremental update\n spinner.start(getModelLoadingMessage());\n const embeddings = new LocalEmbeddings();\n await embeddings.initialize();\n spinner.succeed('Embedding model loaded');\n \n // Process changes\n await handleDeletions(changes.deleted, vectorDB, manifest, spinner);\n await handleUpdates(changes.added, changes.modified, vectorDB, embeddings, config, options, spinner);\n \n // Update git state\n await updateGitState(rootDir, vectorDB, manifest);\n \n console.log(chalk.dim('\\nNext step: Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n return true;\n}\n\n/**\n * Perform a full index of the codebase.\n */\nasync function performFullIndex(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<void> {\n // 0. Clear existing index (required for schema changes)\n spinner.text = 'Clearing existing index...';\n await vectorDB.clear();\n \n // 1. Scan for files\n spinner.text = 'Scanning codebase...';\n const files = await scanFilesToIndex(rootDir, config);\n \n if (files.length === 0) {\n spinner.fail('No files found to index');\n return;\n }\n \n spinner.text = `Found ${files.length} files`;\n \n // 2. Initialize embeddings model\n spinner.text = getModelLoadingMessage();\n const embeddings = new LocalEmbeddings();\n await embeddings.initialize();\n spinner.succeed('Embedding model loaded');\n \n // 3. Get config values and process files\n const indexConfig = getIndexingConfig(config);\n const vectorDBBatchSize = 100; // Smaller batch for UI responsiveness\n \n spinner.start(`Processing files with ${indexConfig.concurrency}x concurrency...`);\n \n const startTime = Date.now();\n let processedChunks = 0;\n \n // Accumulator for chunks across multiple files\n const chunkAccumulator: ChunkWithContent[] = [];\n const limit = pLimit(indexConfig.concurrency);\n \n // Track successfully indexed files for manifest\n const indexedFileEntries: Array<{ filepath: string; chunkCount: number; mtime: number }> = [];\n \n // Create progress tracker\n const progressTracker = new IndexingProgressTracker(files.length, spinner);\n progressTracker.start();\n \n try {\n // Mutex to prevent concurrent access to shared state (chunkAccumulator, indexedFileEntries)\n // This prevents race conditions when multiple concurrent tasks try to:\n // 1. Push to shared arrays\n // 2. Check accumulator length threshold\n // 3. Trigger processing\n let addChunksLock: Promise<void> | null = null;\n let processingQueue: Promise<void> | null = null;\n \n // Function to process accumulated chunks\n // Uses queue-based synchronization to prevent TOCTOU race conditions\n const processAccumulatedChunks = async (): Promise<void> => {\n // Chain onto existing processing promise to create a queue\n // This prevents the race condition where multiple tasks check processingQueue\n // simultaneously and both proceed to process\n if (processingQueue) {\n processingQueue = processingQueue.then(() => doProcessChunks());\n } else {\n processingQueue = doProcessChunks();\n }\n return processingQueue;\n };\n \n // The actual processing logic (separated for queue-based synchronization)\n const doProcessChunks = async (): Promise<void> => {\n if (chunkAccumulator.length === 0) return;\n \n const currentPromise = processingQueue;\n \n try {\n const toProcess = chunkAccumulator.splice(0, chunkAccumulator.length);\n \n // Process in batches for UI responsiveness\n for (let i = 0; i < toProcess.length; i += indexConfig.embeddingBatchSize) {\n const batch = toProcess.slice(i, Math.min(i + indexConfig.embeddingBatchSize, toProcess.length));\n const texts = batch.map(item => item.content);\n \n progressTracker.setMessage(getEmbeddingMessage());\n const embeddingVectors = await processEmbeddingMicroBatches(texts, embeddings);\n processedChunks += batch.length;\n \n progressTracker.setMessage(`Inserting ${batch.length} chunks into vector space...`);\n await vectorDB.insertBatch(embeddingVectors, batch.map(item => item.chunk.metadata), texts);\n await new Promise(resolve => setImmediate(resolve));\n }\n \n progressTracker.setMessage(getIndexingMessage());\n } finally {\n if (processingQueue === currentPromise) processingQueue = null;\n }\n };\n \n // Process files with concurrency limit\n const filePromises = files.map((file) =>\n limit(async () => {\n try {\n // Get file stats to capture actual modification time\n const stats = await fs.stat(file);\n const content = await fs.readFile(file, 'utf-8');\n \n const chunks = chunkFile(file, content, {\n chunkSize: indexConfig.chunkSize,\n chunkOverlap: indexConfig.chunkOverlap,\n useAST: indexConfig.useAST,\n astFallback: indexConfig.astFallback,\n });\n \n if (chunks.length === 0) {\n progressTracker.incrementFiles();\n return;\n }\n \n // Critical section: add chunks to shared state and check threshold\n // Must be protected with mutex to prevent race conditions\n {\n // Wait for any in-progress add operation\n if (addChunksLock) {\n await addChunksLock;\n }\n \n // Acquire lock\n let releaseAddLock!: () => void;\n addChunksLock = new Promise<void>(resolve => {\n releaseAddLock = resolve;\n });\n \n try {\n // Add chunks to accumulator\n for (const chunk of chunks) {\n chunkAccumulator.push({\n chunk,\n content: chunk.content,\n });\n }\n \n // Track this file for manifest with actual file mtime\n indexedFileEntries.push({\n filepath: file,\n chunkCount: chunks.length,\n mtime: stats.mtimeMs,\n });\n \n progressTracker.incrementFiles();\n \n // Process when batch is large enough (use smaller batch for responsiveness)\n // Check is done inside the mutex to prevent multiple tasks from triggering processing\n if (chunkAccumulator.length >= vectorDBBatchSize) {\n await processAccumulatedChunks();\n }\n } finally {\n // Release lock (always defined by Promise constructor)\n releaseAddLock();\n addChunksLock = null;\n }\n }\n } catch (error) {\n if (options.verbose) {\n console.error(chalk.yellow(`\\n⚠️ Skipping ${file}: ${error}`));\n }\n progressTracker.incrementFiles();\n }\n })\n );\n \n // Wait for all files to be processed\n await Promise.all(filePromises);\n \n // Process remaining chunks\n progressTracker.setMessage('Processing final chunks...');\n await processAccumulatedChunks();\n } finally {\n // Always stop the progress tracker to clean up the interval\n progressTracker.stop();\n }\n \n // Save manifest with all indexed files\n spinner.start('Saving index manifest...');\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFiles(\n indexedFileEntries.map(entry => ({\n filepath: entry.filepath,\n // Use actual file mtime for accurate change detection\n lastModified: entry.mtime,\n chunkCount: entry.chunkCount,\n }))\n );\n \n // Save git state if in a git repo\n await updateGitState(rootDir, vectorDB, manifest);\n \n spinner.succeed('Manifest saved');\n \n // Write version file to mark successful completion\n await writeVersionFile(vectorDB.dbPath);\n \n const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);\n spinner.succeed(\n `Indexed ${progressTracker.getProcessedCount()} files (${processedChunks} chunks) in ${totalTime}s using ${indexConfig.concurrency}x concurrency`\n );\n \n console.log(chalk.dim('\\nNext step: Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n}\n\n/**\n * Index a codebase, creating vector embeddings for semantic search.\n * \n * Refactored to be more maintainable:\n * - Tries incremental indexing first (if not forced)\n * - Falls back to full indexing if needed\n * - Delegates to helper functions for specific tasks\n * \n * @param options - Indexing options\n */\nexport async function indexCodebase(options: IndexingOptions = {}): Promise<void> {\n const rootDir = options.rootDir ?? process.cwd();\n const spinner = ora('Starting indexing process...').start();\n \n try {\n // Load configuration\n spinner.text = 'Loading configuration...';\n const config = await configService.load(rootDir);\n \n // Initialize vector database\n spinner.text = 'Initializing vector database...';\n const vectorDB = new VectorDB(rootDir);\n await vectorDB.initialize();\n \n // Try incremental indexing first (unless forced)\n if (!options.force) {\n const completed = await tryIncrementalIndex(rootDir, vectorDB, config, options, spinner);\n if (completed) {\n return; // Incremental index completed\n }\n } else {\n spinner.text = 'Force flag enabled, performing full reindex...';\n }\n \n // Fall back to full index\n await performFullIndex(rootDir, vectorDB, config, options, spinner);\n \n } catch (error) {\n spinner.fail(`Indexing failed: ${error}`);\n throw error;\n }\n}\n\n","import { Command } from 'commander';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { initCommand } from './init.js';\nimport { statusCommand } from './status.js';\nimport { indexCommand } from './index-cmd.js';\nimport { serveCommand } from './serve.js';\nimport { complexityCommand } from './complexity.js';\n\n// Get version from package.json dynamically\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson;\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\nexport const program = new Command();\n\nprogram\n .name('lien')\n .description('Local semantic code search for AI assistants via MCP')\n .version(packageJson.version);\n\nprogram\n .command('init')\n .description('Initialize Lien in the current directory')\n .option('-u, --upgrade', 'Upgrade existing config with new options')\n .option('-y, --yes', 'Skip interactive prompts and use defaults')\n .option('-p, --path <path>', 'Path to initialize (defaults to current directory)')\n .action(initCommand);\n\nprogram\n .command('index')\n .description('Index the codebase for semantic search')\n .option('-f, --force', 'Force full reindex (skip incremental)')\n .option('-w, --watch', 'Watch for changes and re-index automatically')\n .option('-v, --verbose', 'Show detailed logging during indexing')\n .action(indexCommand);\n\nprogram\n .command('serve')\n .description('Start the MCP server for Cursor integration')\n .option('-p, --port <port>', 'Port number (for future use)', '7133')\n .option('--no-watch', 'Disable file watching for this session')\n .option('-w, --watch', '[DEPRECATED] File watching is now enabled by default')\n .option('-r, --root <path>', 'Root directory to serve (defaults to current directory)')\n .action(serveCommand);\n\nprogram\n .command('status')\n .description('Show indexing status and statistics')\n .action(statusCommand);\n\nprogram\n .command('complexity')\n .description('Analyze code complexity')\n .option('--files <paths...>', 'Specific files to analyze')\n .option('--format <type>', 'Output format: text, json, sarif', 'text')\n .option('--threshold <n>', 'Override both complexity thresholds (cyclomatic & cognitive)')\n .option('--cyclomatic-threshold <n>', 'Override cyclomatic complexity threshold only')\n .option('--cognitive-threshold <n>', 'Override cognitive complexity threshold only')\n .option('--fail-on <severity>', 'Exit 1 if violations: error, warning')\n .action(complexityCommand);\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { defaultConfig, LienConfig, FrameworkInstance, FrameworkConfig } from '../config/schema.js';\nimport { showCompactBanner } from '../utils/banner.js';\nimport { MigrationManager } from '../config/migration-manager.js';\nimport { detectAllFrameworks } from '../frameworks/detector-service.js';\nimport { getFrameworkDetector } from '../frameworks/registry.js';\n\n// ES module equivalent of __dirname\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport interface InitOptions {\n upgrade?: boolean;\n yes?: boolean;\n path?: string;\n}\n\nexport async function initCommand(options: InitOptions = {}) {\n const rootDir = options.path || process.cwd();\n const configPath = path.join(rootDir, '.lien.config.json');\n \n try {\n // Check if config already exists\n let configExists = false;\n try {\n await fs.access(configPath);\n configExists = true;\n } catch {\n // File doesn't exist\n }\n \n // Handle upgrade scenario\n if (configExists && options.upgrade) {\n const migrationManager = new MigrationManager(rootDir);\n await migrationManager.upgradeInteractive();\n return;\n }\n \n // Warn if config exists and not upgrading\n if (configExists && !options.upgrade) {\n console.log(chalk.yellow('⚠️ .lien.config.json already exists'));\n console.log(chalk.dim('Run'), chalk.bold('lien init --upgrade'), chalk.dim('to merge new config options'));\n return;\n }\n \n // Create new config with framework detection\n if (!configExists) {\n await createNewConfig(rootDir, options);\n }\n } catch (error) {\n console.error(chalk.red('Error creating config file:'), error);\n process.exit(1);\n }\n}\n\nasync function createNewConfig(rootDir: string, options: InitOptions) {\n // Show banner for new initialization\n showCompactBanner();\n console.log(chalk.bold('Initializing Lien...\\n'));\n \n // 1. Run framework detection\n console.log(chalk.dim('🔍 Detecting frameworks in'), chalk.bold(rootDir));\n const detections = await detectAllFrameworks(rootDir);\n \n let frameworks: FrameworkInstance[] = [];\n \n if (detections.length === 0) {\n console.log(chalk.yellow('\\n⚠️ No frameworks detected'));\n \n if (!options.yes) {\n const { useGeneric } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'useGeneric',\n message: 'Create a generic config (index all supported file types)?',\n default: true,\n },\n ]);\n \n if (!useGeneric) {\n console.log(chalk.dim('Aborted.'));\n return;\n }\n }\n \n // Create generic framework\n frameworks.push({\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n });\n } else {\n // 2. Display detected frameworks\n console.log(chalk.green(`\\n✓ Found ${detections.length} framework(s):\\n`));\n \n for (const det of detections) {\n const pathDisplay = det.path === '.' ? 'root' : det.path;\n console.log(chalk.bold(` ${det.name}`), chalk.dim(`(${det.confidence} confidence)`));\n console.log(chalk.dim(` Location: ${pathDisplay}`));\n \n if (det.evidence.length > 0) {\n det.evidence.forEach((e) => {\n console.log(chalk.dim(` • ${e}`));\n });\n }\n console.log();\n }\n \n // 3. Interactive confirmation\n if (!options.yes) {\n const { confirm } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'confirm',\n message: 'Configure these frameworks?',\n default: true,\n },\n ]);\n \n if (!confirm) {\n console.log(chalk.dim('Aborted.'));\n return;\n }\n }\n \n // 4. Generate configs for each detected framework\n for (const det of detections) {\n const detector = getFrameworkDetector(det.name);\n if (!detector) {\n console.warn(chalk.yellow(`⚠️ No detector found for ${det.name}, skipping`));\n continue;\n }\n \n // Generate default config\n const frameworkConfig = await detector.generateConfig(rootDir, det.path);\n \n // Optional: Ask to customize (only in interactive mode)\n let shouldCustomize = false;\n if (!options.yes) {\n const { customize } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'customize',\n message: `Customize ${det.name} settings?`,\n default: false,\n },\n ]);\n shouldCustomize = customize;\n }\n \n let finalConfig = frameworkConfig;\n if (shouldCustomize) {\n const customized = await promptForCustomization(det.name, frameworkConfig);\n finalConfig = { ...frameworkConfig, ...customized };\n } else {\n const pathDisplay = det.path === '.' ? 'root' : det.path;\n console.log(chalk.dim(` → Using defaults for ${det.name} at ${pathDisplay}`));\n }\n \n frameworks.push({\n name: det.name,\n path: det.path,\n enabled: true,\n config: finalConfig,\n });\n }\n }\n \n // 5. Ask about Cursor rules installation\n if (!options.yes) {\n const { installCursorRules } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'installCursorRules',\n message: 'Install recommended Cursor rules?',\n default: true,\n },\n ]);\n \n if (installCursorRules) {\n try {\n const cursorRulesDir = path.join(rootDir, '.cursor');\n await fs.mkdir(cursorRulesDir, { recursive: true });\n \n // Find template - it's in the package root (same dir as package.json)\n // When compiled: everything bundles to dist/index.js, so __dirname is dist/\n // Go up one level from dist/ to reach package root\n const templatePath = path.join(__dirname, '../CURSOR_RULES_TEMPLATE.md');\n \n const rulesPath = path.join(cursorRulesDir, 'rules');\n let targetPath: string;\n let isDirectory = false;\n let isFile = false;\n\n try {\n const stats = await fs.stat(rulesPath);\n isDirectory = stats.isDirectory();\n isFile = stats.isFile();\n } catch {\n // Doesn't exist, that's fine\n }\n\n if (isDirectory) {\n // .cursor/rules is already a directory, create lien.mdc inside it\n targetPath = path.join(rulesPath, 'lien.mdc');\n await fs.copyFile(templatePath, targetPath);\n console.log(chalk.green('✓ Installed Cursor rules as .cursor/rules/lien.mdc'));\n } else if (isFile) {\n // .cursor/rules exists as a file - ask to convert to directory structure\n const { convertToDir } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'convertToDir',\n message: 'Existing .cursor/rules file found. Convert to directory and preserve your rules?',\n default: true,\n },\n ]);\n\n if (convertToDir) {\n // Convert file to directory structure\n // 1. Read existing rules\n const existingRules = await fs.readFile(rulesPath, 'utf-8');\n // 2. Delete the file\n await fs.unlink(rulesPath);\n // 3. Create rules as a directory\n await fs.mkdir(rulesPath);\n // 4. Save original rules as project.mdc\n await fs.writeFile(path.join(rulesPath, 'project.mdc'), existingRules);\n // 5. Add Lien rules as lien.mdc\n await fs.copyFile(templatePath, path.join(rulesPath, 'lien.mdc'));\n console.log(chalk.green('✓ Converted .cursor/rules to directory'));\n console.log(chalk.green(' - Your project rules: .cursor/rules/project.mdc'));\n console.log(chalk.green(' - Lien rules: .cursor/rules/lien.mdc'));\n } else {\n console.log(chalk.dim('Skipped Cursor rules installation (preserving existing file)'));\n }\n } else {\n // .cursor/rules doesn't exist, create it as a directory\n await fs.mkdir(rulesPath, { recursive: true });\n targetPath = path.join(rulesPath, 'lien.mdc');\n await fs.copyFile(templatePath, targetPath);\n console.log(chalk.green('✓ Installed Cursor rules as .cursor/rules/lien.mdc'));\n }\n } catch (error) {\n console.log(chalk.yellow('⚠️ Could not install Cursor rules'));\n console.log(chalk.dim(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));\n console.log(chalk.dim('You can manually copy CURSOR_RULES_TEMPLATE.md to .cursor/rules/lien.mdc'));\n }\n }\n }\n \n // 6. Build final config\n const config: LienConfig = {\n ...defaultConfig,\n frameworks,\n };\n \n // 7. Write config\n const configPath = path.join(rootDir, '.lien.config.json');\n await fs.writeFile(configPath, JSON.stringify(config, null, 2) + '\\n', 'utf-8');\n \n // 8. Show success message\n console.log(chalk.green('\\n✓ Created .lien.config.json'));\n console.log(chalk.green(`✓ Configured ${frameworks.length} framework(s)`));\n console.log(chalk.dim('\\nNext steps:'));\n console.log(chalk.dim(' 1. Run'), chalk.bold('lien index'), chalk.dim('to index your codebase'));\n console.log(chalk.dim(' 2. Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n console.log(chalk.dim(' 3. Configure Cursor to use the MCP server (see README.md)'));\n}\n\nasync function promptForCustomization(frameworkName: string, config: FrameworkConfig): Promise<Partial<FrameworkConfig>> {\n console.log(chalk.bold(`\\nCustomizing ${frameworkName} settings:`));\n \n const answers = await inquirer.prompt([\n {\n type: 'input',\n name: 'include',\n message: 'File patterns to include (comma-separated):',\n default: config.include.join(', '),\n filter: (input: string) => input.split(',').map(s => s.trim()),\n },\n {\n type: 'input',\n name: 'exclude',\n message: 'File patterns to exclude (comma-separated):',\n default: config.exclude.join(', '),\n filter: (input: string) => input.split(',').map(s => s.trim()),\n },\n ]);\n \n return {\n include: answers.include,\n exclude: answers.exclude,\n };\n}\n\n// Removed: upgradeConfig function is now handled by MigrationManager.upgradeInteractive()\n","import figlet from 'figlet';\nimport chalk from 'chalk';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\n\n// Get package.json dynamically\n// In development: src/utils/banner.ts -> ../../package.json\n// In production (bundled): dist/index.js -> ../package.json\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\n// Try production path first (dist -> package.json), then dev path\nlet packageJson;\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\n// Package info\nconst PACKAGE_NAME = packageJson.name;\nconst VERSION = packageJson.version;\n\n/**\n * Wrap text in a box with a footer line\n */\nfunction wrapInBox(text: string, footer: string, padding = 1): string {\n const lines = text.split('\\n').filter(line => line.trim().length > 0);\n \n // Use only the main content (logo) to determine box width\n const maxLength = Math.max(...lines.map(line => line.length));\n \n const horizontalBorder = '─'.repeat(maxLength + padding * 2);\n const top = `┌${horizontalBorder}┐`;\n const bottom = `└${horizontalBorder}┘`;\n const separator = `├${horizontalBorder}┤`;\n \n const paddedLines = lines.map(line => {\n const padRight = ' '.repeat(maxLength - line.length + padding);\n const padLeft = ' '.repeat(padding);\n return `│${padLeft}${line}${padRight}│`;\n });\n \n // Center the footer line\n const totalPad = maxLength - footer.length;\n const leftPad = Math.floor(totalPad / 2);\n const rightPad = totalPad - leftPad;\n const centeredFooter = ' '.repeat(leftPad) + footer + ' '.repeat(rightPad);\n \n const paddedFooter = `│${' '.repeat(padding)}${centeredFooter}${' '.repeat(padding)}│`;\n \n return [top, ...paddedLines, separator, paddedFooter, bottom].join('\\n');\n}\n\n/**\n * Display the gorgeous ANSI Shadow banner (uses stderr for MCP server)\n */\nexport function showBanner(): void {\n const banner = figlet.textSync('LIEN', {\n font: 'ANSI Shadow',\n horizontalLayout: 'fitted',\n verticalLayout: 'fitted',\n });\n\n const footer = `${PACKAGE_NAME} - v${VERSION}`;\n const boxedBanner = wrapInBox(banner.trim(), footer);\n console.error(chalk.cyan(boxedBanner));\n console.error(); // Empty line\n}\n\n/**\n * Display the gorgeous ANSI Shadow banner (uses stdout for CLI commands)\n */\nexport function showCompactBanner(): void {\n const banner = figlet.textSync('LIEN', {\n font: 'ANSI Shadow',\n horizontalLayout: 'fitted',\n verticalLayout: 'fitted',\n });\n\n const footer = `${PACKAGE_NAME} - v${VERSION}`;\n const boxedBanner = wrapInBox(banner.trim(), footer);\n console.log(chalk.cyan(boxedBanner));\n console.log(); // Empty line\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport chalk from 'chalk';\nimport { LienConfig, defaultConfig } from './schema.js';\nimport { needsMigration, migrateConfig, migrateConfigFile } from './migration.js';\nimport { deepMergeConfig, detectNewFields } from './merge.js';\nimport { CURRENT_CONFIG_VERSION } from '../constants.js';\n\n/**\n * Result of a migration operation\n */\nexport interface MigrationResult {\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}\n\n/**\n * Centralized migration orchestration service\n * \n * Handles all config migration scenarios:\n * - Auto-migration during config loading\n * - Interactive upgrade via CLI\n * - Migration status checking\n */\nexport class MigrationManager {\n constructor(private readonly rootDir: string = process.cwd()) {}\n \n /**\n * Get the config file path\n */\n private getConfigPath(): string {\n return path.join(this.rootDir, '.lien.config.json');\n }\n \n /**\n * Check if the current config needs migration\n */\n async needsMigration(): Promise<boolean> {\n try {\n const configPath = this.getConfigPath();\n const content = await fs.readFile(configPath, 'utf-8');\n const config = JSON.parse(content);\n return needsMigration(config);\n } catch (error) {\n // If config doesn't exist or can't be read, no migration needed\n return false;\n }\n }\n \n /**\n * Perform silent migration (for auto-migration during load)\n * Returns the migrated config without user interaction\n */\n async autoMigrate(): Promise<LienConfig> {\n const result = await migrateConfigFile(this.rootDir);\n \n if (result.migrated && result.backupPath) {\n const backupFilename = path.basename(result.backupPath);\n console.log(`✅ Migration complete! Backup saved as ${backupFilename}`);\n console.log('📝 Your config now uses the framework-based structure.');\n }\n \n return result.config;\n }\n \n /**\n * Perform interactive upgrade (for CLI upgrade command)\n * Provides detailed feedback and handles edge cases\n */\n async upgradeInteractive(): Promise<void> {\n const configPath = this.getConfigPath();\n \n try {\n // 1. Read existing config\n const existingContent = await fs.readFile(configPath, 'utf-8');\n const existingConfig = JSON.parse(existingContent);\n \n // 2. Check if any changes are needed\n const migrationNeeded = needsMigration(existingConfig);\n const newFields = migrationNeeded ? [] : detectNewFields(existingConfig, defaultConfig);\n const hasChanges = migrationNeeded || newFields.length > 0;\n \n if (!hasChanges) {\n console.log(chalk.green('✓ Config is already up to date'));\n console.log(chalk.dim('No changes needed'));\n return;\n }\n \n // 3. Backup existing config (only if changes are needed)\n const backupPath = `${configPath}.backup`;\n await fs.copyFile(configPath, backupPath);\n \n // 4. Perform upgrade\n let upgradedConfig: LienConfig;\n let migrated = false;\n \n if (migrationNeeded) {\n console.log(chalk.blue(`🔄 Migrating config from v0.2.0 to v${CURRENT_CONFIG_VERSION}...`));\n upgradedConfig = migrateConfig(existingConfig);\n migrated = true;\n } else {\n // Just merge with defaults for current version configs\n upgradedConfig = deepMergeConfig(defaultConfig, existingConfig as Partial<LienConfig>);\n \n console.log(chalk.dim('\\nNew options added:'));\n newFields.forEach(field => console.log(chalk.dim(' •'), chalk.bold(field)));\n }\n \n // 5. Write upgraded config\n await fs.writeFile(\n configPath,\n JSON.stringify(upgradedConfig, null, 2) + '\\n',\n 'utf-8'\n );\n \n // 6. Show results\n console.log(chalk.green('✓ Config upgraded successfully'));\n console.log(chalk.dim('Backup saved to:'), backupPath);\n \n if (migrated) {\n console.log(chalk.dim('\\n📝 Your config now uses the framework-based structure.'));\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.log(chalk.red('Error: No config file found'));\n console.log(chalk.dim('Run'), chalk.bold('lien init'), chalk.dim('to create a config file'));\n return;\n }\n throw error;\n }\n }\n \n /**\n * Perform migration and return result\n * Used when programmatic access to migration result is needed\n */\n async migrate(): Promise<MigrationResult> {\n return migrateConfigFile(this.rootDir);\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { DetectionResult, DetectionOptions, defaultDetectionOptions } from './types.js';\nimport { frameworkDetectors } from './registry.js';\n\n/**\n * Detect all frameworks in a monorepo by recursively scanning subdirectories\n * @param rootDir - Absolute path to project root\n * @param options - Detection options (max depth, skip dirs)\n * @returns Array of detected frameworks with their paths\n */\nexport async function detectAllFrameworks(\n rootDir: string,\n options: Partial<DetectionOptions> = {}\n): Promise<DetectionResult[]> {\n const opts = { ...defaultDetectionOptions, ...options };\n const results: DetectionResult[] = [];\n const visited = new Set<string>();\n \n // Detect at root first\n await detectAtPath(rootDir, '.', results, visited);\n \n // Recursively scan subdirectories\n await scanSubdirectories(rootDir, '.', results, visited, 0, opts);\n \n return results;\n}\n\n/**\n * Detect frameworks at a specific path\n */\nasync function detectAtPath(\n rootDir: string,\n relativePath: string,\n results: DetectionResult[],\n visited: Set<string>\n): Promise<void> {\n // Mark as visited\n const fullPath = path.join(rootDir, relativePath);\n if (visited.has(fullPath)) {\n return;\n }\n visited.add(fullPath);\n \n // Run all detectors and collect results\n const detectedAtPath: Array<DetectionResult & { priority: number }> = [];\n \n for (const detector of frameworkDetectors) {\n try {\n const result = await detector.detect(rootDir, relativePath);\n if (result.detected) {\n detectedAtPath.push({\n ...result,\n priority: detector.priority ?? 0,\n });\n }\n } catch (error) {\n // Log error but continue with other detectors\n console.error(`Error running detector '${detector.name}' at ${relativePath}:`, error);\n }\n }\n \n // Conflict resolution: Allow multiple HIGH-confidence frameworks to coexist\n // This enables hybrid projects (e.g., Shopify + Node.js, Laravel + Node.js)\n if (detectedAtPath.length > 1) {\n // Separate frameworks by confidence level\n const highConfidence = detectedAtPath.filter(d => d.confidence === 'high');\n const mediumConfidence = detectedAtPath.filter(d => d.confidence === 'medium');\n const lowConfidence = detectedAtPath.filter(d => d.confidence === 'low');\n \n if (highConfidence.length > 1) {\n // Multiple HIGH-confidence frameworks -> keep all (hybrid/monorepo behavior)\n // Strip internal priority property before adding to results\n const cleanResults = highConfidence.map(({ priority, ...result }) => result);\n results.push(...cleanResults);\n const names = highConfidence.map(d => d.name).join(' + ');\n console.log(` → Detected hybrid project: ${names}`);\n \n // Log skipped medium/low confidence detections\n if (mediumConfidence.length > 0 || lowConfidence.length > 0) {\n const skippedNames = [...mediumConfidence, ...lowConfidence].map(d => d.name).join(', ');\n console.log(` → Skipping lower confidence detections: ${skippedNames}`);\n }\n } else if (highConfidence.length === 1) {\n // Only one HIGH-confidence framework\n const { priority, ...result } = highConfidence[0];\n results.push(result);\n \n // Log skipped medium/low confidence detections\n if (mediumConfidence.length > 0 || lowConfidence.length > 0) {\n const skippedNames = [...mediumConfidence, ...lowConfidence].map(d => d.name).join(', ');\n console.log(` → Skipping lower confidence detections: ${skippedNames}`);\n }\n } else if (mediumConfidence.length > 0) {\n // No HIGH confidence, but have MEDIUM -> use priority system\n mediumConfidence.sort((a, b) => b.priority - a.priority);\n const { priority, ...winner } = mediumConfidence[0];\n results.push(winner);\n \n // Skipped = remaining medium + all low confidence\n const skipped = [...mediumConfidence.slice(1), ...lowConfidence];\n if (skipped.length > 0) {\n const skippedNames = skipped.map(d => d.name).join(', ');\n console.log(` → Skipping ${skippedNames} at ${relativePath} (${winner.name} takes precedence)`);\n }\n } else if (lowConfidence.length > 0) {\n // Only LOW confidence -> use priority system\n lowConfidence.sort((a, b) => b.priority - a.priority);\n const { priority, ...winner } = lowConfidence[0];\n results.push(winner);\n \n // Skipped = remaining low confidence\n const skipped = lowConfidence.slice(1);\n if (skipped.length > 0) {\n const skippedNames = skipped.map(d => d.name).join(', ');\n console.log(` → Skipping ${skippedNames} at ${relativePath} (${winner.name} takes precedence)`);\n }\n }\n } else if (detectedAtPath.length === 1) {\n const { priority, ...result } = detectedAtPath[0];\n results.push(result);\n }\n}\n\n/**\n * Recursively scan subdirectories for frameworks\n */\nasync function scanSubdirectories(\n rootDir: string,\n relativePath: string,\n results: DetectionResult[],\n visited: Set<string>,\n depth: number,\n options: DetectionOptions\n): Promise<void> {\n // Check depth limit\n if (depth >= options.maxDepth) {\n return;\n }\n \n const fullPath = path.join(rootDir, relativePath);\n \n try {\n const entries = await fs.readdir(fullPath, { withFileTypes: true });\n \n // Process only directories\n const dirs = entries.filter(e => e.isDirectory());\n \n for (const dir of dirs) {\n // Skip directories in the skip list\n if (options.skipDirs.includes(dir.name)) {\n continue;\n }\n \n // Skip hidden directories (except .git, .github which are already in skipDirs)\n if (dir.name.startsWith('.')) {\n continue;\n }\n \n const subPath = relativePath === '.' \n ? dir.name \n : path.join(relativePath, dir.name);\n \n // Detect at this subdirectory\n await detectAtPath(rootDir, subPath, results, visited);\n \n // Recurse deeper\n await scanSubdirectories(rootDir, subPath, results, visited, depth + 1, options);\n }\n } catch (error) {\n // Silently skip directories we can't read (permission errors, etc.)\n return;\n }\n}\n\n/**\n * Get a human-readable summary of detected frameworks\n */\nexport function getDetectionSummary(results: DetectionResult[]): string {\n if (results.length === 0) {\n return 'No frameworks detected';\n }\n \n const lines: string[] = [];\n \n for (const result of results) {\n const pathDisplay = result.path === '.' ? 'root' : result.path;\n lines.push(`${result.name} at ${pathDisplay} (${result.confidence} confidence)`);\n \n if (result.evidence.length > 0) {\n result.evidence.forEach(e => {\n lines.push(` - ${e}`);\n });\n }\n }\n \n return lines.join('\\n');\n}\n\n","import { FrameworkConfig } from '../config/schema.js';\n\n/**\n * Result of framework detection\n */\nexport interface DetectionResult {\n detected: boolean;\n name: string; // 'nodejs', 'laravel'\n path: string; // Relative path from root: '.', 'packages/cli', 'cognito-backend'\n confidence: 'high' | 'medium' | 'low';\n evidence: string[]; // Human-readable evidence (e.g., \"Found package.json with jest\")\n version?: string; // Framework/language version if detectable\n}\n\n/**\n * Interface for framework detectors\n */\nexport interface FrameworkDetector {\n name: string; // Unique framework identifier\n \n /**\n * Priority for conflict resolution (higher = takes precedence)\n * - 100: Specific frameworks (Laravel, Rails, Django)\n * - 50: Generic frameworks (Node.js, Python)\n * - 0: Fallback/generic\n */\n priority?: number;\n \n /**\n * Detect if this framework exists at the given path\n * @param rootDir - Absolute path to project root\n * @param relativePath - Relative path from root to check (e.g., '.' or 'packages/cli')\n * @returns Detection result with evidence\n */\n detect(rootDir: string, relativePath: string): Promise<DetectionResult>;\n \n /**\n * Generate default configuration for this framework\n * @param rootDir - Absolute path to project root\n * @param relativePath - Relative path where framework was detected\n * @returns Framework-specific configuration\n */\n generateConfig(rootDir: string, relativePath: string): Promise<FrameworkConfig>;\n}\n\n/**\n * Options for framework detection\n */\nexport interface DetectionOptions {\n maxDepth: number; // Maximum directory depth to scan\n skipDirs: string[]; // Directories to skip (node_modules, vendor, etc.)\n}\n\n/**\n * Default detection options\n */\nexport const defaultDetectionOptions: DetectionOptions = {\n maxDepth: 3,\n skipDirs: [\n 'node_modules',\n 'vendor',\n 'dist',\n 'build',\n '.next',\n '.nuxt',\n 'coverage',\n '.git',\n '.idea',\n '.vscode',\n 'tmp',\n 'temp',\n ],\n};\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateNodeJsConfig } from './config.js';\n\n/**\n * Node.js/TypeScript/JavaScript framework detector\n */\nexport const nodejsDetector: FrameworkDetector = {\n name: 'nodejs',\n priority: 50, // Generic, yields to specific frameworks like Laravel\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'nodejs',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for package.json\n const packageJsonPath = path.join(fullPath, 'package.json');\n let packageJson: any = null;\n \n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8');\n packageJson = JSON.parse(content);\n result.evidence.push('Found package.json');\n } catch {\n // No package.json, not a Node.js project\n return result;\n }\n \n // At this point, we know it's a Node.js project\n result.detected = true;\n result.confidence = 'high';\n \n // Check for TypeScript\n if (packageJson.devDependencies?.typescript || packageJson.dependencies?.typescript) {\n result.evidence.push('TypeScript detected');\n }\n \n // Check for testing frameworks\n const testFrameworks = [\n { name: 'jest', display: 'Jest' },\n { name: 'vitest', display: 'Vitest' },\n { name: 'mocha', display: 'Mocha' },\n { name: 'ava', display: 'AVA' },\n { name: '@playwright/test', display: 'Playwright' },\n ];\n \n for (const framework of testFrameworks) {\n if (\n packageJson.devDependencies?.[framework.name] || \n packageJson.dependencies?.[framework.name]\n ) {\n result.evidence.push(`${framework.display} test framework detected`);\n break; // Only mention first test framework found\n }\n }\n \n // Check for common frameworks/libraries\n const frameworks = [\n { name: 'next', display: 'Next.js' },\n { name: 'react', display: 'React' },\n { name: 'vue', display: 'Vue' },\n { name: 'express', display: 'Express' },\n { name: '@nestjs/core', display: 'NestJS' },\n ];\n \n for (const fw of frameworks) {\n if (packageJson.dependencies?.[fw.name]) {\n result.evidence.push(`${fw.display} detected`);\n break; // Only mention first framework found\n }\n }\n \n // Try to detect version from package.json engines or node version\n if (packageJson.engines?.node) {\n result.version = packageJson.engines.node;\n }\n \n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateNodeJsConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Node.js framework configuration\n */\nexport async function generateNodeJsConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // Broader patterns to catch all common project structures\n // (frontend/, src/, lib/, app/, components/, etc.)\n '**/*.ts',\n '**/*.tsx',\n '**/*.js',\n '**/*.jsx',\n '**/*.vue',\n '**/*.mjs',\n '**/*.cjs',\n '**/*.md',\n '**/*.mdx',\n ],\n exclude: [\n // Node.js dependencies (with ** prefix for nested projects)\n '**/node_modules/**',\n 'node_modules/**',\n \n // PHP/Composer dependencies (for monorepos with PHP)\n '**/vendor/**',\n 'vendor/**',\n \n // Build outputs\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n '**/public/build/**',\n 'public/build/**',\n 'out/**',\n \n // Framework build caches\n '.next/**',\n '.nuxt/**',\n '.vite/**',\n '.lien/**',\n \n // Test artifacts\n 'coverage/**',\n 'playwright-report/**',\n 'test-results/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Common build/cache directories\n '.cache/**',\n '.turbo/**',\n '.vercel/**',\n '.netlify/**',\n \n // Minified/bundled files\n '**/*.min.js',\n '**/*.min.css',\n '**/*.bundle.js',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generatePhpConfig } from './config.js';\n\n/**\n * Generic PHP framework detector\n * Detects any PHP project with composer.json\n */\nexport const phpDetector: FrameworkDetector = {\n name: 'php',\n priority: 50, // Generic, yields to specific frameworks like Laravel\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'php',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for composer.json\n const composerJsonPath = path.join(fullPath, 'composer.json');\n let composerJson: any = null;\n \n try {\n const content = await fs.readFile(composerJsonPath, 'utf-8');\n composerJson = JSON.parse(content);\n result.evidence.push('Found composer.json');\n } catch {\n // No composer.json, not a PHP project\n return result;\n }\n \n // Check if this is a Laravel project (Laravel detector should handle it)\n const hasLaravel = \n composerJson.require?.['laravel/framework'] ||\n composerJson['require-dev']?.['laravel/framework'];\n \n if (hasLaravel) {\n // This is a Laravel project - let the Laravel detector handle it\n // Return not detected to avoid redundant \"php\" + \"laravel\" detection\n return result;\n }\n \n // At this point, we know it's a generic PHP project (not Laravel)\n result.detected = true;\n result.confidence = 'high';\n \n // Check for common PHP directories\n const phpDirs = ['src', 'lib', 'app', 'tests'];\n let foundDirs = 0;\n \n for (const dir of phpDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs > 0) {\n result.evidence.push(`Found PHP project structure (${foundDirs} directories)`);\n }\n \n // Check for PHP version\n if (composerJson.require?.php) {\n result.version = composerJson.require.php;\n result.evidence.push(`PHP ${composerJson.require.php}`);\n }\n \n // Check for testing frameworks\n const testFrameworks = [\n { name: 'phpunit/phpunit', display: 'PHPUnit' },\n { name: 'pestphp/pest', display: 'Pest' },\n { name: 'codeception/codeception', display: 'Codeception' },\n { name: 'behat/behat', display: 'Behat' },\n ];\n \n for (const framework of testFrameworks) {\n if (\n composerJson.require?.[framework.name] || \n composerJson['require-dev']?.[framework.name]\n ) {\n result.evidence.push(`${framework.display} test framework detected`);\n break; // Only mention first test framework found\n }\n }\n \n // Check for common PHP tools/frameworks\n const tools = [\n { name: 'symfony/framework-bundle', display: 'Symfony' },\n { name: 'symfony/http-kernel', display: 'Symfony' },\n { name: 'symfony/symfony', display: 'Symfony (monolithic)' },\n { name: 'doctrine/orm', display: 'Doctrine ORM' },\n { name: 'guzzlehttp/guzzle', display: 'Guzzle HTTP' },\n { name: 'monolog/monolog', display: 'Monolog' },\n ];\n \n for (const tool of tools) {\n if (composerJson.require?.[tool.name]) {\n result.evidence.push(`${tool.display} detected`);\n break; // Only mention first tool found\n }\n }\n \n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generatePhpConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate generic PHP framework configuration\n */\nexport async function generatePhpConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // PHP source code\n 'src/**/*.php',\n 'lib/**/*.php',\n 'app/**/*.php',\n 'tests/**/*.php',\n '*.php',\n \n // Common PHP project files\n 'config/**/*.php',\n 'public/**/*.php',\n \n // Documentation\n '**/*.md',\n '**/*.mdx',\n 'docs/**/*.md',\n 'README.md',\n 'CHANGELOG.md',\n ],\n exclude: [\n // Composer dependencies (CRITICAL)\n '**/vendor/**',\n 'vendor/**',\n \n // Node.js dependencies\n '**/node_modules/**',\n 'node_modules/**',\n \n // Build outputs\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n '**/public/build/**',\n 'public/build/**',\n \n // Laravel/PHP system directories\n 'storage/**',\n 'cache/**',\n 'bootstrap/cache/**',\n \n // Test artifacts\n 'coverage/**',\n 'test-results/**',\n '.phpunit.cache/**',\n \n // Build outputs\n '__generated__/**',\n \n // Minified files\n '**/*.min.js',\n '**/*.min.css',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateLaravelConfig } from './config.js';\n\n/**\n * Laravel/PHP framework detector\n */\nexport const laravelDetector: FrameworkDetector = {\n name: 'laravel',\n priority: 100, // Laravel takes precedence over Node.js\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'laravel',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for composer.json with Laravel\n const composerJsonPath = path.join(fullPath, 'composer.json');\n let composerJson: any = null;\n \n try {\n const content = await fs.readFile(composerJsonPath, 'utf-8');\n composerJson = JSON.parse(content);\n result.evidence.push('Found composer.json');\n } catch {\n // No composer.json, not a Laravel project\n return result;\n }\n \n // Check if Laravel framework is in dependencies\n const hasLaravel = \n composerJson.require?.['laravel/framework'] ||\n composerJson['require-dev']?.['laravel/framework'];\n \n if (!hasLaravel) {\n // Has composer.json but not Laravel\n return result;\n }\n \n result.evidence.push('Laravel framework detected in composer.json');\n \n // Check for artisan file (strong indicator of Laravel)\n const artisanPath = path.join(fullPath, 'artisan');\n try {\n await fs.access(artisanPath);\n result.evidence.push('Found artisan file');\n result.confidence = 'high';\n } catch {\n result.confidence = 'medium';\n }\n \n // Check for typical Laravel directory structure\n const laravelDirs = ['app', 'routes', 'config', 'database'];\n let foundDirs = 0;\n \n for (const dir of laravelDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs >= 2) {\n result.evidence.push(`Laravel directory structure detected (${foundDirs}/${laravelDirs.length} dirs)`);\n result.confidence = 'high';\n }\n \n // Check for test directories\n const testDirsToCheck = [\n path.join(fullPath, 'tests', 'Feature'),\n path.join(fullPath, 'tests', 'Unit'),\n ];\n \n for (const testDir of testDirsToCheck) {\n try {\n const stats = await fs.stat(testDir);\n if (stats.isDirectory()) {\n const dirName = path.basename(path.dirname(testDir)) + '/' + path.basename(testDir);\n result.evidence.push(`Found ${dirName} test directory`);\n }\n } catch {\n // Test directory doesn't exist\n }\n }\n \n // Extract Laravel version if available\n if (composerJson.require?.['laravel/framework']) {\n result.version = composerJson.require['laravel/framework'];\n }\n \n result.detected = true;\n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateLaravelConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Laravel framework configuration\n */\nexport async function generateLaravelConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // PHP backend\n 'app/**/*.php',\n 'routes/**/*.php',\n 'config/**/*.php',\n 'database/**/*.php',\n 'resources/**/*.php',\n 'tests/**/*.php',\n '*.php',\n // Frontend assets (Vue/React/Inertia) - Scoped to resources/ to avoid build output\n 'resources/**/*.js',\n 'resources/**/*.ts',\n 'resources/**/*.jsx',\n 'resources/**/*.tsx',\n 'resources/**/*.vue',\n // Blade templates\n 'resources/views/**/*.blade.php',\n // Documentation\n 'docs/**/*.md',\n 'README.md',\n 'CHANGELOG.md',\n ],\n exclude: [\n // Composer dependencies (CRITICAL: exclude before any include patterns)\n '**/vendor/**',\n 'vendor/**',\n \n // Build outputs (Vite/Mix compiled assets)\n '**/public/build/**',\n 'public/build/**',\n 'public/hot',\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n \n // Laravel system directories\n 'storage/**',\n 'bootstrap/cache/**',\n 'public/**/*.js', // Compiled JS in public\n 'public/**/*.css', // Compiled CSS in public\n \n // Node.js dependencies\n '**/node_modules/**',\n 'node_modules/**',\n \n // Test artifacts\n 'playwright-report/**',\n 'test-results/**',\n 'coverage/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Frontend build outputs\n '.vite/**',\n '.nuxt/**',\n '.next/**',\n \n // Minified files\n '**/*.min.js',\n '**/*.min.css',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateShopifyConfig } from './config.js';\n\n/**\n * Shopify Liquid theme framework detector\n */\nexport const shopifyDetector: FrameworkDetector = {\n name: 'shopify',\n priority: 100, // High priority (same as Laravel)\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'shopify',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // 1. Check for config/settings_schema.json (STRONGEST signal)\n const settingsSchemaPath = path.join(fullPath, 'config', 'settings_schema.json');\n let hasSettingsSchema = false;\n \n try {\n await fs.access(settingsSchemaPath);\n hasSettingsSchema = true;\n result.evidence.push('Found config/settings_schema.json');\n } catch {\n // Not present, continue checking other markers\n }\n \n // 2. Check for layout/theme.liquid\n const themeLayoutPath = path.join(fullPath, 'layout', 'theme.liquid');\n let hasThemeLayout = false;\n \n try {\n await fs.access(themeLayoutPath);\n hasThemeLayout = true;\n result.evidence.push('Found layout/theme.liquid');\n } catch {\n // Not present\n }\n \n // 3. Check for typical Shopify directories\n const shopifyDirs = ['sections', 'snippets', 'templates', 'locales'];\n let foundDirs = 0;\n \n for (const dir of shopifyDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs >= 2) {\n result.evidence.push(`Shopify directory structure detected (${foundDirs}/${shopifyDirs.length} dirs)`);\n }\n \n // 4. Check for shopify.theme.toml (Shopify CLI)\n try {\n const tomlPath = path.join(fullPath, 'shopify.theme.toml');\n await fs.access(tomlPath);\n result.evidence.push('Found shopify.theme.toml');\n } catch {\n // Optional file\n }\n \n // 5. Check for .shopifyignore\n try {\n const ignorePath = path.join(fullPath, '.shopifyignore');\n await fs.access(ignorePath);\n result.evidence.push('Found .shopifyignore');\n } catch {\n // Optional file\n }\n \n // Determine detection confidence with early returns\n // High: Has settings_schema.json + 2+ directories\n if (hasSettingsSchema && foundDirs >= 2) {\n result.detected = true;\n result.confidence = 'high';\n return result;\n }\n \n // Medium: Has settings_schema alone, OR has theme.liquid + 1+ directory\n if (hasSettingsSchema || (hasThemeLayout && foundDirs >= 1)) {\n result.detected = true;\n result.confidence = 'medium';\n return result;\n }\n \n // Medium: Has 3+ typical directories but no strong markers\n if (foundDirs >= 3) {\n result.detected = true;\n result.confidence = 'medium';\n return result;\n }\n \n // Not detected\n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateShopifyConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Shopify theme framework configuration\n */\nexport async function generateShopifyConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // Core Liquid templates\n 'layout/**/*.liquid',\n 'sections/**/*.liquid',\n 'snippets/**/*.liquid',\n 'templates/**/*.liquid', // Matches any nesting level (e.g., templates/customers/account.liquid)\n 'templates/**/*.json', // JSON template definitions (Shopify 2.0+)\n \n // Theme editor blocks (Online Store 2.0)\n 'blocks/**/*.liquid',\n \n // Assets (CSS, JS with optional Liquid templating)\n 'assets/**/*.js',\n 'assets/**/*.js.liquid',\n 'assets/**/*.css',\n 'assets/**/*.css.liquid',\n 'assets/**/*.scss',\n 'assets/**/*.scss.liquid',\n \n // Configuration files\n 'config/*.json',\n \n // Locales (i18n)\n 'locales/*.json',\n \n // Documentation\n '*.md',\n 'docs/**/*.md',\n \n // Shopify-specific config files\n 'shopify.theme.toml',\n '.shopifyignore',\n ],\n exclude: [\n 'node_modules/**',\n 'dist/**',\n 'build/**',\n '.git/**',\n \n // Playwright/testing artifacts\n 'playwright-report/**',\n 'test-results/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Common frontend build outputs\n '.vite/**',\n '.nuxt/**',\n '.next/**',\n ],\n };\n}\n\n","import { FrameworkDetector } from './types.js';\nimport { nodejsDetector } from './nodejs/detector.js';\nimport { phpDetector } from './php/detector.js';\nimport { laravelDetector } from './laravel/detector.js';\nimport { shopifyDetector } from './shopify/detector.js';\n\n/**\n * Registry of all available framework detectors\n * Frameworks will be added as they are implemented\n * \n * Order doesn't matter for detection as priority system handles conflicts,\n * but listed here in order from generic to specific for clarity:\n * - Generic language detectors (Node.js, PHP)\n * - Specific framework detectors (Laravel, Shopify)\n */\nexport const frameworkDetectors: FrameworkDetector[] = [\n nodejsDetector,\n phpDetector,\n laravelDetector,\n shopifyDetector,\n];\n\n/**\n * Register a framework detector\n */\nexport function registerFramework(detector: FrameworkDetector): void {\n // Check if already registered\n const existing = frameworkDetectors.find(d => d.name === detector.name);\n if (existing) {\n console.warn(`Framework detector '${detector.name}' is already registered, skipping`);\n return;\n }\n \n frameworkDetectors.push(detector);\n}\n\n/**\n * Get a framework detector by name\n */\nexport function getFrameworkDetector(name: string): FrameworkDetector | undefined {\n return frameworkDetectors.find(d => d.name === name);\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport os from 'os';\nimport crypto from 'crypto';\nimport { configService } from '../config/service.js';\nimport { isGitRepo, getCurrentBranch, getCurrentCommit } from '../git/utils.js';\nimport { readVersionFile } from '../vectordb/version.js';\nimport { showCompactBanner } from '../utils/banner.js';\nimport { isModernConfig } from '../config/schema.js';\n\nexport async function statusCommand() {\n const rootDir = process.cwd();\n const projectName = path.basename(rootDir);\n \n // Use same hashing logic as VectorDB to show correct path\n const pathHash = crypto\n .createHash('md5')\n .update(rootDir)\n .digest('hex')\n .substring(0, 8);\n \n const indexPath = path.join(os.homedir(), '.lien', 'indices', `${projectName}-${pathHash}`);\n \n showCompactBanner();\n console.log(chalk.bold('Status\\n'));\n \n // Check if config exists\n const hasConfig = await configService.exists(rootDir);\n console.log(chalk.dim('Configuration:'), hasConfig ? chalk.green('✓ Found') : chalk.red('✗ Not initialized'));\n \n if (!hasConfig) {\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien init'), chalk.yellow('to initialize'));\n return;\n }\n \n // Check if index exists\n try {\n const stats = await fs.stat(indexPath);\n console.log(chalk.dim('Index location:'), indexPath);\n console.log(chalk.dim('Index status:'), chalk.green('✓ Exists'));\n \n // Try to get directory size\n try {\n const files = await fs.readdir(indexPath, { recursive: true });\n console.log(chalk.dim('Index files:'), files.length);\n } catch (e) {\n // Ignore\n }\n \n console.log(chalk.dim('Last modified:'), stats.mtime.toLocaleString());\n \n // Show version file info\n try {\n const version = await readVersionFile(indexPath);\n if (version > 0) {\n const versionDate = new Date(version);\n console.log(chalk.dim('Last reindex:'), versionDate.toLocaleString());\n }\n } catch {\n // Ignore\n }\n } catch (error) {\n console.log(chalk.dim('Index status:'), chalk.yellow('✗ Not indexed'));\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien index'), chalk.yellow('to index your codebase'));\n }\n \n // Load and show configuration settings\n try {\n const config = await configService.load(rootDir);\n \n console.log(chalk.bold('\\nFeatures:'));\n \n // Git detection status\n const isRepo = await isGitRepo(rootDir);\n if (config.gitDetection.enabled && isRepo) {\n console.log(chalk.dim('Git detection:'), chalk.green('✓ Enabled'));\n console.log(chalk.dim(' Poll interval:'), `${config.gitDetection.pollIntervalMs / 1000}s`);\n \n // Show current git state\n try {\n const branch = await getCurrentBranch(rootDir);\n const commit = await getCurrentCommit(rootDir);\n console.log(chalk.dim(' Current branch:'), branch);\n console.log(chalk.dim(' Current commit:'), commit.substring(0, 8));\n \n // Check if git state file exists\n const gitStateFile = path.join(indexPath, '.git-state.json');\n try {\n const gitStateContent = await fs.readFile(gitStateFile, 'utf-8');\n const gitState = JSON.parse(gitStateContent);\n if (gitState.branch !== branch || gitState.commit !== commit) {\n console.log(chalk.yellow(' ⚠️ Git state changed - will reindex on next serve'));\n }\n } catch {\n // Git state file doesn't exist yet\n }\n } catch {\n // Ignore git command errors\n }\n } else if (config.gitDetection.enabled && !isRepo) {\n console.log(chalk.dim('Git detection:'), chalk.yellow('Enabled (not a git repo)'));\n } else {\n console.log(chalk.dim('Git detection:'), chalk.gray('Disabled'));\n }\n \n // File watching status\n if (config.fileWatching.enabled) {\n console.log(chalk.dim('File watching:'), chalk.green('✓ Enabled'));\n console.log(chalk.dim(' Debounce:'), `${config.fileWatching.debounceMs}ms`);\n } else {\n console.log(chalk.dim('File watching:'), chalk.gray('Disabled'));\n console.log(chalk.dim(' Enable with:'), chalk.bold('lien serve --watch'));\n }\n \n // Indexing settings\n console.log(chalk.bold('\\nIndexing Settings:'));\n if (isModernConfig(config)) {\n console.log(chalk.dim('Concurrency:'), config.core.concurrency);\n console.log(chalk.dim('Batch size:'), config.core.embeddingBatchSize);\n console.log(chalk.dim('Chunk size:'), config.core.chunkSize);\n console.log(chalk.dim('Chunk overlap:'), config.core.chunkOverlap);\n }\n \n } catch (error) {\n console.log(chalk.yellow('\\nWarning: Could not load configuration'));\n }\n}\n\n","import chalk from 'chalk';\nimport { indexCodebase } from '../indexer/index.js';\nimport { showCompactBanner } from '../utils/banner.js';\n\nexport async function indexCommand(options: { watch?: boolean; verbose?: boolean; force?: boolean }) {\n showCompactBanner();\n \n try {\n // If force flag is set, clear the index and manifest first (clean slate)\n if (options.force) {\n const { VectorDB } = await import('../vectordb/lancedb.js');\n const { ManifestManager } = await import('../indexer/manifest.js');\n \n console.log(chalk.yellow('Clearing existing index and manifest...'));\n const vectorDB = new VectorDB(process.cwd());\n await vectorDB.initialize();\n await vectorDB.clear();\n \n // Also clear manifest\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.clear();\n \n console.log(chalk.green('✓ Index and manifest cleared\\n'));\n }\n \n await indexCodebase({\n rootDir: process.cwd(),\n verbose: options.verbose || false,\n force: options.force || false,\n });\n \n if (options.watch) {\n console.log(chalk.yellow('\\n⚠️ Watch mode not yet implemented'));\n // TODO: Implement file watching with chokidar\n }\n } catch (error) {\n console.error(chalk.red('Error during indexing:'), error);\n process.exit(1);\n }\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { startMCPServer } from '../mcp/server.js';\nimport { showBanner } from '../utils/banner.js';\n\nexport async function serveCommand(options: { port?: string; watch?: boolean; noWatch?: boolean; root?: string }) {\n const rootDir = options.root ? path.resolve(options.root) : process.cwd();\n \n try {\n // Validate root directory if --root was specified\n if (options.root) {\n try {\n const stats = await fs.stat(rootDir);\n if (!stats.isDirectory()) {\n console.error(chalk.red(`Error: --root path is not a directory: ${rootDir}`));\n process.exit(1);\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.error(chalk.red(`Error: --root directory does not exist: ${rootDir}`));\n } else if ((error as NodeJS.ErrnoException).code === 'EACCES') {\n console.error(chalk.red(`Error: --root directory is not accessible: ${rootDir}`));\n } else {\n console.error(chalk.red(`Error: Failed to access --root directory: ${rootDir}`));\n console.error(chalk.dim((error as Error).message));\n }\n process.exit(1);\n }\n }\n \n // Log to stderr since stdout is for MCP protocol\n showBanner();\n console.error(chalk.bold('Starting MCP server...\\n'));\n \n if (options.root) {\n console.error(chalk.dim(`Serving from: ${rootDir}\\n`));\n }\n \n // Handle deprecated --watch flag\n if (options.watch) {\n console.error(chalk.yellow('⚠️ --watch flag is deprecated (file watching is now default)'));\n console.error(chalk.dim(' Use --no-watch to disable file watching\\n'));\n }\n \n // Determine file watching state\n // Priority: --no-watch > --watch (deprecated) > config default\n const watch = options.noWatch ? false : options.watch ? true : undefined;\n \n await startMCPServer({\n rootDir,\n verbose: true,\n watch,\n });\n } catch (error) {\n console.error(chalk.red('Failed to start MCP server:'), error);\n process.exit(1);\n }\n}\n\n","import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { tools } from './tools.js';\nimport { toolHandlers } from './handlers/index.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { LocalEmbeddings } from '../embeddings/local.js';\nimport { GitStateTracker } from '../git/tracker.js';\nimport { indexMultipleFiles, indexSingleFile } from '../indexer/incremental.js';\nimport { configService } from '../config/service.js';\nimport { ManifestManager } from '../indexer/manifest.js';\nimport { isGitAvailable, isGitRepo } from '../git/utils.js';\nimport { FileWatcher } from '../watcher/index.js';\nimport { VERSION_CHECK_INTERVAL_MS } from '../constants.js';\nimport { LienError, LienErrorCode } from '../errors/index.js';\nimport type { ToolContext, LogFn, LogLevel } from './types.js';\n\n// Get version from package.json dynamically\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson: { name: string; version: string };\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\nexport interface MCPServerOptions {\n rootDir: string;\n verbose?: boolean;\n watch?: boolean;\n}\n\n/**\n * Initialize embeddings and vector database.\n */\nasync function initializeDatabase(\n rootDir: string,\n log: LogFn\n): Promise<{ embeddings: LocalEmbeddings; vectorDB: VectorDB }> {\n const embeddings = new LocalEmbeddings();\n const vectorDB = new VectorDB(rootDir);\n\n log('Loading embedding model...');\n await embeddings.initialize();\n\n log('Loading vector database...');\n await vectorDB.initialize();\n\n log('Embeddings and vector DB ready');\n return { embeddings, vectorDB };\n}\n\n/**\n * Run auto-indexing if needed (first run with no index).\n */\nasync function handleAutoIndexing(\n vectorDB: VectorDB,\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n log: LogFn\n): Promise<void> {\n const hasIndex = await vectorDB.hasData();\n\n if (!hasIndex && config.mcp.autoIndexOnFirstRun) {\n log('📦 No index found - running initial indexing...');\n log('⏱️ This may take 5-20 minutes depending on project size');\n\n try {\n const { indexCodebase } = await import('../indexer/index.js');\n await indexCodebase({ rootDir, verbose: true });\n log('✅ Initial indexing complete!');\n } catch (error) {\n log(`⚠️ Initial indexing failed: ${error}`, 'warning');\n log('You can manually run: lien index', 'warning');\n }\n } else if (!hasIndex) {\n log('⚠️ No index found. Auto-indexing is disabled in config.', 'warning');\n log('Run \"lien index\" to index your codebase.', 'warning');\n }\n}\n\n/**\n * Setup git detection and background polling.\n */\nasync function setupGitDetection(\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n vectorDB: VectorDB,\n embeddings: LocalEmbeddings,\n verbose: boolean | undefined,\n log: LogFn\n): Promise<{ gitTracker: GitStateTracker | null; gitPollInterval: NodeJS.Timeout | null }> {\n if (!config.gitDetection.enabled) {\n log('Git detection disabled by configuration');\n return { gitTracker: null, gitPollInterval: null };\n }\n\n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n\n if (!gitAvailable) {\n log('Git not available - git detection disabled');\n return { gitTracker: null, gitPollInterval: null };\n }\n if (!isRepo) {\n log('Not a git repository - git detection disabled');\n return { gitTracker: null, gitPollInterval: null };\n }\n\n log('✓ Detected git repository');\n const gitTracker = new GitStateTracker(rootDir, vectorDB.dbPath);\n\n // Check for git changes on startup\n try {\n log('Checking for git changes...');\n const changedFiles = await gitTracker.initialize();\n\n if (changedFiles && changedFiles.length > 0) {\n log(`🌿 Git changes detected: ${changedFiles.length} files changed`);\n const count = await indexMultipleFiles(changedFiles, vectorDB, embeddings, config, { verbose });\n log(`✓ Reindexed ${count} files`);\n } else {\n log('✓ Index is up to date with git state');\n }\n } catch (error) {\n log(`Failed to check git state on startup: ${error}`, 'warning');\n }\n\n // Start background polling\n log(`✓ Git detection enabled (checking every ${config.gitDetection.pollIntervalMs / 1000}s)`);\n\n const gitPollInterval = setInterval(async () => {\n try {\n const changedFiles = await gitTracker.detectChanges();\n if (changedFiles && changedFiles.length > 0) {\n log(`🌿 Git change detected: ${changedFiles.length} files changed`);\n indexMultipleFiles(changedFiles, vectorDB, embeddings, config, { verbose })\n .then(count => log(`✓ Background reindex complete: ${count} files`))\n .catch(error => log(`Background reindex failed: ${error}`, 'warning'));\n }\n } catch (error) {\n log(`Git detection check failed: ${error}`, 'warning');\n }\n }, config.gitDetection.pollIntervalMs);\n\n return { gitTracker, gitPollInterval };\n}\n\n/**\n * Setup file watching for real-time updates.\n */\nasync function setupFileWatching(\n watch: boolean | undefined,\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n vectorDB: VectorDB,\n embeddings: LocalEmbeddings,\n verbose: boolean | undefined,\n log: LogFn\n): Promise<FileWatcher | null> {\n const fileWatchingEnabled = watch !== undefined ? watch : config.fileWatching.enabled;\n if (!fileWatchingEnabled) return null;\n\n log('👀 Starting file watcher...');\n const fileWatcher = new FileWatcher(rootDir, config);\n\n try {\n await fileWatcher.start(async (event) => {\n const { type, filepath } = event;\n\n if (type === 'unlink') {\n log(`🗑️ File deleted: ${filepath}`);\n try {\n await vectorDB.deleteByFile(filepath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(filepath);\n log(`✓ Removed ${filepath} from index`);\n } catch (error) {\n log(`Failed to remove ${filepath}: ${error}`, 'warning');\n }\n } else {\n const action = type === 'add' ? 'added' : 'changed';\n log(`📝 File ${action}: ${filepath}`);\n indexSingleFile(filepath, vectorDB, embeddings, config, { verbose })\n .catch((error) => log(`Failed to reindex ${filepath}: ${error}`, 'warning'));\n }\n });\n\n log(`✓ File watching enabled (watching ${fileWatcher.getWatchedFiles().length} files)`);\n return fileWatcher;\n } catch (error) {\n log(`Failed to start file watcher: ${error}`, 'warning');\n return null;\n }\n}\n\n/**\n * Register tool call handler on the MCP server.\n */\nfunction registerToolCallHandler(\n server: Server,\n toolContext: ToolContext,\n log: LogFn\n): void {\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args } = request.params;\n log(`Handling tool call: ${name}`);\n\n const handler = toolHandlers[name];\n if (!handler) {\n const error = new LienError(\n `Unknown tool: ${name}`,\n LienErrorCode.INVALID_INPUT,\n { requestedTool: name, availableTools: tools.map(t => t.name) },\n 'medium', false, false\n );\n return { isError: true, content: [{ type: 'text' as const, text: JSON.stringify(error.toJSON(), null, 2) }] };\n }\n\n try {\n return await handler(args, toolContext);\n } catch (error) {\n if (error instanceof LienError) {\n return { isError: true, content: [{ type: 'text' as const, text: JSON.stringify(error.toJSON(), null, 2) }] };\n }\n console.error(`Unexpected error handling tool call ${name}:`, error);\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: error instanceof Error ? error.message : 'Unknown error', code: LienErrorCode.INTERNAL_ERROR, tool: name }, null, 2),\n }],\n };\n }\n });\n}\n\nexport async function startMCPServer(options: MCPServerOptions): Promise<void> {\n const { rootDir, verbose, watch } = options;\n \n // Early log function before server is ready (falls back to stderr)\n const earlyLog: LogFn = (message, level = 'info') => { \n if (verbose || level === 'warning' || level === 'error') {\n console.error(`[Lien MCP] [${level}] ${message}`); \n }\n };\n\n earlyLog('Initializing MCP server...');\n\n // Initialize core components\n const { embeddings, vectorDB } = await initializeDatabase(rootDir, earlyLog).catch(error => {\n console.error(`Failed to initialize: ${error}`);\n process.exit(1);\n });\n\n // Create MCP server with logging capability\n const server = new Server(\n { name: 'lien', version: packageJson.version },\n { capabilities: { tools: {}, logging: {} } }\n );\n\n // Create proper log function that uses MCP logging notifications\n // - In verbose mode: all levels (debug, info, notice, warning, error)\n // - In non-verbose mode: only warnings and errors\n const log: LogFn = (message, level: LogLevel = 'info') => {\n if (verbose || level === 'warning' || level === 'error') {\n server.sendLoggingMessage({\n level,\n logger: 'lien',\n data: message,\n }).catch(() => {\n // Fallback to stderr if MCP notification fails (e.g., not connected yet)\n console.error(`[Lien MCP] [${level}] ${message}`);\n });\n }\n };\n\n server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));\n\n // Version check helpers\n const checkAndReconnect = async () => {\n try {\n if (await vectorDB.checkVersion()) {\n log('Index version changed, reconnecting...');\n await vectorDB.reconnect();\n }\n } catch (error) {\n log(`Version check failed: ${error}`, 'warning');\n }\n };\n\n const getIndexMetadata = () => ({\n indexVersion: vectorDB.getCurrentVersion(),\n indexDate: vectorDB.getVersionDate(),\n });\n\n const versionCheckInterval = setInterval(checkAndReconnect, VERSION_CHECK_INTERVAL_MS);\n\n // Load config and create tool context\n const config = await configService.load(rootDir);\n const toolContext: ToolContext = { vectorDB, embeddings, config, rootDir, log, checkAndReconnect, getIndexMetadata };\n\n // Register handlers and setup features\n registerToolCallHandler(server, toolContext, log);\n await handleAutoIndexing(vectorDB, config, rootDir, log);\n const { gitPollInterval } = await setupGitDetection(config, rootDir, vectorDB, embeddings, verbose, log);\n const fileWatcher = await setupFileWatching(watch, config, rootDir, vectorDB, embeddings, verbose, log);\n\n // Cleanup handler\n const cleanup = async () => {\n log('Shutting down MCP server...');\n clearInterval(versionCheckInterval);\n if (gitPollInterval) clearInterval(gitPollInterval);\n if (fileWatcher) await fileWatcher.stop();\n process.exit(0);\n };\n\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n\n // Connect transport\n const transport = new StdioServerTransport();\n transport.onclose = () => { log('Transport closed'); cleanup().catch(() => process.exit(0)); };\n transport.onerror = (error) => log(`Transport error: ${error}`);\n\n await server.connect(transport);\n log('MCP server started and listening on stdio');\n}\n","import { z } from 'zod';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n/**\n * Convert a Zod schema to an MCP tool schema.\n * \n * This utility generates JSON Schema from Zod schemas for use in MCP tool definitions.\n * The resulting schema includes all validation rules and descriptions from the Zod schema.\n * \n * @param zodSchema - The Zod schema to convert\n * @param name - The tool name\n * @param description - The tool description\n * @returns MCP-compatible tool schema object\n * \n * @example\n * ```typescript\n * const SearchSchema = z.object({\n * query: z.string().min(3).describe(\"Search query\"),\n * limit: z.number().default(5)\n * });\n * \n * const tool = toMCPToolSchema(\n * SearchSchema,\n * 'semantic_search',\n * 'Search the codebase semantically'\n * );\n * ```\n */\nexport function toMCPToolSchema(\n zodSchema: z.ZodSchema,\n name: string,\n description: string\n) {\n return {\n name,\n description,\n inputSchema: zodToJsonSchema(zodSchema, {\n target: 'jsonSchema7',\n $refStrategy: 'none',\n }),\n };\n}\n\n","import { z } from 'zod';\n\n/**\n * Schema for semantic search tool input.\n * \n * Validates query strings and result limits for semantic code search.\n * Includes rich descriptions to guide AI assistants on proper usage.\n */\nexport const SemanticSearchSchema = z.object({\n query: z.string()\n .min(3, \"Query must be at least 3 characters\")\n .max(500, \"Query too long (max 500 characters)\")\n .describe(\n \"Natural language description of what you're looking for.\\n\\n\" +\n \"Use full sentences describing functionality, not exact names.\\n\\n\" +\n \"Good examples:\\n\" +\n \" - 'handles user authentication'\\n\" +\n \" - 'validates email format'\\n\" +\n \" - 'processes payment transactions'\\n\\n\" +\n \"Bad examples:\\n\" +\n \" - 'auth' (too vague)\\n\" +\n \" - 'validateEmail' (use grep for exact names)\"\n ),\n \n limit: z.number()\n .int()\n .min(1, \"Limit must be at least 1\")\n .max(50, \"Limit cannot exceed 50\")\n .default(5)\n .describe(\n \"Number of results to return.\\n\\n\" +\n \"Default: 5\\n\" +\n \"Increase to 10-15 for broad exploration.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for semantic search input\n */\nexport type SemanticSearchInput = z.infer<typeof SemanticSearchSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for find_similar tool input.\n * \n * Validates code snippets and result limits for similarity search.\n */\nexport const FindSimilarSchema = z.object({\n code: z.string()\n .min(10, \"Code snippet must be at least 10 characters\")\n .describe(\n \"Code snippet to find similar implementations for.\\n\\n\" +\n \"Provide a representative code sample that demonstrates the pattern \" +\n \"you want to find similar examples of in the codebase.\"\n ),\n \n limit: z.number()\n .int()\n .min(1, \"Limit must be at least 1\")\n .max(20, \"Limit cannot exceed 20\")\n .default(5)\n .describe(\n \"Number of similar code blocks to return.\\n\\n\" +\n \"Default: 5\"\n ),\n});\n\n/**\n * Inferred TypeScript type for find similar input\n */\nexport type FindSimilarInput = z.infer<typeof FindSimilarSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_files_context tool input.\n * \n * Validates file paths and context options for retrieving file-specific code chunks.\n * Supports both single file and batch operations.\n */\nexport const GetFilesContextSchema = z.object({\n filepaths: z.union([\n z.string().min(1, \"Filepath cannot be empty\"),\n z.array(z.string().min(1, \"Filepath cannot be empty\")).min(1, \"Array must contain at least one filepath\").max(50, \"Maximum 50 files per request\")\n ]).describe(\n \"Single filepath or array of filepaths (relative to workspace root).\\n\\n\" +\n \"Single file: 'src/components/Button.tsx'\\n\" +\n \"Multiple files: ['src/auth.ts', 'src/user.ts']\\n\\n\" +\n \"Maximum 50 files per request for batch operations.\"\n ),\n \n includeRelated: z.boolean()\n .default(true)\n .describe(\n \"Include semantically related chunks from nearby code.\\n\\n\" +\n \"Default: true\\n\\n\" +\n \"When enabled, also returns related code from other files that are \" +\n \"semantically similar to the target file's contents.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for file context input\n */\nexport type GetFilesContextInput = z.infer<typeof GetFilesContextSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for list_functions tool input.\n * \n * Validates pattern and language filters for symbol listing.\n */\nexport const ListFunctionsSchema = z.object({\n pattern: z.string()\n .optional()\n .describe(\n \"Regex pattern to match symbol names.\\n\\n\" +\n \"Examples:\\n\" +\n \" - '.*Controller.*' to find all Controllers\\n\" +\n \" - 'handle.*' to find handlers\\n\" +\n \" - '.*Service$' to find Services\\n\\n\" +\n \"If omitted, returns all symbols.\"\n ),\n \n language: z.string()\n .optional()\n .describe(\n \"Filter by programming language.\\n\\n\" +\n \"Examples: 'typescript', 'python', 'javascript', 'php'\\n\\n\" +\n \"If omitted, searches all languages.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for list functions input\n */\nexport type ListFunctionsInput = z.infer<typeof ListFunctionsSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_dependents tool input.\n * \n * Validates file paths and options for finding reverse dependencies\n * (which files import/depend on a given file).\n * \n * Limitations:\n * - Scans up to 10,000 code chunks. For very large codebases (>1M lines),\n * results may be incomplete. A warning is returned if the limit is reached.\n */\nexport const GetDependentsSchema = z.object({\n filepath: z.string()\n .min(1, \"Filepath cannot be empty\")\n .describe(\n \"Path to file to find dependents for (relative to workspace root).\\n\\n\" +\n \"Example: 'src/utils/validate.ts'\\n\\n\" +\n \"Returns all files that import or depend on this file.\\n\\n\" +\n \"Note: Scans up to 10,000 code chunks. For very large codebases,\\n\" +\n \"results may be incomplete (a warning will be included if truncated).\"\n ),\n \n depth: z.number()\n .int()\n .min(1)\n .max(1)\n .default(1)\n .describe(\n \"Depth of transitive dependencies. Only depth=1 (direct dependents) is currently supported.\\n\\n\" +\n \"1 = Direct dependents only\"\n ),\n});\n\n/**\n * Inferred TypeScript type for get_dependents input\n */\nexport type GetDependentsInput = z.infer<typeof GetDependentsSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_complexity tool input.\n * \n * Validates parameters for complexity analysis queries,\n * enabling tech debt analysis and refactoring prioritization.\n */\nexport const GetComplexitySchema = z.object({\n files: z.array(z.string().min(1, \"Filepath cannot be empty\"))\n .optional()\n .describe(\n \"Specific files to analyze. If omitted, analyzes entire codebase.\\n\\n\" +\n \"Example: ['src/auth.ts', 'src/api/user.ts']\"\n ),\n \n top: z.number()\n .int()\n .min(1, \"Top must be at least 1\")\n .max(50, \"Top cannot exceed 50\")\n .default(10)\n .describe(\n \"Return top N most complex functions. Default: 10\\n\\n\" +\n \"Use higher values to see more violations.\"\n ),\n \n threshold: z.number()\n .int()\n .min(1, \"Threshold must be at least 1\")\n .optional()\n .describe(\n \"Only return functions above this complexity threshold.\\n\\n\" +\n \"Note: Violations are first identified using the threshold from lien.config.json (default: 15). \" +\n \"This parameter filters those violations to show only items above the specified value. \" +\n \"Setting threshold below the config threshold will not show additional functions.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for get_complexity input\n */\nexport type GetComplexityInput = z.infer<typeof GetComplexitySchema>;\n\n","import { toMCPToolSchema } from './utils/zod-to-json-schema.js';\nimport {\n SemanticSearchSchema,\n FindSimilarSchema,\n GetFilesContextSchema,\n ListFunctionsSchema,\n GetDependentsSchema,\n GetComplexitySchema,\n} from './schemas/index.js';\n\n/**\n * MCP tool definitions with Zod-generated schemas.\n * \n * All schemas are automatically generated from Zod definitions,\n * providing type safety and rich validation at runtime.\n */\nexport const tools = [\n toMCPToolSchema(\n SemanticSearchSchema,\n 'semantic_search',\n `Search codebase by MEANING, not text. USE THIS INSTEAD OF grep/ripgrep for finding implementations, features, or understanding how code works.\n\nExamples:\n- \"Where is authentication handled?\" → semantic_search({ query: \"handles user authentication\" })\n- \"How does payment work?\" → semantic_search({ query: \"processes payment transactions\" })\n\nUse natural language describing what the code DOES, not function names. For exact string matching, use grep instead.\n\nResults include a relevance category (highly_relevant, relevant, loosely_related, not_relevant) for each match.`\n ),\n toMCPToolSchema(\n FindSimilarSchema,\n 'find_similar',\n `Find code structurally similar to a given snippet. Use for:\n- Ensuring consistency when adding new code\n- Finding duplicate implementations\n- Refactoring similar patterns together\n\nProvide at least 10 characters of code to match against. Results include a relevance category for each match.`\n ),\n toMCPToolSchema(\n GetFilesContextSchema,\n 'get_files_context',\n `Get context for one or more files including dependencies and test coverage.\n\nMANDATORY: Call this BEFORE editing any file. Accepts single path or array of paths.\n\nSingle file:\n get_files_context({ filepaths: \"src/auth.ts\" })\n \n Returns:\n {\n file: \"src/auth.ts\",\n chunks: [...],\n testAssociations: [\"src/__tests__/auth.test.ts\"]\n }\n\nMultiple files (batch):\n get_files_context({ filepaths: [\"src/auth.ts\", \"src/user.ts\"] })\n \n Returns:\n {\n files: {\n \"src/auth.ts\": {\n chunks: [...],\n testAssociations: [\"src/__tests__/auth.test.ts\"]\n },\n \"src/user.ts\": {\n chunks: [...],\n testAssociations: [\"src/__tests__/user.test.ts\"]\n }\n }\n }\n\nReturns for each file:\n- All chunks and related code\n- testAssociations: Array of test files that import this file (reverse dependency lookup)\n- Relevance scoring\n\nALWAYS check testAssociations before modifying source code.\nAfter changes, remind the user to run the associated tests.\n\nBatch calls are more efficient than multiple single-file calls.`\n ),\n toMCPToolSchema(\n ListFunctionsSchema,\n 'list_functions',\n `Fast symbol lookup by naming pattern. Use when searching by NAME, not behavior.\n\nExamples:\n- \"Show all controllers\" → list_functions({ pattern: \".*Controller.*\" })\n- \"Find service classes\" → list_functions({ pattern: \".*Service$\" })\n\n10x faster than semantic_search for structural/architectural queries. Use semantic_search instead when searching by what code DOES.`\n ),\n toMCPToolSchema(\n GetDependentsSchema,\n 'get_dependents',\n `Find all code that depends on a file (reverse dependency lookup). Use for impact analysis:\n- \"What breaks if I change this?\"\n- \"Is this safe to delete?\"\n- \"What imports this module?\"\n\nReturns:\n- List of files that import the target\n- Risk level (low/medium/high/critical) based on dependent count and complexity\n\nExample: get_dependents({ filepath: \"src/utils/validate.ts\" })`\n ),\n toMCPToolSchema(\n GetComplexitySchema,\n 'get_complexity',\n `Get complexity analysis for files or the entire codebase.\n\nAnalyzes multiple complexity metrics:\n- **Test paths**: Number of test cases needed for full coverage (cyclomatic)\n- **Mental load**: How hard to follow - penalizes nesting (cognitive)\n- **Time to understand**: Estimated reading time based on Halstead effort\n- **Estimated bugs**: Predicted bug count based on Halstead volume\n\nUse for tech debt analysis and refactoring prioritization:\n- \"What are the most complex functions?\"\n- \"Show me tech debt hotspots\"\n- \"What should I refactor?\"\n\nExamples:\n get_complexity({ top: 10 })\n get_complexity({ files: [\"src/auth.ts\", \"src/api/user.ts\"] })\n get_complexity({ threshold: 15 })\n\nReturns violations with metricType ('cyclomatic', 'cognitive', 'halstead_effort',\nor 'halstead_bugs'), risk levels, and dependent counts.\nHuman-readable output: \"23 (needs ~23 tests)\", \"🧠 45\", \"~2h 30m\", \"2.27 bugs\".`\n ),\n];","import { ZodSchema, ZodError } from 'zod';\nimport { LienError, LienErrorCode } from '../../errors/index.js';\n\n/**\n * Wrap a tool handler with Zod validation and error handling.\n * \n * This utility provides automatic:\n * - Input validation using Zod schemas\n * - Type-safe handler execution with inferred types\n * - Consistent error formatting for validation, Lien, and unexpected errors\n * - MCP-compatible response structure\n * \n * @param schema - Zod schema to validate tool inputs against\n * @param handler - Tool handler function that receives validated inputs\n * @returns Wrapped handler that validates inputs and handles errors\n * \n * @example\n * ```typescript\n * const SearchSchema = z.object({\n * query: z.string().min(3),\n * limit: z.number().default(5)\n * });\n * \n * const searchHandler = wrapToolHandler(\n * SearchSchema,\n * async (args) => {\n * // args is fully typed: { query: string; limit: number }\n * const results = await search(args.query, args.limit);\n * return { results };\n * }\n * );\n * \n * // Use in MCP server\n * return await searchHandler(request.params.arguments);\n * ```\n */\nexport function wrapToolHandler<T>(\n schema: ZodSchema<T>,\n handler: (validated: T) => Promise<any>\n) {\n return async (args: unknown) => {\n try {\n // Validate input with Zod\n const validated = schema.parse(args);\n \n // Execute handler with validated, typed input\n const result = await handler(validated);\n \n // Return MCP-compatible success response\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(result, null, 2),\n }],\n };\n \n } catch (error) {\n // Handle Zod validation errors\n if (error instanceof ZodError) {\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: 'Invalid parameters',\n code: LienErrorCode.INVALID_INPUT,\n details: error.errors.map(e => ({\n field: e.path.join('.'),\n message: e.message,\n })),\n }, null, 2),\n }],\n };\n }\n \n // Handle known Lien errors\n if (error instanceof LienError) {\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify(error.toJSON(), null, 2),\n }],\n };\n }\n \n // Handle unexpected errors\n console.error('Unexpected error in tool handler:', error);\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: error instanceof Error ? error.message : 'Unknown error',\n code: LienErrorCode.INTERNAL_ERROR,\n }, null, 2),\n }],\n };\n }\n };\n}\n\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { SemanticSearchSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle semantic_search tool calls.\n * Searches the codebase by meaning using embeddings.\n */\nexport async function handleSemanticSearch(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n SemanticSearchSchema,\n async (validatedArgs) => {\n log(`Searching for: \"${validatedArgs.query}\"`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n const queryEmbedding = await embeddings.embed(validatedArgs.query);\n const results = await vectorDB.search(queryEmbedding, validatedArgs.limit, validatedArgs.query);\n\n log(`Found ${results.length} results`);\n\n return {\n indexInfo: getIndexMetadata(),\n results,\n };\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { FindSimilarSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle find_similar tool calls.\n * Finds code structurally similar to a given snippet.\n */\nexport async function handleFindSimilar(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n FindSimilarSchema,\n async (validatedArgs) => {\n log(`Finding similar code...`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n const codeEmbedding = await embeddings.embed(validatedArgs.code);\n // Pass code as query for relevance boosting\n const results = await vectorDB.search(codeEmbedding, validatedArgs.limit, validatedArgs.code);\n\n log(`Found ${results.length} similar chunks`);\n\n return {\n indexInfo: getIndexMetadata(),\n results,\n };\n }\n )(args);\n}\n","/**\n * Shared path matching utilities for dependency analysis.\n * \n * These functions handle path normalization and matching logic used by\n * the get_dependents tool to find reverse dependencies.\n */\n\n/**\n * Normalizes a file path for comparison.\n * \n * - Removes quotes and trims whitespace\n * - Converts backslashes to forward slashes\n * - Strips file extensions (.ts, .tsx, .js, .jsx)\n * - Converts absolute paths to relative (if within workspace root)\n * \n * @param path - The path to normalize\n * @param workspaceRoot - The workspace root directory (normalized with forward slashes)\n * @returns Normalized path\n */\nexport function normalizePath(path: string, workspaceRoot: string): string {\n let normalized = path.replace(/['\"]/g, '').trim().replace(/\\\\/g, '/');\n \n // Normalize extensions: .ts/.tsx/.js/.jsx → all treated as equivalent\n // This handles TypeScript's ESM requirement of .js imports for .ts files\n normalized = normalized.replace(/\\.(ts|tsx|js|jsx)$/, '');\n \n // Normalize to relative path if it starts with workspace root\n if (normalized.startsWith(workspaceRoot + '/')) {\n normalized = normalized.substring(workspaceRoot.length + 1);\n }\n \n return normalized;\n}\n\n/**\n * Checks if a pattern matches at path component boundaries.\n * \n * Ensures matches occur at proper boundaries (/, .) to avoid false positives like:\n * - \"logger\" matching \"logger-utils\" ❌\n * - \"src/logger\" matching \"src/logger-service\" ❌\n * \n * @param str - The string to search in\n * @param pattern - The pattern to search for\n * @returns True if pattern matches at a boundary\n */\nexport function matchesAtBoundary(str: string, pattern: string): boolean {\n const index = str.indexOf(pattern);\n if (index === -1) return false;\n \n // Check character before match (must be start or path separator)\n const charBefore = index > 0 ? str[index - 1] : '/';\n if (charBefore !== '/' && index !== 0) return false;\n \n // Check character after match (must be end or path separator)\n // Extensions are already stripped during normalization, so we only need to check for '/' as a valid path separator\n const endIndex = index + pattern.length;\n if (endIndex === str.length) return true;\n const charAfter = str[endIndex];\n return charAfter === '/';\n}\n\n/**\n * Determines if an import path matches a target file path.\n * \n * Handles various matching strategies:\n * 1. Exact match\n * 2. Target path appears in import (at boundaries)\n * 3. Import path appears in target (at boundaries)\n * 4. Relative imports (./logger vs src/utils/logger)\n * \n * @param normalizedImport - Normalized import path\n * @param normalizedTarget - Normalized target file path\n * @returns True if the import matches the target file\n */\nexport function matchesFile(normalizedImport: string, normalizedTarget: string): boolean {\n // Exact match\n if (normalizedImport === normalizedTarget) return true;\n \n // Strategy 1: Check if target path appears in import at path boundaries\n if (matchesAtBoundary(normalizedImport, normalizedTarget)) {\n return true;\n }\n \n // Strategy 2: Check if import path appears in target (for longer target paths)\n if (matchesAtBoundary(normalizedTarget, normalizedImport)) {\n return true;\n }\n \n // Strategy 3: Handle relative imports (./logger vs src/utils/logger)\n // Remove leading ./ and ../ from import\n const cleanedImport = normalizedImport.replace(/^(\\.\\.?\\/)+/, '');\n if (matchesAtBoundary(cleanedImport, normalizedTarget) || \n matchesAtBoundary(normalizedTarget, cleanedImport)) {\n return true;\n }\n \n return false;\n}\n\n/**\n * Gets a canonical path representation (relative to workspace, with extension).\n * \n * @param filepath - The file path to canonicalize\n * @param workspaceRoot - The workspace root directory (normalized with forward slashes)\n * @returns Canonical path\n */\nexport function getCanonicalPath(filepath: string, workspaceRoot: string): string {\n let canonical = filepath.replace(/\\\\/g, '/');\n if (canonical.startsWith(workspaceRoot + '/')) {\n canonical = canonical.substring(workspaceRoot.length + 1);\n }\n return canonical;\n}\n\n/**\n * Determines if a file is a test file based on naming conventions.\n * \n * Uses precise regex patterns to avoid false positives:\n * - Files with .test. or .spec. extensions (e.g., foo.test.ts, bar.spec.js)\n * - Files in test/, tests/, or __tests__/ directories\n * \n * Avoids false positives like:\n * - contest.ts (contains \".test.\" but isn't a test)\n * - latest/config.ts (contains \"/test/\" but isn't a test)\n * \n * @param filepath - The file path to check\n * @returns True if the file is a test file\n */\nexport function isTestFile(filepath: string): boolean {\n return /\\.(test|spec)\\.[^/]+$/.test(filepath) ||\n /(^|[/\\\\])(test|tests|__tests__)[/\\\\]/.test(filepath);\n}\n\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetFilesContextSchema } from '../schemas/index.js';\nimport { normalizePath, matchesFile, getCanonicalPath, isTestFile } from '../utils/path-matching.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Maximum number of chunks to scan for test association analysis.\n * Larger codebases may have incomplete results if they exceed this limit.\n */\nconst SCAN_LIMIT = 10000;\n\n/**\n * Handle get_files_context tool calls.\n * Gets context for one or more files including dependencies and test coverage.\n */\nexport async function handleGetFilesContext(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetFilesContextSchema,\n async (validatedArgs) => {\n // Normalize input: convert single string to array\n const filepaths = Array.isArray(validatedArgs.filepaths)\n ? validatedArgs.filepaths\n : [validatedArgs.filepaths];\n\n const isSingleFile = !Array.isArray(validatedArgs.filepaths);\n\n log(`Getting context for: ${filepaths.join(', ')}`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n // Compute workspace root for path matching\n const workspaceRoot = process.cwd().replace(/\\\\/g, '/');\n\n // Batch embedding calls for all filepaths at once to reduce latency\n const fileEmbeddings = await Promise.all(filepaths.map(fp => embeddings.embed(fp)));\n\n // Batch all initial file searches in parallel\n const allFileSearches = await Promise.all(\n fileEmbeddings.map((embedding, i) =>\n vectorDB.search(embedding, 50, filepaths[i])\n )\n );\n\n // Filter results to only include chunks from each target file\n // Use exact matching with getCanonicalPath to avoid false positives\n const fileChunksMap = filepaths.map((filepath, i) => {\n const allResults = allFileSearches[i];\n const targetCanonical = getCanonicalPath(filepath, workspaceRoot);\n\n return allResults.filter(r => {\n const chunkCanonical = getCanonicalPath(r.metadata.file, workspaceRoot);\n return chunkCanonical === targetCanonical;\n });\n });\n\n // Batch related chunk operations if includeRelated is true\n let relatedChunksMap: any[][] = [];\n if (validatedArgs.includeRelated) {\n // Get files that have chunks (need first chunk for related search)\n const filesWithChunks = fileChunksMap\n .map((chunks, i) => ({ chunks, filepath: filepaths[i], index: i }))\n .filter(({ chunks }) => chunks.length > 0);\n\n if (filesWithChunks.length > 0) {\n // Batch embedding calls for all first chunks\n const relatedEmbeddings = await Promise.all(\n filesWithChunks.map(({ chunks }) => embeddings.embed(chunks[0].content))\n );\n\n // Batch all related chunk searches\n const relatedSearches = await Promise.all(\n relatedEmbeddings.map((embedding, i) =>\n vectorDB.search(embedding, 5, filesWithChunks[i].chunks[0].content)\n )\n );\n\n // Map back to original indices\n relatedChunksMap = Array.from({ length: filepaths.length }, () => []);\n filesWithChunks.forEach(({ filepath, index }, i) => {\n const related = relatedSearches[i];\n const targetCanonical = getCanonicalPath(filepath, workspaceRoot);\n // Filter out chunks from the same file using exact matching\n relatedChunksMap[index] = related.filter(r => {\n const chunkCanonical = getCanonicalPath(r.metadata.file, workspaceRoot);\n return chunkCanonical !== targetCanonical;\n });\n });\n }\n }\n\n // Compute test associations for each file\n // Scan once for all files to avoid repeated database queries (performance optimization)\n const allChunks = await vectorDB.scanWithFilter({ limit: SCAN_LIMIT });\n\n // Warn if we hit the limit (similar to get_dependents tool)\n if (allChunks.length === SCAN_LIMIT) {\n log(`Scanned ${SCAN_LIMIT} chunks (limit reached). Test associations may be incomplete for large codebases.`, 'warning');\n }\n\n // Path normalization cache to avoid repeated string operations\n const pathCache = new Map<string, string>();\n const normalizePathCached = (path: string): string => {\n if (pathCache.has(path)) return pathCache.get(path)!;\n const normalized = normalizePath(path, workspaceRoot);\n pathCache.set(path, normalized);\n return normalized;\n };\n\n // Compute test associations for each file using the same scan result\n const testAssociationsMap = filepaths.map((filepath) => {\n const normalizedTarget = normalizePathCached(filepath);\n\n // Find chunks that:\n // 1. Are from test files\n // 2. Import the target file\n const testFiles = new Set<string>();\n for (const chunk of allChunks) {\n const chunkFile = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n\n // Skip if not a test file\n if (!isTestFile(chunkFile)) continue;\n\n // Check if this test file imports the target\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n if (matchesFile(normalizedImport, normalizedTarget)) {\n testFiles.add(chunkFile);\n break;\n }\n }\n }\n\n return Array.from(testFiles);\n });\n\n // Combine file chunks with related chunks and test associations\n const filesData: Record<string, { chunks: any[]; testAssociations: string[] }> = {};\n filepaths.forEach((filepath, i) => {\n const fileChunks = fileChunksMap[i];\n const relatedChunks = relatedChunksMap[i] || [];\n\n // Deduplicate chunks (by canonical file path + line range)\n // Use canonical paths to avoid duplicates from absolute vs relative paths\n const seenChunks = new Set<string>();\n const dedupedChunks = [...fileChunks, ...relatedChunks].filter(chunk => {\n const canonicalFile = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n const chunkId = `${canonicalFile}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (seenChunks.has(chunkId)) return false;\n seenChunks.add(chunkId);\n return true;\n });\n\n filesData[filepath] = {\n chunks: dedupedChunks,\n testAssociations: testAssociationsMap[i],\n };\n });\n\n log(`Found ${Object.values(filesData).reduce((sum, f) => sum + f.chunks.length, 0)} total chunks`);\n\n // Return format depends on single vs multi file\n if (isSingleFile) {\n // Single file: return old format for backward compatibility\n const filepath = filepaths[0];\n return {\n indexInfo: getIndexMetadata(),\n file: filepath,\n chunks: filesData[filepath].chunks,\n testAssociations: filesData[filepath].testAssociations,\n };\n } else {\n // Multiple files: return new format\n return {\n indexInfo: getIndexMetadata(),\n files: filesData,\n };\n }\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { ListFunctionsSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle list_functions tool calls.\n * Fast symbol lookup by naming pattern.\n */\nexport async function handleListFunctions(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n ListFunctionsSchema,\n async (validatedArgs) => {\n log('Listing functions with symbol metadata...');\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n let results;\n let usedMethod = 'symbols';\n\n try {\n // Try using symbol-based query first (v0.5.0+)\n results = await vectorDB.querySymbols({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n\n // If no results and pattern was provided, it might be an old index\n // Fall back to content scanning\n if (results.length === 0 && (validatedArgs.language || validatedArgs.pattern)) {\n log('No symbol results, falling back to content scan...');\n results = await vectorDB.scanWithFilter({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n usedMethod = 'content';\n }\n } catch (error) {\n // If querySymbols fails (e.g., old index without symbol fields), fall back\n log(`Symbol query failed, falling back to content scan: ${error}`);\n results = await vectorDB.scanWithFilter({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n usedMethod = 'content';\n }\n\n log(`Found ${results.length} matches using ${usedMethod} method`);\n\n return {\n indexInfo: getIndexMetadata(),\n method: usedMethod,\n results,\n note: usedMethod === 'content'\n ? 'Using content search. Run \"lien reindex\" to enable faster symbol-based queries.'\n : undefined,\n };\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetDependentsSchema } from '../schemas/index.js';\nimport { normalizePath, matchesFile, getCanonicalPath, isTestFile } from '../utils/path-matching.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\nimport type { SearchResult } from '../../vectordb/types.js';\n\n/**\n * Complexity metrics for a single dependent file.\n */\ninterface FileComplexity {\n filepath: string;\n avgComplexity: number;\n maxComplexity: number;\n complexityScore: number; // Sum of all complexities\n chunksWithComplexity: number;\n}\n\n/**\n * Aggregate complexity metrics for all dependents.\n */\ninterface ComplexityMetrics {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n highComplexityDependents: Array<{\n filepath: string;\n maxComplexity: number;\n avgComplexity: number;\n }>;\n complexityRiskBoost: 'low' | 'medium' | 'high' | 'critical';\n}\n\n/**\n * Risk level thresholds for dependent count.\n * Based on impact analysis: more dependents = higher risk of breaking changes.\n */\nconst DEPENDENT_COUNT_THRESHOLDS = {\n LOW: 5, // Few dependents, safe to change\n MEDIUM: 15, // Moderate impact, review dependents\n HIGH: 30, // High impact, careful planning needed\n} as const;\n\n/**\n * Complexity thresholds for risk assessment.\n * Based on cyclomatic complexity: higher complexity = harder to change safely.\n */\nconst COMPLEXITY_THRESHOLDS = {\n HIGH_COMPLEXITY_DEPENDENT: 10, // Individual file is complex\n CRITICAL_AVG: 15, // Average complexity indicates systemic complexity\n CRITICAL_MAX: 25, // Peak complexity indicates hotspot\n HIGH_AVG: 10, // Moderately complex on average\n HIGH_MAX: 20, // Some complex functions exist\n MEDIUM_AVG: 6, // Slightly above simple code\n MEDIUM_MAX: 15, // Occasional branching\n} as const;\n\n/**\n * Maximum number of chunks to scan for dependency analysis.\n * Larger codebases may have incomplete results if they exceed this limit.\n */\nconst SCAN_LIMIT = 10000;\n\n/** Risk level ordering for comparison */\nconst RISK_ORDER = { low: 0, medium: 1, high: 2, critical: 3 } as const;\ntype RiskLevel = keyof typeof RISK_ORDER;\n\n/**\n * Build import-to-chunk index for O(n) instead of O(n*m) lookup.\n */\nfunction buildImportIndex(\n allChunks: SearchResult[],\n normalizePathCached: (path: string) => string\n): Map<string, SearchResult[]> {\n const importIndex = new Map<string, SearchResult[]>();\n \n for (const chunk of allChunks) {\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n if (!importIndex.has(normalizedImport)) {\n importIndex.set(normalizedImport, []);\n }\n importIndex.get(normalizedImport)!.push(chunk);\n }\n }\n \n return importIndex;\n}\n\n/**\n * Find dependent chunks using direct lookup and fuzzy matching.\n */\nfunction findDependentChunks(\n importIndex: Map<string, SearchResult[]>,\n normalizedTarget: string\n): SearchResult[] {\n const dependentChunks: SearchResult[] = [];\n const seenChunkIds = new Set<string>();\n\n const addChunk = (chunk: SearchResult) => {\n const chunkId = `${chunk.metadata.file}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (!seenChunkIds.has(chunkId)) {\n dependentChunks.push(chunk);\n seenChunkIds.add(chunkId);\n }\n };\n\n // Direct index lookup (fastest path)\n if (importIndex.has(normalizedTarget)) {\n for (const chunk of importIndex.get(normalizedTarget)!) {\n addChunk(chunk);\n }\n }\n\n // Fuzzy match for relative imports and path variations\n for (const [normalizedImport, chunks] of importIndex.entries()) {\n if (normalizedImport !== normalizedTarget && matchesFile(normalizedImport, normalizedTarget)) {\n for (const chunk of chunks) {\n addChunk(chunk);\n }\n }\n }\n\n return dependentChunks;\n}\n\n/**\n * Calculate complexity metrics for each file from its chunks.\n */\nfunction calculateFileComplexities(\n chunksByFile: Map<string, SearchResult[]>\n): FileComplexity[] {\n const fileComplexities: FileComplexity[] = [];\n\n for (const [filepath, chunks] of chunksByFile.entries()) {\n const complexities = chunks\n .map(c => c.metadata.complexity)\n .filter((c): c is number => typeof c === 'number' && c > 0);\n\n if (complexities.length > 0) {\n const sum = complexities.reduce((a, b) => a + b, 0);\n fileComplexities.push({\n filepath,\n avgComplexity: Math.round((sum / complexities.length) * 10) / 10,\n maxComplexity: Math.max(...complexities),\n complexityScore: sum,\n chunksWithComplexity: complexities.length,\n });\n }\n }\n\n return fileComplexities;\n}\n\n/**\n * Calculate overall complexity metrics from per-file complexities.\n */\nfunction calculateOverallComplexityMetrics(\n fileComplexities: FileComplexity[]\n): ComplexityMetrics {\n if (fileComplexities.length === 0) {\n return {\n averageComplexity: 0,\n maxComplexity: 0,\n filesWithComplexityData: 0,\n highComplexityDependents: [],\n complexityRiskBoost: 'low',\n };\n }\n\n const allAvgs = fileComplexities.map(f => f.avgComplexity);\n const allMaxes = fileComplexities.map(f => f.maxComplexity);\n const totalAvg = allAvgs.reduce((a, b) => a + b, 0) / allAvgs.length;\n const globalMax = Math.max(...allMaxes);\n\n const highComplexityDependents = fileComplexities\n .filter(f => f.maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_COMPLEXITY_DEPENDENT)\n .sort((a, b) => b.maxComplexity - a.maxComplexity)\n .slice(0, 5)\n .map(f => ({ filepath: f.filepath, maxComplexity: f.maxComplexity, avgComplexity: f.avgComplexity }));\n\n const complexityRiskBoost = calculateComplexityRiskBoost(totalAvg, globalMax);\n\n return {\n averageComplexity: Math.round(totalAvg * 10) / 10,\n maxComplexity: globalMax,\n filesWithComplexityData: fileComplexities.length,\n highComplexityDependents,\n complexityRiskBoost,\n };\n}\n\n/**\n * Calculate complexity-based risk boost level.\n */\nfunction calculateComplexityRiskBoost(avgComplexity: number, maxComplexity: number): RiskLevel {\n if (avgComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_MAX) {\n return 'critical';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.HIGH_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_MAX) {\n return 'high';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_MAX) {\n return 'medium';\n }\n return 'low';\n}\n\n/**\n * Calculate risk level based on dependent count and complexity.\n */\nfunction calculateRiskLevel(dependentCount: number, complexityRiskBoost: RiskLevel): RiskLevel {\n let riskLevel: RiskLevel =\n dependentCount === 0 ? 'low' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.LOW ? 'low' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.MEDIUM ? 'medium' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.HIGH ? 'high' : 'critical';\n\n // Boost if complexity risk is higher\n if (RISK_ORDER[complexityRiskBoost] > RISK_ORDER[riskLevel]) {\n riskLevel = complexityRiskBoost;\n }\n\n return riskLevel;\n}\n\n/**\n * Handle get_dependents tool calls.\n * Finds all code that depends on a file (reverse dependency lookup).\n */\nexport async function handleGetDependents(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetDependentsSchema,\n async (validatedArgs) => {\n log(`Finding dependents of: ${validatedArgs.filepath}`);\n await checkAndReconnect();\n\n const allChunks = await vectorDB.scanWithFilter({ limit: SCAN_LIMIT });\n const hitLimit = allChunks.length === SCAN_LIMIT;\n if (hitLimit) {\n log(`Scanned ${SCAN_LIMIT} chunks (limit reached). Results may be incomplete.`, 'warning');\n }\n log(`Scanning ${allChunks.length} chunks for imports...`);\n\n const workspaceRoot = process.cwd().replace(/\\\\/g, '/');\n const pathCache = new Map<string, string>();\n const normalizePathCached = (path: string): string => {\n if (!pathCache.has(path)) pathCache.set(path, normalizePath(path, workspaceRoot));\n return pathCache.get(path)!;\n };\n\n // Build index and find dependents\n const importIndex = buildImportIndex(allChunks, normalizePathCached);\n const normalizedTarget = normalizePathCached(validatedArgs.filepath);\n const dependentChunks = findDependentChunks(importIndex, normalizedTarget);\n\n // Group by canonical file path\n const chunksByFile = new Map<string, typeof dependentChunks>();\n for (const chunk of dependentChunks) {\n const canonical = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n const existing = chunksByFile.get(canonical) || [];\n existing.push(chunk);\n chunksByFile.set(canonical, existing);\n }\n\n // Calculate metrics\n const fileComplexities = calculateFileComplexities(chunksByFile);\n const complexityMetrics = calculateOverallComplexityMetrics(fileComplexities);\n\n const uniqueFiles = Array.from(chunksByFile.keys()).map(filepath => ({\n filepath,\n isTestFile: isTestFile(filepath),\n }));\n\n const riskLevel = calculateRiskLevel(uniqueFiles.length, complexityMetrics.complexityRiskBoost);\n log(`Found ${uniqueFiles.length} dependent files (risk: ${riskLevel}${complexityMetrics.filesWithComplexityData > 0 ? ', complexity-boosted' : ''})`);\n\n return {\n indexInfo: getIndexMetadata(),\n filepath: validatedArgs.filepath,\n dependentCount: uniqueFiles.length,\n riskLevel,\n dependents: uniqueFiles,\n complexityMetrics,\n note: hitLimit ? `Warning: Scanned ${SCAN_LIMIT} chunks (limit reached). Results may be incomplete.` : undefined,\n };\n }\n )(args);\n}\n","import collect from 'collect.js';\nimport { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetComplexitySchema } from '../schemas/index.js';\nimport { ComplexityAnalyzer } from '../../insights/complexity-analyzer.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\nimport type { ComplexityViolation, FileComplexityData } from '../../insights/types.js';\n\n/**\n * Transform a violation with file-level metadata for API response\n */\nfunction transformViolation(v: ComplexityViolation, fileData: FileComplexityData) {\n return {\n filepath: v.filepath,\n symbolName: v.symbolName,\n symbolType: v.symbolType,\n startLine: v.startLine,\n endLine: v.endLine,\n complexity: v.complexity,\n metricType: v.metricType,\n threshold: v.threshold,\n severity: v.severity,\n language: v.language,\n message: v.message,\n dependentCount: fileData.dependentCount || 0,\n riskLevel: fileData.riskLevel,\n ...(v.halsteadDetails && { halsteadDetails: v.halsteadDetails }),\n };\n}\n\n/**\n * Handle get_complexity tool calls.\n * Analyzes complexity for files or the entire codebase.\n */\nexport async function handleGetComplexity(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, config, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetComplexitySchema,\n async (validatedArgs) => {\n log('Analyzing complexity...');\n await checkAndReconnect();\n\n const analyzer = new ComplexityAnalyzer(vectorDB, config);\n const report = await analyzer.analyze(validatedArgs.files);\n log(`Analyzed ${report.summary.filesAnalyzed} files`);\n\n // Transform violations using collect.js\n type TransformedViolation = ReturnType<typeof transformViolation>;\n const allViolations: TransformedViolation[] = collect(Object.entries(report.files))\n .flatMap(([/* filepath unused */, fileData]) => \n fileData.violations.map(v => transformViolation(v, fileData))\n )\n .sortByDesc('complexity')\n .all() as unknown as TransformedViolation[];\n\n // Apply custom threshold filter if provided\n const violations = validatedArgs.threshold !== undefined\n ? allViolations.filter(v => v.complexity >= validatedArgs.threshold!)\n : allViolations;\n\n const topViolations = violations.slice(0, validatedArgs.top);\n\n // Calculate severity counts - countBy returns { error?: number, warning?: number }\n const bySeverity = collect(violations).countBy('severity').all() as { error?: number; warning?: number };\n\n return {\n indexInfo: getIndexMetadata(),\n summary: {\n filesAnalyzed: report.summary.filesAnalyzed,\n avgComplexity: report.summary.avgComplexity,\n maxComplexity: report.summary.maxComplexity,\n violationCount: violations.length,\n bySeverity: {\n error: bySeverity['error'] || 0,\n warning: bySeverity['warning'] || 0,\n },\n },\n violations: topViolations,\n };\n }\n )(args);\n}\n","/**\n * Complexity analysis types for code quality insights\n */\n\n/**\n * Risk level ordering for comparison operations.\n * Higher value = higher risk.\n */\nexport const RISK_ORDER = { low: 0, medium: 1, high: 2, critical: 3 } as const;\n\n/**\n * Risk level type derived from RISK_ORDER keys\n */\nexport type RiskLevel = keyof typeof RISK_ORDER;\n\n/**\n * Type of complexity metric being measured\n */\nexport type ComplexityMetricType = 'cyclomatic' | 'cognitive' | 'halstead_effort' | 'halstead_bugs';\n\n/**\n * Halstead metric details for Halstead-type violations\n */\nexport interface HalsteadDetails {\n volume: number;\n difficulty: number;\n effort: number;\n bugs: number;\n}\n\nexport interface ComplexityViolation {\n filepath: string;\n startLine: number;\n endLine: number;\n symbolName: string;\n symbolType: 'function' | 'method' | 'class' | 'file';\n language: string;\n complexity: number;\n threshold: number;\n severity: 'warning' | 'error';\n message: string;\n /** Type of complexity metric (cyclomatic vs cognitive vs halstead) */\n metricType: ComplexityMetricType;\n /** Halstead-specific details when metricType is halstead_* */\n halsteadDetails?: HalsteadDetails;\n}\n\nexport interface FileComplexityData {\n violations: ComplexityViolation[];\n dependents: string[];\n dependentCount?: number;\n /** Test files associated with this source file. TODO: Populate when test-to-code mapping is implemented */\n testAssociations: string[];\n riskLevel: RiskLevel;\n dependentComplexityMetrics?: {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n };\n}\n\nexport interface ComplexityReport {\n summary: {\n filesAnalyzed: number;\n totalViolations: number;\n bySeverity: { error: number; warning: number };\n avgComplexity: number;\n maxComplexity: number;\n };\n files: Record<string, FileComplexityData>;\n}\n\n","import { SearchResult } from '../vectordb/types.js';\nimport { normalizePath, getCanonicalPath, matchesFile, isTestFile } from '../mcp/utils/path-matching.js';\nimport { RISK_ORDER, RiskLevel } from '../insights/types.js';\n\n/**\n * Risk level thresholds for dependent count.\n * Based on impact analysis: more dependents = higher risk of breaking changes.\n */\nexport const DEPENDENT_COUNT_THRESHOLDS = {\n LOW: 5, // Few dependents, safe to change\n MEDIUM: 15, // Moderate impact, review dependents\n HIGH: 30, // High impact, careful planning needed\n} as const;\n\n/**\n * Complexity thresholds for risk assessment.\n * Based on cyclomatic complexity: higher complexity = harder to change safely.\n */\nexport const COMPLEXITY_THRESHOLDS = {\n HIGH_COMPLEXITY_DEPENDENT: 10, // Individual file is complex\n CRITICAL_AVG: 15, // Average complexity indicates systemic complexity\n CRITICAL_MAX: 25, // Peak complexity indicates hotspot\n HIGH_AVG: 10, // Moderately complex on average\n HIGH_MAX: 20, // Some complex functions exist\n MEDIUM_AVG: 6, // Slightly above simple code\n MEDIUM_MAX: 15, // Occasional branching\n} as const;\n\nexport interface FileComplexityInfo {\n filepath: string;\n avgComplexity: number;\n maxComplexity: number;\n complexityScore: number;\n chunksWithComplexity: number;\n}\n\nexport interface DependencyAnalysisResult {\n dependents: Array<{\n filepath: string;\n isTestFile: boolean;\n }>;\n dependentCount: number;\n riskLevel: RiskLevel;\n complexityMetrics?: {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n highComplexityDependents: Array<{\n filepath: string;\n maxComplexity: number;\n avgComplexity: number;\n }>;\n complexityRiskBoost: RiskLevel;\n };\n}\n\n/**\n * Creates a cached path normalizer to avoid repeated string operations.\n * \n * @param workspaceRoot - The workspace root directory for path normalization\n * @returns A function that normalizes and caches file paths\n */\nfunction createPathNormalizer(workspaceRoot: string): (path: string) => string {\n const cache = new Map<string, string>();\n return (path: string): string => {\n const cached = cache.get(path);\n if (cached !== undefined) return cached;\n const normalized = normalizePath(path, workspaceRoot);\n cache.set(path, normalized);\n return normalized;\n };\n}\n\n/**\n * Builds an index mapping normalized import paths to chunks that import them.\n * Enables O(1) lookup instead of O(n*m) iteration.\n * \n * @param chunks - All chunks from the vector database\n * @param normalizePathCached - Cached path normalization function\n * @returns Map of normalized import paths to chunks that import them\n */\nfunction buildImportIndex(\n chunks: SearchResult[],\n normalizePathCached: (path: string) => string\n): Map<string, SearchResult[]> {\n const importIndex = new Map<string, SearchResult[]>();\n \n for (const chunk of chunks) {\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n let chunkList = importIndex.get(normalizedImport);\n if (!chunkList) {\n chunkList = [];\n importIndex.set(normalizedImport, chunkList);\n }\n chunkList.push(chunk);\n }\n }\n \n return importIndex;\n}\n\n/**\n * Finds all chunks that import the target file using index + fuzzy matching.\n * \n * @param normalizedTarget - The normalized path of the target file\n * @param importIndex - Index mapping import paths to chunks\n * @returns Array of chunks that import the target file (deduplicated)\n */\nfunction findDependentChunks(\n normalizedTarget: string,\n importIndex: Map<string, SearchResult[]>\n): SearchResult[] {\n const dependentChunks: SearchResult[] = [];\n const seenChunkIds = new Set<string>();\n \n const addChunk = (chunk: SearchResult): void => {\n const chunkId = `${chunk.metadata.file}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (!seenChunkIds.has(chunkId)) {\n dependentChunks.push(chunk);\n seenChunkIds.add(chunkId);\n }\n };\n \n // Direct index lookup (fastest path)\n const directMatches = importIndex.get(normalizedTarget);\n if (directMatches) {\n for (const chunk of directMatches) {\n addChunk(chunk);\n }\n }\n \n // Fuzzy match for relative imports and path variations\n // Note: This is O(M) where M = unique import paths. For large codebases with many\n // violations, consider caching fuzzy match results at a higher level.\n for (const [normalizedImport, chunks] of importIndex.entries()) {\n if (normalizedImport !== normalizedTarget && matchesFile(normalizedImport, normalizedTarget)) {\n for (const chunk of chunks) {\n addChunk(chunk);\n }\n }\n }\n \n return dependentChunks;\n}\n\n/**\n * Groups chunks by their canonical file path.\n * \n * @param chunks - Array of chunks to group\n * @param workspaceRoot - The workspace root directory\n * @returns Map of canonical file paths to their chunks\n */\nfunction groupChunksByFile(\n chunks: SearchResult[],\n workspaceRoot: string\n): Map<string, SearchResult[]> {\n const chunksByFile = new Map<string, SearchResult[]>();\n \n for (const chunk of chunks) {\n const canonical = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n let existing = chunksByFile.get(canonical);\n if (!existing) {\n existing = [];\n chunksByFile.set(canonical, existing);\n }\n existing.push(chunk);\n }\n \n return chunksByFile;\n}\n\n/**\n * Calculates complexity metrics for each file based on its chunks.\n * \n * @param chunksByFile - Map of file paths to their chunks\n * @returns Array of complexity info for files with complexity data\n */\nfunction calculateFileComplexities(\n chunksByFile: Map<string, SearchResult[]>\n): FileComplexityInfo[] {\n const fileComplexities: FileComplexityInfo[] = [];\n \n for (const [filepath, chunks] of chunksByFile.entries()) {\n const complexities = chunks\n .map(c => c.metadata.complexity)\n .filter((c): c is number => typeof c === 'number' && c > 0);\n \n if (complexities.length > 0) {\n const sum = complexities.reduce((a, b) => a + b, 0);\n const avg = sum / complexities.length;\n const max = Math.max(...complexities);\n \n fileComplexities.push({\n filepath,\n avgComplexity: Math.round(avg * 10) / 10,\n maxComplexity: max,\n complexityScore: sum,\n chunksWithComplexity: complexities.length,\n });\n }\n }\n \n return fileComplexities;\n}\n\n/**\n * Calculates overall complexity metrics from per-file data.\n * \n * @param fileComplexities - Array of per-file complexity info\n * @returns Aggregated complexity metrics, or undefined if no data\n */\nfunction calculateOverallComplexityMetrics(\n fileComplexities: FileComplexityInfo[]\n): DependencyAnalysisResult['complexityMetrics'] | undefined {\n if (fileComplexities.length === 0) {\n return undefined;\n }\n \n const allAvgs = fileComplexities.map(f => f.avgComplexity);\n const allMaxes = fileComplexities.map(f => f.maxComplexity);\n const totalAvg = allAvgs.reduce((a, b) => a + b, 0) / allAvgs.length;\n const globalMax = Math.max(...allMaxes);\n \n // Identify high-complexity dependents (top 5)\n const highComplexityDependents = fileComplexities\n .filter(f => f.maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_COMPLEXITY_DEPENDENT)\n .sort((a, b) => b.maxComplexity - a.maxComplexity)\n .slice(0, 5)\n .map(f => ({\n filepath: f.filepath,\n maxComplexity: f.maxComplexity,\n avgComplexity: f.avgComplexity,\n }));\n \n // Calculate complexity-based risk boost\n const complexityRiskBoost = calculateComplexityRiskBoost(totalAvg, globalMax);\n \n return {\n averageComplexity: Math.round(totalAvg * 10) / 10,\n maxComplexity: globalMax,\n filesWithComplexityData: fileComplexities.length,\n highComplexityDependents,\n complexityRiskBoost,\n };\n}\n\n/**\n * Determines risk level based on complexity thresholds.\n * \n * @param avgComplexity - Average complexity across all files\n * @param maxComplexity - Maximum complexity found in any file\n * @returns Risk level based on complexity thresholds\n */\nfunction calculateComplexityRiskBoost(avgComplexity: number, maxComplexity: number): RiskLevel {\n if (avgComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_MAX) {\n return 'critical';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.HIGH_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_MAX) {\n return 'high';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_MAX) {\n return 'medium';\n }\n return 'low';\n}\n\n/**\n * Calculates risk level based on dependent count.\n * \n * @param count - Number of dependent files\n * @returns Risk level based on dependent count thresholds\n */\nfunction calculateRiskLevelFromCount(count: number): RiskLevel {\n if (count <= DEPENDENT_COUNT_THRESHOLDS.LOW) {\n return 'low';\n }\n if (count <= DEPENDENT_COUNT_THRESHOLDS.MEDIUM) {\n return 'medium';\n }\n if (count <= DEPENDENT_COUNT_THRESHOLDS.HIGH) {\n return 'high';\n }\n return 'critical';\n}\n\n/**\n * Analyzes dependencies for a given file by finding all chunks that import it.\n * \n * @param targetFilepath - The file to analyze dependencies for\n * @param allChunks - All chunks from the vector database\n * @param workspaceRoot - The workspace root directory\n * @returns Dependency analysis including dependents, count, and risk level\n */\nexport function analyzeDependencies(\n targetFilepath: string,\n allChunks: SearchResult[],\n workspaceRoot: string\n): DependencyAnalysisResult {\n // Create cached path normalizer\n const normalizePathCached = createPathNormalizer(workspaceRoot);\n \n // Build import index for efficient lookup\n const importIndex = buildImportIndex(allChunks, normalizePathCached);\n \n // Find all dependent chunks\n const normalizedTarget = normalizePathCached(targetFilepath);\n const dependentChunks = findDependentChunks(normalizedTarget, importIndex);\n \n // Group by file for analysis\n const chunksByFile = groupChunksByFile(dependentChunks, workspaceRoot);\n \n // Calculate complexity metrics\n const fileComplexities = calculateFileComplexities(chunksByFile);\n const complexityMetrics = calculateOverallComplexityMetrics(fileComplexities);\n \n // Build dependents list\n const dependents = Array.from(chunksByFile.keys()).map(filepath => ({\n filepath,\n isTestFile: isTestFile(filepath),\n }));\n \n // Calculate risk level\n let riskLevel = calculateRiskLevelFromCount(dependents.length);\n \n // Boost risk level if complexity warrants it\n if (complexityMetrics?.complexityRiskBoost) {\n if (RISK_ORDER[complexityMetrics.complexityRiskBoost] > RISK_ORDER[riskLevel]) {\n riskLevel = complexityMetrics.complexityRiskBoost;\n }\n }\n \n return {\n dependents,\n dependentCount: dependents.length,\n riskLevel,\n complexityMetrics,\n };\n}\n","import { VectorDB } from '../vectordb/lancedb.js';\nimport { LienConfig } from '../config/schema.js';\nimport { ComplexityViolation, ComplexityReport, FileComplexityData, RISK_ORDER, RiskLevel, HalsteadDetails } from './types.js';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { analyzeDependencies } from '../indexer/dependency-analyzer.js';\nimport { SearchResult } from '../vectordb/types.js';\n\n/**\n * Hardcoded severity multipliers:\n * - Warning: triggers at 1x threshold (e.g., testPaths >= 15)\n * - Error: triggers at 2x threshold (e.g., testPaths >= 30)\n */\nconst SEVERITY = { warning: 1.0, error: 2.0 } as const;\n\n/**\n * Analyzer for code complexity based on indexed codebase\n */\nexport class ComplexityAnalyzer {\n constructor(\n private vectorDB: VectorDB,\n private config: LienConfig\n ) {}\n\n /**\n * Analyze complexity of codebase or specific files\n * @param files - Optional list of specific files to analyze\n * @returns Complexity report with violations and summary\n */\n async analyze(files?: string[]): Promise<ComplexityReport> {\n // 1. Get all chunks from index (uses full scan internally for LanceDB)\n // Note: We fetch all chunks even with --files filter because dependency analysis\n // needs the complete dataset to find dependents accurately\n const allChunks = await this.vectorDB.scanAll();\n \n // 2. Filter to specified files if provided\n const chunks = files \n ? allChunks.filter(c => this.matchesAnyFile(c.metadata.file, files))\n : allChunks;\n \n // 3. Find violations from filtered chunks\n const violations = this.findViolations(chunks);\n \n // 4. Build report - pass filtered chunks for file list, but keep violations from those files\n const report = this.buildReport(violations, chunks);\n \n // 5. Enrich files with violations with dependency data\n this.enrichWithDependencies(report, allChunks as SearchResult[]);\n \n return report;\n }\n\n /**\n * Normalize a file path to a consistent relative format\n * Converts absolute paths to relative paths from workspace root\n */\n private normalizeFilePath(filepath: string): string {\n const workspaceRoot = process.cwd();\n // Convert to forward slashes first\n const normalized = filepath.replace(/\\\\/g, '/');\n const normalizedRoot = workspaceRoot.replace(/\\\\/g, '/');\n \n // Convert absolute paths to relative\n if (normalized.startsWith(normalizedRoot + '/')) {\n return normalized.slice(normalizedRoot.length + 1);\n }\n if (normalized.startsWith(normalizedRoot)) {\n return normalized.slice(normalizedRoot.length);\n }\n return normalized;\n }\n\n /**\n * Check if a chunk's file matches any of the target files\n * Uses exact match or suffix matching to avoid unintended matches\n */\n private matchesAnyFile(chunkFile: string, targetFiles: string[]): boolean {\n // Normalize to forward slashes for cross-platform consistency\n // Don't use path.normalize() as its behavior is platform-dependent\n const normalizedChunkFile = chunkFile.replace(/\\\\/g, '/');\n return targetFiles.some(target => {\n const normalizedTarget = target.replace(/\\\\/g, '/');\n // Exact match or target is a suffix of the chunk file\n return normalizedChunkFile === normalizedTarget || \n normalizedChunkFile.endsWith('/' + normalizedTarget);\n });\n }\n\n /**\n * Create a violation if complexity exceeds threshold\n */\n private createViolation(\n metadata: ChunkMetadata,\n complexity: number,\n baseThreshold: number,\n metricType: ComplexityViolation['metricType']\n ): ComplexityViolation | null {\n const warningThreshold = baseThreshold * SEVERITY.warning;\n const errorThreshold = baseThreshold * SEVERITY.error;\n\n if (complexity < warningThreshold) return null;\n\n const violationSeverity = complexity >= errorThreshold ? 'error' : 'warning';\n const effectiveThreshold = violationSeverity === 'error' ? errorThreshold : warningThreshold;\n \n // Human-friendly messages\n const message = metricType === 'cyclomatic'\n ? `Needs ~${complexity} test cases for full coverage (threshold: ${Math.round(effectiveThreshold)})`\n : `Mental load ${complexity} exceeds threshold ${Math.round(effectiveThreshold)} (hard to follow)`;\n\n return {\n filepath: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n symbolName: metadata.symbolName || 'unknown',\n symbolType: metadata.symbolType as 'function' | 'method',\n language: metadata.language,\n complexity,\n threshold: Math.round(effectiveThreshold),\n severity: violationSeverity,\n message,\n metricType,\n };\n }\n\n /**\n * Deduplicate and filter chunks to only function/method types.\n * Handles potential index duplicates by tracking file+line ranges.\n */\n private getUniqueFunctionChunks(\n chunks: Array<{ content: string; metadata: ChunkMetadata }>\n ): ChunkMetadata[] {\n const seen = new Set<string>();\n const result: ChunkMetadata[] = [];\n \n for (const { metadata } of chunks) {\n if (metadata.symbolType !== 'function' && metadata.symbolType !== 'method') continue;\n \n const key = `${metadata.file}:${metadata.startLine}-${metadata.endLine}`;\n if (seen.has(key)) continue;\n \n seen.add(key);\n result.push(metadata);\n }\n \n return result;\n }\n\n /**\n * Convert Halstead effort to time in minutes.\n * Formula: Time (seconds) = Effort / 18 (Stroud number for mental discrimination)\n * Time (minutes) = Effort / (18 * 60) = Effort / 1080\n */\n private effortToMinutes(effort: number): number {\n return effort / 1080;\n }\n\n /**\n * Format minutes as human-readable time (e.g., \"2h 30m\" or \"45m\")\n */\n private formatTime(minutes: number): string {\n if (minutes >= 60) {\n const hours = Math.floor(minutes / 60);\n const mins = Math.round(minutes % 60);\n return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;\n }\n return `${Math.round(minutes)}m`;\n }\n\n /**\n * Create a Halstead violation if metrics exceed thresholds\n */\n private createHalsteadViolation(\n metadata: ChunkMetadata,\n metricValue: number,\n threshold: number,\n metricType: 'halstead_effort' | 'halstead_bugs'\n ): ComplexityViolation | null {\n const warningThreshold = threshold * SEVERITY.warning;\n const errorThreshold = threshold * SEVERITY.error;\n\n if (metricValue < warningThreshold) return null;\n\n const violationSeverity = metricValue >= errorThreshold ? 'error' : 'warning';\n const effectiveThreshold = violationSeverity === 'error' ? errorThreshold : warningThreshold;\n \n // For effort, show time in minutes; for bugs, show decimal with 2 places\n let message: string;\n if (metricType === 'halstead_effort') {\n const timeMinutes = this.effortToMinutes(metricValue);\n const thresholdMinutes = this.effortToMinutes(effectiveThreshold);\n message = `Time to understand ~${this.formatTime(timeMinutes)} exceeds threshold ${this.formatTime(thresholdMinutes)}`;\n } else {\n message = `Estimated bugs ${metricValue.toFixed(2)} exceeds threshold ${effectiveThreshold.toFixed(1)}`;\n }\n\n const halsteadDetails: HalsteadDetails = {\n volume: metadata.halsteadVolume || 0,\n difficulty: metadata.halsteadDifficulty || 0,\n effort: metadata.halsteadEffort || 0,\n bugs: metadata.halsteadBugs || 0,\n };\n\n // Store human-scale values for complexity/threshold:\n // - halstead_effort: rounded to integer minutes for readability (typical values 60-300)\n // - halstead_bugs: kept as decimal for precision (typical values < 5, e.g. 1.5, 2.27)\n let complexity: number;\n let displayThreshold: number;\n if (metricType === 'halstead_effort') {\n // Convert raw effort to minutes and round for comparable deltas\n complexity = Math.round(this.effortToMinutes(metricValue));\n displayThreshold = Math.round(this.effortToMinutes(effectiveThreshold));\n } else {\n // halstead_bugs: store as decimal for precision in small values\n complexity = metricValue;\n displayThreshold = effectiveThreshold;\n }\n\n return {\n filepath: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n symbolName: metadata.symbolName || 'unknown',\n symbolType: metadata.symbolType as 'function' | 'method',\n language: metadata.language,\n complexity,\n threshold: displayThreshold,\n severity: violationSeverity,\n message,\n metricType,\n halsteadDetails,\n };\n }\n\n /**\n * Check complexity metrics and create violations for a single chunk.\n */\n private checkChunkComplexity(\n metadata: ChunkMetadata,\n thresholds: { testPaths: number; mentalLoad: number; halsteadEffort?: number; estimatedBugs?: number }\n ): ComplexityViolation[] {\n const violations: ComplexityViolation[] = [];\n \n // Check test paths (cyclomatic complexity)\n if (metadata.complexity) {\n const v = this.createViolation(metadata, metadata.complexity, thresholds.testPaths, 'cyclomatic');\n if (v) violations.push(v);\n }\n \n // Check mental load (cognitive complexity)\n if (metadata.cognitiveComplexity) {\n const v = this.createViolation(metadata, metadata.cognitiveComplexity, thresholds.mentalLoad, 'cognitive');\n if (v) violations.push(v);\n }\n \n // Check time to understand (Halstead effort)\n if (thresholds.halsteadEffort && metadata.halsteadEffort) {\n const v = this.createHalsteadViolation(metadata, metadata.halsteadEffort, thresholds.halsteadEffort, 'halstead_effort');\n if (v) violations.push(v);\n }\n \n // Check estimated bugs\n if (thresholds.estimatedBugs && metadata.halsteadBugs) {\n const v = this.createHalsteadViolation(metadata, metadata.halsteadBugs, thresholds.estimatedBugs, 'halstead_bugs');\n if (v) violations.push(v);\n }\n \n return violations;\n }\n\n /**\n * Convert time in minutes to Halstead effort.\n * This is the inverse of effortToMinutes().\n * Formula: Time (seconds) = Effort / 18 (Stroud number)\n * So: Effort = Time (minutes) * 60 * 18 = Time * 1080\n */\n private minutesToEffort(minutes: number): number {\n return minutes * 1080;\n }\n\n /**\n * Find all complexity violations based on thresholds.\n * Checks cyclomatic, cognitive, and Halstead complexity.\n */\n private findViolations(chunks: Array<{ content: string; metadata: ChunkMetadata }>): ComplexityViolation[] {\n const configThresholds = this.config.complexity?.thresholds;\n \n // Convert timeToUnderstandMinutes to effort internally\n const halsteadEffort = configThresholds?.timeToUnderstandMinutes \n ? this.minutesToEffort(configThresholds.timeToUnderstandMinutes)\n : this.minutesToEffort(60); // Default: 60 minutes = 64,800 effort\n \n const thresholds = { \n testPaths: configThresholds?.testPaths ?? 15, \n mentalLoad: configThresholds?.mentalLoad ?? 15, \n halsteadEffort, // Converted from minutes to effort internally (see above)\n estimatedBugs: configThresholds?.estimatedBugs ?? 1.5, // Direct decimal value (no conversion needed)\n };\n const functionChunks = this.getUniqueFunctionChunks(chunks);\n \n return functionChunks.flatMap(metadata => \n this.checkChunkComplexity(metadata, thresholds)\n );\n }\n\n /**\n * Build the final report with summary and per-file data\n */\n private buildReport(\n violations: ComplexityViolation[],\n allChunks: Array<{ content: string; metadata: ChunkMetadata }>\n ): ComplexityReport {\n // Normalize violation filepaths and group by normalized path\n const fileViolationsMap = new Map<string, ComplexityViolation[]>();\n for (const violation of violations) {\n const normalizedPath = this.normalizeFilePath(violation.filepath);\n // Update violation's filepath to normalized form\n violation.filepath = normalizedPath;\n const existing = fileViolationsMap.get(normalizedPath) || [];\n existing.push(violation);\n fileViolationsMap.set(normalizedPath, existing);\n }\n\n // Get unique files from all analyzed chunks, normalized to relative paths\n const analyzedFiles = new Set(allChunks.map(c => this.normalizeFilePath(c.metadata.file)));\n\n // Build file data\n const files: Record<string, FileComplexityData> = {};\n for (const filepath of analyzedFiles) {\n const fileViolations = fileViolationsMap.get(filepath) || [];\n files[filepath] = {\n violations: fileViolations,\n dependents: [], // Will be enriched later if needed\n testAssociations: [], // Will be enriched later if needed\n riskLevel: this.calculateRiskLevel(fileViolations),\n };\n }\n\n // Calculate summary statistics\n const errorCount = violations.filter(v => v.severity === 'error').length;\n const warningCount = violations.filter(v => v.severity === 'warning').length;\n\n // Calculate average and max complexity from all chunks with complexity data\n const complexityValues = allChunks\n .filter(c => c.metadata.complexity !== undefined && c.metadata.complexity > 0)\n .map(c => c.metadata.complexity!);\n\n const avgComplexity = complexityValues.length > 0\n ? complexityValues.reduce((sum, val) => sum + val, 0) / complexityValues.length\n : 0;\n\n const maxComplexity = complexityValues.length > 0\n ? Math.max(...complexityValues)\n : 0;\n\n return {\n summary: {\n filesAnalyzed: analyzedFiles.size,\n totalViolations: violations.length,\n bySeverity: { error: errorCount, warning: warningCount },\n avgComplexity: Math.round(avgComplexity * 10) / 10, // Round to 1 decimal\n maxComplexity,\n },\n files,\n };\n }\n\n /**\n * Calculate risk level based on violations\n */\n private calculateRiskLevel(violations: ComplexityViolation[]): RiskLevel {\n if (violations.length === 0) return 'low';\n\n const hasErrors = violations.some(v => v.severity === 'error');\n const errorCount = violations.filter(v => v.severity === 'error').length;\n\n if (errorCount >= 3) return 'critical';\n if (hasErrors) return 'high';\n if (violations.length >= 3) return 'medium';\n return 'low';\n }\n\n /**\n * Enrich files with violations with dependency data\n * This adds:\n * - List of dependent files (who imports this?)\n * - Boosted risk level based on dependents + complexity\n */\n private enrichWithDependencies(\n report: ComplexityReport,\n allChunks: SearchResult[]\n ): void {\n const workspaceRoot = process.cwd();\n\n // Only enrich files that have violations (to save computation)\n const filesWithViolations = Object.entries(report.files)\n .filter(([_, data]) => data.violations.length > 0)\n .map(([filepath, _]) => filepath);\n\n for (const filepath of filesWithViolations) {\n const fileData = report.files[filepath];\n \n // Analyze dependencies for this file\n const depAnalysis = analyzeDependencies(filepath, allChunks, workspaceRoot);\n \n // Update file data with dependency information\n fileData.dependents = depAnalysis.dependents.map(d => d.filepath);\n fileData.dependentCount = depAnalysis.dependentCount;\n \n // Boost risk level based on dependency analysis\n // Take the higher of the two risk levels\n if (RISK_ORDER[depAnalysis.riskLevel] > RISK_ORDER[fileData.riskLevel]) {\n fileData.riskLevel = depAnalysis.riskLevel;\n }\n \n // Add complexity metrics if available\n if (depAnalysis.complexityMetrics) {\n fileData.dependentComplexityMetrics = {\n averageComplexity: depAnalysis.complexityMetrics.averageComplexity,\n maxComplexity: depAnalysis.complexityMetrics.maxComplexity,\n filesWithComplexityData: depAnalysis.complexityMetrics.filesWithComplexityData,\n };\n }\n }\n }\n}\n\n","/**\n * MCP Tool Handler Registry\n *\n * This module exports all tool handlers and a registry mapping tool names to handlers.\n * The registry is used by the MCP server to dispatch tool calls.\n */\n\nimport { handleSemanticSearch } from './semantic-search.js';\nimport { handleFindSimilar } from './find-similar.js';\nimport { handleGetFilesContext } from './get-files-context.js';\nimport { handleListFunctions } from './list-functions.js';\nimport { handleGetDependents } from './get-dependents.js';\nimport { handleGetComplexity } from './get-complexity.js';\nimport type { ToolHandler } from '../types.js';\n\n// Re-export individual handlers for direct use if needed\nexport {\n handleSemanticSearch,\n handleFindSimilar,\n handleGetFilesContext,\n handleListFunctions,\n handleGetDependents,\n handleGetComplexity,\n};\n\n/**\n * Registry mapping MCP tool names to their handler functions.\n * Used by the MCP server to dispatch tool calls.\n */\nexport const toolHandlers: Record<string, ToolHandler> = {\n 'semantic_search': handleSemanticSearch,\n 'find_similar': handleFindSimilar,\n 'get_files_context': handleGetFilesContext,\n 'list_functions': handleListFunctions,\n 'get_dependents': handleGetDependents,\n 'get_complexity': handleGetComplexity,\n};\n","import chokidar from 'chokidar';\nimport { LienConfig, LegacyLienConfig, isLegacyConfig, isModernConfig } from '../config/schema.js';\n\nexport interface FileChangeEvent {\n type: 'add' | 'change' | 'unlink';\n filepath: string;\n}\n\nexport type FileChangeHandler = (event: FileChangeEvent) => void | Promise<void>;\n\n/**\n * File watcher service that monitors code files for changes.\n * Uses chokidar for robust file watching with debouncing support.\n */\nexport class FileWatcher {\n private watcher: chokidar.FSWatcher | null = null;\n private debounceTimers: Map<string, NodeJS.Timeout> = new Map();\n private config: LienConfig | LegacyLienConfig;\n private rootDir: string;\n private onChangeHandler: FileChangeHandler | null = null;\n \n constructor(rootDir: string, config: LienConfig | LegacyLienConfig) {\n this.rootDir = rootDir;\n this.config = config;\n }\n \n /**\n * Starts watching files for changes.\n * \n * @param handler - Callback function called when files change\n */\n async start(handler: FileChangeHandler): Promise<void> {\n if (this.watcher) {\n throw new Error('File watcher is already running');\n }\n \n this.onChangeHandler = handler;\n \n // Get watch patterns based on config type\n let includePatterns: string[];\n let excludePatterns: string[];\n \n if (isLegacyConfig(this.config)) {\n includePatterns = this.config.indexing.include;\n excludePatterns = this.config.indexing.exclude;\n } else if (isModernConfig(this.config)) {\n // For modern configs, aggregate patterns from all frameworks\n includePatterns = this.config.frameworks.flatMap(f => f.config.include);\n excludePatterns = this.config.frameworks.flatMap(f => f.config.exclude);\n } else {\n includePatterns = ['**/*'];\n excludePatterns = [];\n }\n \n // Configure chokidar\n this.watcher = chokidar.watch(includePatterns, {\n cwd: this.rootDir,\n ignored: excludePatterns,\n persistent: true,\n ignoreInitial: true, // Don't trigger for existing files\n awaitWriteFinish: {\n stabilityThreshold: 500, // Wait 500ms for file to stop changing\n pollInterval: 100,\n },\n // Performance optimizations\n usePolling: false,\n interval: 100,\n binaryInterval: 300,\n });\n \n // Register event handlers with debouncing\n this.watcher\n .on('add', (filepath) => this.handleChange('add', filepath))\n .on('change', (filepath) => this.handleChange('change', filepath))\n .on('unlink', (filepath) => this.handleChange('unlink', filepath))\n .on('error', (error) => {\n console.error(`[Lien] File watcher error: ${error}`);\n });\n \n // Wait for watcher to be ready\n await new Promise<void>((resolve) => {\n this.watcher!.on('ready', () => {\n resolve();\n });\n });\n }\n \n /**\n * Handles a file change event with debouncing.\n * Debouncing prevents rapid reindexing when files are saved multiple times quickly.\n */\n private handleChange(type: 'add' | 'change' | 'unlink', filepath: string): void {\n // Clear existing debounce timer for this file\n const existingTimer = this.debounceTimers.get(filepath);\n if (existingTimer) {\n clearTimeout(existingTimer);\n }\n \n // Set new debounce timer\n const timer = setTimeout(() => {\n this.debounceTimers.delete(filepath);\n \n // Call handler\n if (this.onChangeHandler) {\n const absolutePath = filepath.startsWith('/')\n ? filepath\n : `${this.rootDir}/${filepath}`;\n \n try {\n const result = this.onChangeHandler({\n type,\n filepath: absolutePath,\n });\n \n // Handle async handlers\n if (result instanceof Promise) {\n result.catch((error) => {\n console.error(`[Lien] Error handling file change: ${error}`);\n });\n }\n } catch (error) {\n console.error(`[Lien] Error handling file change: ${error}`);\n }\n }\n }, this.config.fileWatching.debounceMs);\n \n this.debounceTimers.set(filepath, timer);\n }\n \n /**\n * Stops the file watcher and cleans up resources.\n */\n async stop(): Promise<void> {\n if (!this.watcher) {\n return;\n }\n \n // Clear all pending debounce timers\n for (const timer of this.debounceTimers.values()) {\n clearTimeout(timer);\n }\n this.debounceTimers.clear();\n \n // Close watcher\n await this.watcher.close();\n this.watcher = null;\n this.onChangeHandler = null;\n }\n \n /**\n * Gets the list of files currently being watched.\n */\n getWatchedFiles(): string[] {\n if (!this.watcher) {\n return [];\n }\n \n const watched = this.watcher.getWatched();\n const files: string[] = [];\n \n for (const [dir, filenames] of Object.entries(watched)) {\n for (const filename of filenames) {\n files.push(`${dir}/${filename}`);\n }\n }\n \n return files;\n }\n \n /**\n * Checks if the watcher is currently running.\n */\n isRunning(): boolean {\n return this.watcher !== null;\n }\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { configService } from '../config/service.js';\nimport { ComplexityAnalyzer } from '../insights/complexity-analyzer.js';\nimport { formatReport, OutputFormat } from '../insights/formatters/index.js';\nimport type { LienConfig, LegacyLienConfig } from '../config/schema.js';\n\ninterface ComplexityOptions {\n files?: string[];\n format: OutputFormat;\n threshold?: string;\n cyclomaticThreshold?: string;\n cognitiveThreshold?: string;\n failOn?: 'error' | 'warning';\n}\n\n/** Parsed threshold overrides */\ninterface ThresholdOverrides {\n cyclomatic: number | null;\n cognitive: number | null;\n}\n\nconst VALID_FAIL_ON = ['error', 'warning'];\nconst VALID_FORMATS = ['text', 'json', 'sarif'];\n\n/** Validate --fail-on option */\nfunction validateFailOn(failOn: string | undefined): void {\n if (failOn && !VALID_FAIL_ON.includes(failOn)) {\n console.error(chalk.red(`Error: Invalid --fail-on value \"${failOn}\". Must be either 'error' or 'warning'`));\n process.exit(1);\n }\n}\n\n/** Validate --format option */\nfunction validateFormat(format: string): void {\n if (!VALID_FORMATS.includes(format)) {\n console.error(chalk.red(`Error: Invalid --format value \"${format}\". Must be one of: text, json, sarif`));\n process.exit(1);\n }\n}\n\n/** Validate that specified files exist */\nfunction validateFilesExist(files: string[] | undefined, rootDir: string): void {\n if (!files || files.length === 0) return;\n \n const missingFiles = files.filter(file => {\n const fullPath = path.isAbsolute(file) ? file : path.join(rootDir, file);\n return !fs.existsSync(fullPath);\n });\n \n if (missingFiles.length > 0) {\n console.error(chalk.red(`Error: File${missingFiles.length > 1 ? 's' : ''} not found:`));\n missingFiles.forEach(file => console.error(chalk.red(` - ${file}`)));\n process.exit(1);\n }\n}\n\n/** Parse and validate a threshold value */\nfunction parseThresholdValue(value: string | undefined, flagName: string): number | null {\n if (!value) return null;\n \n const parsed = parseInt(value, 10);\n if (isNaN(parsed)) {\n console.error(chalk.red(`Error: Invalid ${flagName} value \"${value}\". Must be a number`));\n process.exit(1);\n }\n if (parsed <= 0) {\n console.error(chalk.red(`Error: Invalid ${flagName} value \"${value}\". Must be a positive number`));\n process.exit(1);\n }\n return parsed;\n}\n\n/** Parse all threshold options into overrides */\nfunction parseThresholdOverrides(options: ComplexityOptions): ThresholdOverrides {\n const baseThreshold = parseThresholdValue(options.threshold, '--threshold');\n const cyclomaticOverride = parseThresholdValue(options.cyclomaticThreshold, '--cyclomatic-threshold');\n const cognitiveOverride = parseThresholdValue(options.cognitiveThreshold, '--cognitive-threshold');\n \n return {\n // Specific flags take precedence over --threshold\n cyclomatic: cyclomaticOverride ?? baseThreshold,\n cognitive: cognitiveOverride ?? baseThreshold,\n };\n}\n\n/** Apply threshold overrides to config (mutates config) */\nfunction applyThresholdOverrides(config: LienConfig | LegacyLienConfig, overrides: ThresholdOverrides): void {\n if (overrides.cyclomatic === null && overrides.cognitive === null) return;\n \n // Cast to allow mutation - both config types support complexity at runtime\n const cfg = config as { complexity?: LienConfig['complexity'] };\n \n // Ensure complexity config structure exists\n if (!cfg.complexity) {\n cfg.complexity = {\n enabled: true,\n thresholds: { testPaths: 15, mentalLoad: 15 },\n };\n } else if (!cfg.complexity.thresholds) {\n cfg.complexity.thresholds = { testPaths: 15, mentalLoad: 15 };\n }\n \n // Apply overrides (CLI flags use --cyclomatic/--cognitive for familiarity)\n if (overrides.cyclomatic !== null) {\n cfg.complexity.thresholds.testPaths = overrides.cyclomatic;\n }\n if (overrides.cognitive !== null) {\n cfg.complexity.thresholds.mentalLoad = overrides.cognitive;\n }\n}\n\n/** Check if index exists */\nasync function ensureIndexExists(vectorDB: VectorDB): Promise<void> {\n try {\n await vectorDB.scanWithFilter({ limit: 1 });\n } catch {\n console.error(chalk.red('Error: Index not found'));\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien index'), chalk.yellow('to index your codebase first'));\n process.exit(1);\n }\n}\n\n/**\n * Analyze code complexity from indexed codebase\n */\nexport async function complexityCommand(options: ComplexityOptions) {\n const rootDir = process.cwd();\n \n try {\n // Validate options\n validateFailOn(options.failOn);\n validateFormat(options.format);\n validateFilesExist(options.files, rootDir);\n const thresholdOverrides = parseThresholdOverrides(options);\n \n // Load config and database\n const config = await configService.load(rootDir);\n const vectorDB = new VectorDB(rootDir);\n await vectorDB.initialize();\n await ensureIndexExists(vectorDB);\n \n // Apply threshold overrides if provided\n applyThresholdOverrides(config, thresholdOverrides);\n \n // Run analysis and output\n const analyzer = new ComplexityAnalyzer(vectorDB, config);\n const report = await analyzer.analyze(options.files);\n console.log(formatReport(report, options.format));\n \n // Exit code for CI integration\n if (options.failOn) {\n const hasViolations = options.failOn === 'error' \n ? report.summary.bySeverity.error > 0\n : report.summary.totalViolations > 0;\n if (hasViolations) process.exit(1);\n }\n } catch (error) {\n console.error(chalk.red('Error analyzing complexity:'), error);\n process.exit(1);\n }\n}\n\n","import chalk from 'chalk';\nimport { ComplexityReport, ComplexityViolation, FileComplexityData } from '../types.js';\n\n/**\n * Violation with associated file path for rendering\n */\ntype ViolationWithFile = ComplexityViolation & { file: string };\n\n/**\n * Get the display label for a metric type\n */\nfunction getMetricLabel(metricType: ComplexityViolation['metricType']): string {\n switch (metricType) {\n case 'cognitive': return '🧠 Mental load';\n case 'cyclomatic': return '🔀 Test paths';\n case 'halstead_effort': return '⏱️ Time to understand';\n case 'halstead_bugs': return '🐛 Estimated bugs';\n default: return 'Complexity';\n }\n}\n\n/**\n * Convert Halstead effort to time in minutes\n */\nfunction effortToMinutes(effort: number): number {\n return effort / 1080;\n}\n\n/**\n * Format minutes as human-readable time\n */\nfunction formatTime(minutes: number): string {\n if (minutes >= 60) {\n const hours = Math.floor(minutes / 60);\n const mins = Math.round(minutes % 60);\n return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;\n }\n return `${Math.round(minutes)}m`;\n}\n\n/**\n * Format Halstead details as additional lines\n */\nfunction formatHalsteadDetails(violation: ViolationWithFile): string[] {\n if (!violation.halsteadDetails) return [];\n \n const { volume, difficulty, effort, bugs } = violation.halsteadDetails;\n const timeStr = formatTime(effortToMinutes(effort));\n return [\n chalk.dim(` 📊 Volume: ${Math.round(volume).toLocaleString()}, Difficulty: ${difficulty.toFixed(1)}`),\n chalk.dim(` ⏱️ Time: ~${timeStr}, Est. bugs: ${bugs.toFixed(2)}`),\n ];\n}\n\n/**\n * Metric-specific formatters for complexity/threshold display.\n * Each formatter returns { complexity, threshold } as display strings.\n */\ntype MetricFormatter = (val: number, thresh: number) => { complexity: string; threshold: string };\n\nconst metricFormatters: Record<string, MetricFormatter> = {\n halstead_effort: (val, thresh) => ({\n // val/thresh are already in minutes (human-scale)\n complexity: '~' + formatTime(val),\n threshold: formatTime(thresh),\n }),\n halstead_bugs: (val, thresh) => ({\n complexity: val.toFixed(2),\n threshold: thresh.toFixed(1),\n }),\n cyclomatic: (val, thresh) => ({\n complexity: `${val} (needs ~${val} tests)`,\n threshold: thresh.toString(),\n }),\n};\n\nconst defaultFormatter: MetricFormatter = (val, thresh) => ({\n complexity: val.toString(),\n threshold: thresh.toString(),\n});\n\n/**\n * Format symbol name with appropriate suffix\n */\nfunction formatSymbolDisplay(violation: ViolationWithFile, isBold: boolean): string {\n const display = ['function', 'method'].includes(violation.symbolType)\n ? `${violation.symbolName}()`\n : violation.symbolName;\n return isBold ? chalk.bold(display) : display;\n}\n\n/**\n * Format dependency impact information\n */\nfunction formatDependencyInfo(fileData: FileComplexityData): string[] {\n const depCount = fileData.dependentCount ?? fileData.dependents.length;\n if (depCount === 0) return [];\n\n const lines = [chalk.dim(` 📦 Imported by ${depCount} file${depCount !== 1 ? 's' : ''}`)];\n \n if (fileData.dependentComplexityMetrics) {\n const { averageComplexity, maxComplexity } = fileData.dependentComplexityMetrics;\n lines.push(chalk.dim(` - Dependent avg complexity: ${averageComplexity}, max: ${maxComplexity}`));\n }\n \n return lines;\n}\n\n/**\n * Format percentage over threshold\n */\nfunction formatPercentageOver(complexity: number, threshold: number): string {\n if (threshold <= 0) return 'N/A (invalid threshold)';\n return `${Math.round(((complexity - threshold) / threshold) * 100)}% over threshold`;\n}\n\n/**\n * Format a single violation entry with its metadata\n */\nfunction formatViolation(\n violation: ViolationWithFile,\n fileData: FileComplexityData,\n colorFn: typeof chalk.red | typeof chalk.yellow,\n isBold: boolean\n): string[] {\n const symbolText = formatSymbolDisplay(violation, isBold);\n const metricLabel = getMetricLabel(violation.metricType);\n const formatter = metricFormatters[violation.metricType] || defaultFormatter;\n const { complexity: complexityDisplay, threshold: thresholdDisplay } = formatter(violation.complexity, violation.threshold);\n\n return [\n colorFn(` ${violation.file}:${violation.startLine}`) + chalk.dim(' - ') + symbolText,\n chalk.dim(` ${metricLabel}: ${complexityDisplay} (threshold: ${thresholdDisplay})`),\n chalk.dim(` ⬆️ ${formatPercentageOver(violation.complexity, violation.threshold)}`),\n ...formatHalsteadDetails(violation),\n ...formatDependencyInfo(fileData),\n chalk.dim(` ⚠️ Risk: ${fileData.riskLevel.toUpperCase()}`),\n '',\n ];\n}\n\n/**\n * Format complexity report as human-readable text with colors\n */\nexport function formatTextReport(report: ComplexityReport): string {\n const lines: string[] = [];\n\n // Header\n lines.push(chalk.bold('🔍 Complexity Analysis\\n'));\n\n // Summary\n lines.push(chalk.bold('Summary:'));\n lines.push(chalk.dim(' Files analyzed: ') + report.summary.filesAnalyzed.toString());\n const errorText = `${report.summary.bySeverity.error} error${report.summary.bySeverity.error !== 1 ? 's' : ''}`;\n const warningText = `${report.summary.bySeverity.warning} warning${report.summary.bySeverity.warning !== 1 ? 's' : ''}`;\n lines.push(chalk.dim(' Violations: ') + `${report.summary.totalViolations} (${errorText}, ${warningText})`);\n lines.push(chalk.dim(' Average complexity: ') + report.summary.avgComplexity.toString());\n lines.push(chalk.dim(' Max complexity: ') + report.summary.maxComplexity.toString());\n lines.push('');\n\n // Group violations by file\n const filesWithViolations = Object.entries(report.files)\n .filter(([_, data]) => data.violations.length > 0)\n .sort((a, b) => b[1].violations.length - a[1].violations.length);\n\n if (filesWithViolations.length === 0) {\n lines.push(chalk.green('✓ No violations found!'));\n return lines.join('\\n');\n }\n\n // Errors section\n const errors = filesWithViolations.flatMap(([file, data]) =>\n data.violations.filter(v => v.severity === 'error').map(v => ({ file, ...v }))\n );\n\n if (errors.length > 0) {\n lines.push(chalk.red.bold('❌ Errors:\\n'));\n for (const error of errors) {\n lines.push(...formatViolation(error, report.files[error.file], chalk.red, true));\n }\n }\n\n // Warnings section\n const warnings = filesWithViolations.flatMap(([file, data]) =>\n data.violations.filter(v => v.severity === 'warning').map(v => ({ file, ...v }))\n );\n\n if (warnings.length > 0) {\n lines.push(chalk.yellow.bold('⚠️ Warnings:\\n'));\n for (const warning of warnings) {\n lines.push(...formatViolation(warning, report.files[warning.file], chalk.yellow, false));\n }\n }\n\n return lines.join('\\n');\n}\n\n","import { ComplexityReport } from '../types.js';\n\n/**\n * Format complexity report as JSON for consumption by GitHub Action\n */\nexport function formatJsonReport(report: ComplexityReport): string {\n return JSON.stringify(report, null, 2);\n}\n\n","import { ComplexityReport } from '../types.js';\n\n/**\n * SARIF (Static Analysis Results Interchange Format) 2.1.0\n * Used by GitHub Code Scanning to show results in Security tab\n * https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning\n */\ninterface SarifReport {\n $schema: string;\n version: string;\n runs: SarifRun[];\n}\n\ninterface SarifRun {\n tool: {\n driver: {\n name: string;\n version: string;\n informationUri?: string;\n rules?: SarifRule[];\n };\n };\n results: SarifResult[];\n}\n\ninterface SarifRule {\n id: string;\n shortDescription: {\n text: string;\n };\n fullDescription?: {\n text: string;\n };\n help?: {\n text: string;\n };\n defaultConfiguration?: {\n level: 'warning' | 'error' | 'note';\n };\n}\n\ninterface SarifResult {\n ruleId: string;\n level: 'warning' | 'error' | 'note';\n message: {\n text: string;\n };\n locations: Array<{\n physicalLocation: {\n artifactLocation: {\n uri: string;\n };\n region: {\n startLine: number;\n endLine: number;\n };\n };\n }>;\n}\n\n/**\n * Get the SARIF rule ID for a metric type\n */\nfunction getRuleId(metricType: string): string {\n switch (metricType) {\n case 'cognitive': return 'lien/high-cognitive-complexity';\n case 'cyclomatic': return 'lien/high-cyclomatic-complexity';\n case 'halstead_effort': return 'lien/high-halstead-effort';\n case 'halstead_bugs': return 'lien/high-estimated-bugs';\n default: return 'lien/high-complexity';\n }\n}\n\n/**\n * Format complexity report as SARIF for GitHub Code Scanning\n */\nexport function formatSarifReport(report: ComplexityReport): string {\n const rules: SarifRule[] = [\n {\n id: 'lien/high-cyclomatic-complexity',\n shortDescription: {\n text: 'Too many test paths',\n },\n fullDescription: {\n text: 'Function or method requires too many test cases to achieve full branch coverage. Each decision point (if, switch, loop) adds a path that needs testing.',\n },\n help: {\n text: 'Consider refactoring by extracting methods, using early returns, or simplifying conditional logic to reduce the number of test paths.',\n },\n },\n {\n id: 'lien/high-cognitive-complexity',\n shortDescription: {\n text: 'High mental load',\n },\n fullDescription: {\n text: 'Function or method has high mental load (deeply nested or hard to follow), requiring too much mental effort to understand and maintain.',\n },\n help: {\n text: 'Consider flattening nested conditionals, extracting helper functions, or using guard clauses to reduce mental load.',\n },\n },\n {\n id: 'lien/high-halstead-effort',\n shortDescription: {\n text: 'Long time to understand',\n },\n fullDescription: {\n text: 'Function or method takes too long to understand, based on Halstead metrics (operators and operands count).',\n },\n help: {\n text: 'Consider simplifying expressions, reducing variable count, or breaking into smaller functions.',\n },\n },\n {\n id: 'lien/high-estimated-bugs',\n shortDescription: {\n text: 'High estimated bug count',\n },\n fullDescription: {\n text: 'Function or method is likely to contain bugs based on Halstead metrics (Volume / 3000), which estimates bug count from code complexity.',\n },\n help: {\n text: 'Consider simplifying the function, breaking into smaller units, or adding thorough test coverage.',\n },\n },\n ];\n\n const results: SarifResult[] = [];\n\n // Convert violations to SARIF results\n for (const [filepath, fileData] of Object.entries(report.files)) {\n for (const violation of fileData.violations) {\n const ruleId = getRuleId(violation.metricType);\n \n results.push({\n ruleId,\n level: violation.severity,\n message: {\n text: `${violation.symbolName}: ${violation.message}`,\n },\n locations: [\n {\n physicalLocation: {\n artifactLocation: {\n uri: filepath,\n },\n region: {\n startLine: violation.startLine,\n endLine: violation.endLine,\n },\n },\n },\n ],\n });\n }\n }\n\n const sarifReport: SarifReport = {\n $schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',\n version: '2.1.0',\n runs: [\n {\n tool: {\n driver: {\n name: 'Lien Complexity Analyzer',\n version: '1.0.0',\n informationUri: 'https://github.com/liendev/lien',\n rules,\n },\n },\n results,\n },\n ],\n };\n\n return JSON.stringify(sarifReport, null, 2);\n}\n\n","import { ComplexityReport } from '../types.js';\nimport { formatTextReport } from './text.js';\nimport { formatJsonReport } from './json.js';\nimport { formatSarifReport } from './sarif.js';\n\nexport type OutputFormat = 'text' | 'json' | 'sarif';\n\n/**\n * Format complexity report in the specified format\n */\nexport function formatReport(\n report: ComplexityReport,\n format: OutputFormat\n): string {\n switch (format) {\n case 'json':\n return formatJsonReport(report);\n case 'sarif':\n return formatSarifReport(report);\n case 'text':\n default:\n return formatTextReport(report);\n }\n}\n\n// Export individual formatters\nexport { formatTextReport, formatJsonReport, formatSarifReport };\n\n","import { program } from './cli/index.js';\n\nprogram.parse();\n\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAoCvB,SAAS,oBAA4B;AAC1C,SAAO,YAAY;AACrB;AAxCA,IAeM,YACA,WACAA,UAEF;AAnBJ;AAAA;AAAA;AAeA,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,YAAY,QAAQ,UAAU;AACpC,IAAMA,WAAU,cAAc,YAAY,GAAG;AAI7C,QAAI;AAEF,oBAAcA,SAAQ,KAAK,WAAW,iBAAiB,CAAC;AAAA,IAC1D,QAAQ;AACN,UAAI;AAEF,sBAAcA,SAAQ,KAAK,WAAW,oBAAoB,CAAC;AAAA,MAC7D,QAAQ;AAEN,gBAAQ,KAAK,qEAAqE;AAClF,sBAAc,EAAE,SAAS,gBAAgB;AAAA,MAC3C;AAAA,IACF;AAAA;AAAA;;;ACjCA,IASa,oBACA,uBAGA,qBACA,8BAKA,4BAIA,0BAEA,0BAGA,sBACA,yBAGA,cACA,2BAGA,8BAGA,qBAIA,wBAWA;AAtDb;AAAA;AAAA;AAMA;AAGO,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAG9B,IAAM,sBAAsB;AAC5B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iB,0CAA0C,EAClE,OAAO,aAAa,2CAA2C,EAC/D,OAAO,qBAAqB,oDAAoD,EAChF,OAAO,WAAW;AAErB,QACG,QAAQ,OAAO,EACf,YAAY,wCAAwC,EACpD,OAAO,eAAe,uCAAuC,EAC7D,OAAO,eAAe,8CAA8C,EACpE,OAAO,iBAAiB,uCAAuC,EAC/D,OAAO,YAAY;AAEtB,QACG,QAAQ,OAAO,EACf,YAAY,6CAA6C,EACzD,OAAO,qBAAqB,gCAAgC,MAAM,EAClE,OAAO,cAAc,wCAAwC,EAC7D,OAAO,eAAe,sDAAsD,EAC5E,OAAO,qBAAqB,yDAAyD,EACrF,OAAO,YAAY;AAEtB,QACG,QAAQ,QAAQ,EAChB,YAAY,qCAAqC,EACjD,OAAO,aAAa;AAEvB,QACG,QAAQ,YAAY,EACpB,YAAY,yBAAyB,EACrC,OAAO,sBAAsB,2BAA2B,EACxD,OAAO,mBAAmB,oCAAoC,MAAM,EACpE,OAAO,mBAAmB,8DAA8D,EACxF,OAAO,8BAA8B,+CAA+C,EACpF,OAAO,6BAA6B,8CAA8C,EAClF,OAAO,wBAAwB,sCAAsC,EACrE,OAAO,iBAAiB;;;A6ClE3B,QAAQ,MAAM;","names":["require","fs","path","fs","path","fs","path","init_version","fs","path","e","detectLanguage","search","detectLanguage","init_chunker","init_types","path","init_types","buildLegacySymbols","fs","path","init_version","path","os","crypto","init_version","fs","path","fs","path","fs","path","manifest","init_chunker","fs","path","fs","chalk","isGitAvailable","isGitRepo","GitStateTracker","init_chunker","init_version","createRequire","fileURLToPath","dirname","join","fs","path","fileURLToPath","chalk","createRequire","fileURLToPath","dirname","join","__filename","__dirname","require","packageJson","fs","path","chalk","fs","path","fs","path","path","packageJson","fs","fs","path","path","fs","tools","fs","path","path","fs","fs","path","path","fs","path","fs","__filename","fileURLToPath","__dirname","path","fs","chalk","init_version","chalk","fs","path","path","chalk","fs","chalk","VectorDB","ManifestManager","chalk","chalk","fs","path","createRequire","fileURLToPath","dirname","join","z","z","z","z","z","path","isTestFile","path","chunkFile","isTestFile","SCAN_LIMIT","path","isTestFile","RISK_ORDER","DEPENDENT_COUNT_THRESHOLDS","COMPLEXITY_THRESHOLDS","path","buildImportIndex","findDependentChunks","calculateFileComplexities","calculateOverallComplexityMetrics","calculateComplexityRiskBoost","isTestFile","RISK_ORDER","chunkFile","RISK_ORDER","__filename","fileURLToPath","__dirname","dirname","require","createRequire","packageJson","join","indexCodebase","path","fs","chalk","chalk","fs","path","chalk","chalk","path","fs","__filename","fileURLToPath","__dirname","dirname","require","createRequire","packageJson","join"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/version.ts","../src/constants.ts","../src/config/schema.ts","../src/config/migration.ts","../src/config/merge.ts","../src/errors/codes.ts","../src/errors/index.ts","../src/config/service.ts","../src/git/utils.ts","../src/vectordb/version.ts","../src/indexer/scanner.ts","../src/indexer/symbol-extractor.ts","../src/indexer/ast/parser.ts","../src/indexer/ast/complexity/cyclomatic.ts","../src/indexer/ast/complexity/cognitive.ts","../src/indexer/ast/complexity/halstead.ts","../src/indexer/ast/complexity/index.ts","../src/indexer/ast/symbols.ts","../src/indexer/ast/traversers/typescript.ts","../src/indexer/ast/traversers/php.ts","../src/indexer/ast/traversers/python.ts","../src/indexer/ast/traversers/index.ts","../src/indexer/ast/chunker.ts","../src/indexer/liquid-chunker.ts","../src/indexer/json-template-chunker.ts","../src/indexer/chunker.ts","../src/embeddings/local.ts","../src/embeddings/types.ts","../src/vectordb/relevance.ts","../src/vectordb/intent-classifier.ts","../src/vectordb/boosting/types.ts","../src/vectordb/boosting/strategies.ts","../src/vectordb/boosting/composer.ts","../src/vectordb/boosting/index.ts","../src/vectordb/query.ts","../src/vectordb/batch-insert.ts","../src/vectordb/maintenance.ts","../src/vectordb/lancedb.ts","../src/indexer/manifest.ts","../src/git/tracker.ts","../src/utils/result.ts","../src/indexer/incremental.ts","../src/indexer/change-detector.ts","../src/utils/loading-messages.ts","../src/indexer/progress-tracker.ts","../src/indexer/index.ts","../src/cli/index.ts","../src/cli/init.ts","../src/utils/banner.ts","../src/config/migration-manager.ts","../src/frameworks/detector-service.ts","../src/frameworks/types.ts","../src/frameworks/nodejs/detector.ts","../src/frameworks/nodejs/config.ts","../src/frameworks/php/detector.ts","../src/frameworks/php/config.ts","../src/frameworks/laravel/detector.ts","../src/frameworks/laravel/config.ts","../src/frameworks/shopify/detector.ts","../src/frameworks/shopify/config.ts","../src/frameworks/registry.ts","../src/cli/status.ts","../src/cli/index-cmd.ts","../src/cli/serve.ts","../src/mcp/server.ts","../src/mcp/utils/zod-to-json-schema.ts","../src/mcp/schemas/search.schema.ts","../src/mcp/schemas/similarity.schema.ts","../src/mcp/schemas/file.schema.ts","../src/mcp/schemas/symbols.schema.ts","../src/mcp/schemas/dependents.schema.ts","../src/mcp/schemas/complexity.schema.ts","../src/mcp/tools.ts","../src/mcp/utils/tool-wrapper.ts","../src/mcp/handlers/semantic-search.ts","../src/mcp/handlers/find-similar.ts","../src/mcp/utils/path-matching.ts","../src/mcp/handlers/get-files-context.ts","../src/mcp/handlers/list-functions.ts","../src/mcp/handlers/get-dependents.ts","../src/mcp/handlers/get-complexity.ts","../src/insights/types.ts","../src/indexer/dependency-analyzer.ts","../src/insights/complexity-analyzer.ts","../src/mcp/handlers/index.ts","../src/watcher/index.ts","../src/cli/complexity.ts","../src/insights/formatters/text.ts","../src/insights/formatters/json.ts","../src/insights/formatters/sarif.ts","../src/insights/formatters/index.ts","../src/index.ts"],"sourcesContent":["import { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\n\n/**\n * Centralized package version loader.\n * Handles different build output structures (development vs production).\n * \n * Build scenarios:\n * - Development (ts-node): src/utils/version.ts → ../package.json\n * - Production (dist): dist/utils/version.js → ../package.json\n * - Nested builds: dist/something/version.js → ../../package.json\n */\n\n// Setup require for ESM\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson: { version: string; name?: string };\n\ntry {\n // Try relative to current file (works in most scenarios)\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n try {\n // Fallback: go up one more level (nested build output)\n packageJson = require(join(__dirname, '../../package.json'));\n } catch {\n // Last resort: hardcoded fallback (should never happen in production)\n console.warn('[Lien] Warning: Could not load package.json, using fallback version');\n packageJson = { version: '0.0.0-unknown' };\n }\n}\n\n/**\n * Get the current package version\n */\nexport function getPackageVersion(): string {\n return packageJson.version;\n}\n\n/**\n * Get the full package.json (for compatibility)\n */\nexport function getPackageInfo(): { version: string; name?: string } {\n return packageJson;\n}\n\n","/**\n * Centralized constants for the Lien project.\n * This file contains all magic numbers and configuration defaults\n * to ensure consistency across the codebase.\n */\n\nimport { getPackageVersion } from './utils/version.js';\n\n// Chunking settings\nexport const DEFAULT_CHUNK_SIZE = 75;\nexport const DEFAULT_CHUNK_OVERLAP = 10;\n\n// Concurrency and batching\nexport const DEFAULT_CONCURRENCY = 4;\nexport const DEFAULT_EMBEDDING_BATCH_SIZE = 50;\n\n// Micro-batching for event loop yielding\n// Process N embeddings at a time, then yield to event loop\n// This prevents UI freezing during CPU-intensive embedding generation\nexport const EMBEDDING_MICRO_BATCH_SIZE = 10;\n\n// Vector database batch size limits\n// Maximum batch size before splitting (prevents LanceDB errors on very large batches)\nexport const VECTOR_DB_MAX_BATCH_SIZE = 1000;\n// Minimum batch size for retry logic (stop splitting below this size)\nexport const VECTOR_DB_MIN_BATCH_SIZE = 10;\n\n// Embedding model configuration\nexport const EMBEDDING_DIMENSIONS = 384; // all-MiniLM-L6-v2\nexport const DEFAULT_EMBEDDING_MODEL = 'Xenova/all-MiniLM-L6-v2';\n\n// MCP server configuration\nexport const DEFAULT_PORT = 7133; // LIEN in leetspeak\nexport const VERSION_CHECK_INTERVAL_MS = 2000;\n\n// Git detection\nexport const DEFAULT_GIT_POLL_INTERVAL_MS = 10000; // Check every 10 seconds\n\n// File watching\nexport const DEFAULT_DEBOUNCE_MS = 1000;\n\n// Configuration version - always matches package version\n// Config format is tied to the package release that introduces it\nexport const CURRENT_CONFIG_VERSION = getPackageVersion();\n\n// Index format version - bump on ANY breaking change to indexing\n// Examples that require version bump:\n// - Chunking algorithm changes\n// - Embedding model changes (e.g., switch from all-MiniLM-L6-v2 to another model)\n// - Vector DB schema changes (new metadata fields)\n// - Metadata structure changes\n// v2: AST-based chunking + enhanced metadata (symbolName, complexity, etc.)\n// v3: Added cognitiveComplexity field to schema\n// v4: Added Halstead metrics (volume, difficulty, effort, bugs)\nexport const INDEX_FORMAT_VERSION = 4;\n\n","import {\n DEFAULT_CHUNK_SIZE,\n DEFAULT_CHUNK_OVERLAP,\n DEFAULT_CONCURRENCY,\n DEFAULT_EMBEDDING_BATCH_SIZE,\n DEFAULT_PORT,\n DEFAULT_GIT_POLL_INTERVAL_MS,\n DEFAULT_DEBOUNCE_MS,\n CURRENT_CONFIG_VERSION,\n} from '../constants.js';\n\n/**\n * Framework-specific configuration\n */\nexport interface FrameworkConfig {\n include: string[]; // File patterns relative to framework path\n exclude: string[]; // Exclude patterns relative to framework path\n}\n\n/**\n * Framework instance in a monorepo\n */\nexport interface FrameworkInstance {\n name: string; // 'nodejs', 'laravel'\n path: string; // '.', 'cognito-backend', 'packages/cli'\n enabled: boolean;\n config: FrameworkConfig;\n}\n\n/**\n * Main Lien configuration supporting monorepo setups\n */\nexport interface LienConfig {\n version: string;\n core: {\n chunkSize: number;\n chunkOverlap: number;\n concurrency: number;\n embeddingBatchSize: number;\n };\n chunking: {\n useAST: boolean; // Enable AST-based chunking (v0.13.0)\n astFallback: 'line-based' | 'error'; // Fallback strategy on AST errors\n };\n mcp: {\n port: number;\n transport: 'stdio' | 'socket';\n autoIndexOnFirstRun: boolean;\n };\n gitDetection: {\n enabled: boolean;\n pollIntervalMs: number;\n };\n fileWatching: {\n enabled: boolean;\n debounceMs: number;\n };\n complexity?: {\n enabled: boolean;\n thresholds: {\n testPaths: number; // 🔀 Max test paths per function (default: 15)\n mentalLoad: number; // 🧠 Max mental load score (default: 15)\n timeToUnderstandMinutes?: number; // ⏱️ Max minutes to understand (default: 60)\n estimatedBugs?: number; // 🐛 Max estimated bugs (default: 1.5)\n };\n // Severity multipliers are hardcoded: warning = 1x threshold, error = 2x threshold\n };\n frameworks: FrameworkInstance[];\n}\n\n/**\n * Legacy config format for backwards compatibility\n * @deprecated Use LienConfig with frameworks array instead\n */\nexport interface LegacyLienConfig {\n version: string;\n indexing: {\n exclude: string[];\n include: string[];\n chunkSize: number;\n chunkOverlap: number;\n concurrency: number;\n embeddingBatchSize: number;\n };\n mcp: {\n port: number;\n transport: 'stdio' | 'socket';\n autoIndexOnFirstRun: boolean;\n };\n gitDetection: {\n enabled: boolean;\n pollIntervalMs: number;\n };\n fileWatching: {\n enabled: boolean;\n debounceMs: number;\n };\n}\n\n/**\n * Type guard to check if a config is the legacy format\n * @param config - Config object to check\n * @returns True if config is LegacyLienConfig\n */\nexport function isLegacyConfig(\n config: LienConfig | LegacyLienConfig\n): config is LegacyLienConfig {\n return 'indexing' in config && !('frameworks' in config);\n}\n\n/**\n * Type guard to check if a config is the modern format\n * @param config - Config object to check\n * @returns True if config is LienConfig\n */\nexport function isModernConfig(\n config: LienConfig | LegacyLienConfig\n): config is LienConfig {\n return 'frameworks' in config;\n}\n\n/**\n * Default configuration with empty frameworks array\n * Frameworks should be detected and added via lien init\n */\nexport const defaultConfig: LienConfig = {\n version: CURRENT_CONFIG_VERSION,\n core: {\n chunkSize: DEFAULT_CHUNK_SIZE,\n chunkOverlap: DEFAULT_CHUNK_OVERLAP,\n concurrency: DEFAULT_CONCURRENCY,\n embeddingBatchSize: DEFAULT_EMBEDDING_BATCH_SIZE,\n },\n chunking: {\n useAST: true, // AST-based chunking enabled by default (v0.13.0)\n astFallback: 'line-based', // Fallback to line-based on errors\n },\n mcp: {\n port: DEFAULT_PORT,\n transport: 'stdio',\n autoIndexOnFirstRun: true,\n },\n gitDetection: {\n enabled: true,\n pollIntervalMs: DEFAULT_GIT_POLL_INTERVAL_MS,\n },\n fileWatching: {\n enabled: true, // Enabled by default (fast with incremental indexing!)\n debounceMs: DEFAULT_DEBOUNCE_MS,\n },\n complexity: {\n enabled: true,\n thresholds: {\n testPaths: 15, // 🔀 Max test paths per function\n mentalLoad: 15, // 🧠 Max mental load score\n timeToUnderstandMinutes: 60, // ⏱️ Functions taking >1 hour to understand\n estimatedBugs: 1.5, // 🐛 Functions estimated to have >1.5 bugs\n },\n },\n frameworks: [], // Will be populated by lien init via framework detection\n};\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { LienConfig, LegacyLienConfig, FrameworkInstance, defaultConfig } from './schema.js';\nimport { CURRENT_CONFIG_VERSION } from '../constants.js';\n\n/**\n * Checks if a config object needs migration from v0.2.0 to v0.3.0\n */\nexport function needsMigration(config: any): boolean {\n // Check if config uses old structure:\n // - Has 'indexing' field instead of 'core' and 'frameworks'\n // - Or has no 'frameworks' field at all\n // - Or version is explicitly set to something < 0.3.0\n // - Or missing 'chunking' field (v0.13.0)\n if (!config) {\n return false;\n }\n\n // If missing chunking config, needs migration to v0.13.0\n if (config.frameworks !== undefined && !config.chunking) {\n return true;\n }\n\n // If it has frameworks array and chunking, it's already in new format\n if (config.frameworks !== undefined && config.chunking !== undefined) {\n return false;\n }\n\n // If it has 'indexing' field, it's the old format\n if (config.indexing !== undefined) {\n return true;\n }\n\n // If version is explicitly < 0.3.0\n if (config.version && config.version.startsWith('0.2')) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Migrates a v0.2.0 config to v0.3.0+ format\n */\nexport function migrateConfig(oldConfig: Partial<LegacyLienConfig | LienConfig>): LienConfig {\n // Start with default config structure\n const newConfig: LienConfig = {\n version: CURRENT_CONFIG_VERSION,\n core: {\n chunkSize: (oldConfig as any).indexing?.chunkSize ?? (oldConfig as any).core?.chunkSize ?? defaultConfig.core.chunkSize,\n chunkOverlap: (oldConfig as any).indexing?.chunkOverlap ?? (oldConfig as any).core?.chunkOverlap ?? defaultConfig.core.chunkOverlap,\n concurrency: (oldConfig as any).indexing?.concurrency ?? (oldConfig as any).core?.concurrency ?? defaultConfig.core.concurrency,\n embeddingBatchSize: (oldConfig as any).indexing?.embeddingBatchSize ?? (oldConfig as any).core?.embeddingBatchSize ?? defaultConfig.core.embeddingBatchSize,\n },\n chunking: {\n useAST: (oldConfig as any).chunking?.useAST ?? defaultConfig.chunking.useAST,\n astFallback: (oldConfig as any).chunking?.astFallback ?? defaultConfig.chunking.astFallback,\n },\n mcp: {\n port: oldConfig.mcp?.port ?? defaultConfig.mcp.port,\n transport: oldConfig.mcp?.transport ?? defaultConfig.mcp.transport,\n autoIndexOnFirstRun: oldConfig.mcp?.autoIndexOnFirstRun ?? defaultConfig.mcp.autoIndexOnFirstRun,\n },\n gitDetection: {\n enabled: oldConfig.gitDetection?.enabled ?? defaultConfig.gitDetection.enabled,\n pollIntervalMs: oldConfig.gitDetection?.pollIntervalMs ?? defaultConfig.gitDetection.pollIntervalMs,\n },\n fileWatching: {\n enabled: oldConfig.fileWatching?.enabled ?? defaultConfig.fileWatching.enabled,\n debounceMs: oldConfig.fileWatching?.debounceMs ?? defaultConfig.fileWatching.debounceMs,\n },\n frameworks: (oldConfig as any).frameworks ?? [],\n };\n\n // Convert old indexing config to a single \"generic\" framework (only for legacy configs)\n if ((oldConfig as any).indexing && newConfig.frameworks.length === 0) {\n const genericFramework: FrameworkInstance = {\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: (oldConfig as any).indexing.include ?? ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: (oldConfig as any).indexing.exclude ?? [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n };\n\n newConfig.frameworks.push(genericFramework);\n } else if (newConfig.frameworks.length === 0) {\n // No indexing config and no frameworks present, use defaults for generic framework\n const genericFramework: FrameworkInstance = {\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n };\n\n newConfig.frameworks.push(genericFramework);\n }\n\n return newConfig;\n}\n\n/**\n * Migrates config file and creates backup\n */\nexport async function migrateConfigFile(rootDir: string = process.cwd()): Promise<{\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}> {\n const configPath = path.join(rootDir, '.lien.config.json');\n\n try {\n // Read existing config\n const configContent = await fs.readFile(configPath, 'utf-8');\n const oldConfig = JSON.parse(configContent);\n\n // Check if migration is needed\n if (!needsMigration(oldConfig)) {\n return {\n migrated: false,\n config: oldConfig as LienConfig,\n };\n }\n\n // Perform migration\n const newConfig = migrateConfig(oldConfig);\n\n // Create backup\n const backupPath = `${configPath}.v0.2.0.backup`;\n await fs.copyFile(configPath, backupPath);\n\n // Write migrated config\n await fs.writeFile(configPath, JSON.stringify(newConfig, null, 2) + '\\n', 'utf-8');\n\n return {\n migrated: true,\n backupPath,\n config: newConfig,\n };\n } catch (error) {\n // If config doesn't exist, return default\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return {\n migrated: false,\n config: defaultConfig,\n };\n }\n throw error;\n }\n}\n\n","import { LienConfig } from './schema.js';\n\n/**\n * Deep merges user config with defaults, preserving user customizations.\n * User values always take precedence over defaults.\n * \n * @param defaults - The default configuration\n * @param user - The user's partial configuration\n * @returns Complete merged configuration\n */\nexport function deepMergeConfig(defaults: LienConfig, user: Partial<LienConfig>): LienConfig {\n return {\n version: user.version ?? defaults.version,\n core: {\n ...defaults.core,\n ...user.core,\n },\n chunking: {\n ...defaults.chunking,\n ...user.chunking,\n },\n mcp: {\n ...defaults.mcp,\n ...user.mcp,\n },\n gitDetection: {\n ...defaults.gitDetection,\n ...user.gitDetection,\n },\n fileWatching: {\n ...defaults.fileWatching,\n ...user.fileWatching,\n },\n complexity: user.complexity ? {\n enabled: user.complexity.enabled ?? defaults.complexity?.enabled ?? true,\n thresholds: {\n ...defaults.complexity?.thresholds,\n ...(user.complexity.thresholds || {}),\n },\n } : defaults.complexity,\n frameworks: user.frameworks ?? defaults.frameworks,\n };\n}\n\n/**\n * Detects new fields that exist in the 'after' config but not in the 'before' config.\n * Returns a list of human-readable field paths.\n * \n * @param before - The existing config (potentially missing fields)\n * @param after - The complete config with all fields\n * @returns Array of new field paths (e.g., [\"mcp.autoIndexOnFirstRun\", \"gitDetection\"])\n */\nexport function detectNewFields(before: Record<string, any>, after: Record<string, any>): string[] {\n const newFields: string[] = [];\n\n // Check top-level sections\n for (const key of Object.keys(after)) {\n if (!(key in before)) {\n newFields.push(key);\n continue;\n }\n\n // Check nested fields for object sections\n if (typeof after[key] === 'object' && after[key] !== null && !Array.isArray(after[key])) {\n const beforeSection = (before[key] as Record<string, any>) || {};\n const afterSection = after[key] as Record<string, any>;\n\n for (const nestedKey of Object.keys(afterSection)) {\n if (!(nestedKey in beforeSection)) {\n newFields.push(`${key}.${nestedKey}`);\n }\n }\n }\n }\n\n return newFields;\n}\n\n","/**\n * Error codes for all Lien-specific errors.\n * Used to identify error types programmatically.\n */\nexport enum LienErrorCode {\n // Configuration\n CONFIG_NOT_FOUND = 'CONFIG_NOT_FOUND',\n CONFIG_INVALID = 'CONFIG_INVALID',\n \n // Index\n INDEX_NOT_FOUND = 'INDEX_NOT_FOUND',\n INDEX_CORRUPTED = 'INDEX_CORRUPTED',\n \n // Embeddings\n EMBEDDING_MODEL_FAILED = 'EMBEDDING_MODEL_FAILED',\n EMBEDDING_GENERATION_FAILED = 'EMBEDDING_GENERATION_FAILED',\n \n // File System\n FILE_NOT_FOUND = 'FILE_NOT_FOUND',\n FILE_NOT_READABLE = 'FILE_NOT_READABLE',\n INVALID_PATH = 'INVALID_PATH',\n \n // Tool Input\n INVALID_INPUT = 'INVALID_INPUT',\n \n // System\n INTERNAL_ERROR = 'INTERNAL_ERROR',\n}\n\n","import { LienErrorCode } from './codes.js';\n\n// Re-export for consumers\nexport { LienErrorCode } from './codes.js';\n\n/**\n * Severity levels for errors\n */\nexport type ErrorSeverity = 'low' | 'medium' | 'high' | 'critical';\n\n/**\n * Base error class for all Lien-specific errors\n */\nexport class LienError extends Error {\n constructor(\n message: string,\n public readonly code: LienErrorCode,\n public readonly context?: Record<string, unknown>,\n public readonly severity: ErrorSeverity = 'medium',\n public readonly recoverable: boolean = true,\n public readonly retryable: boolean = false\n ) {\n super(message);\n this.name = 'LienError';\n \n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n \n /**\n * Serialize error to JSON for MCP responses\n */\n toJSON() {\n return {\n error: this.message,\n code: this.code,\n severity: this.severity,\n recoverable: this.recoverable,\n context: this.context,\n };\n }\n \n /**\n * Check if this error is retryable\n */\n isRetryable(): boolean {\n return this.retryable;\n }\n \n /**\n * Check if this error is recoverable\n */\n isRecoverable(): boolean {\n return this.recoverable;\n }\n}\n\n/**\n * Configuration-related errors (loading, parsing, migration)\n */\nexport class ConfigError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.CONFIG_INVALID, context, 'medium', true, false);\n this.name = 'ConfigError';\n }\n}\n\n/**\n * Indexing-related errors (file processing, chunking)\n */\nexport class IndexingError extends LienError {\n constructor(\n message: string,\n public readonly file?: string,\n context?: Record<string, unknown>\n ) {\n super(message, LienErrorCode.INTERNAL_ERROR, { ...context, file }, 'medium', true, false);\n this.name = 'IndexingError';\n }\n}\n\n/**\n * Embedding generation errors\n */\nexport class EmbeddingError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.EMBEDDING_GENERATION_FAILED, context, 'high', true, true);\n this.name = 'EmbeddingError';\n }\n}\n\n/**\n * Vector database errors (connection, query, storage)\n */\nexport class DatabaseError extends LienError {\n constructor(message: string, context?: Record<string, unknown>) {\n super(message, LienErrorCode.INTERNAL_ERROR, context, 'high', true, true);\n this.name = 'DatabaseError';\n }\n}\n\n/**\n * Helper function to wrap unknown errors with context\n * @param error - Unknown error object to wrap\n * @param context - Context message describing what operation failed\n * @param additionalContext - Optional additional context data\n * @returns LienError with proper message and context\n */\nexport function wrapError(\n error: unknown,\n context: string,\n additionalContext?: Record<string, unknown>\n): LienError {\n const message = error instanceof Error ? error.message : String(error);\n const stack = error instanceof Error ? error.stack : undefined;\n \n const wrappedError = new LienError(\n `${context}: ${message}`,\n LienErrorCode.INTERNAL_ERROR,\n additionalContext\n );\n \n // Preserve original stack trace if available\n if (stack) {\n wrappedError.stack = `${wrappedError.stack}\\n\\nCaused by:\\n${stack}`;\n }\n \n return wrappedError;\n}\n\n/**\n * Type guard to check if an error is a LienError\n */\nexport function isLienError(error: unknown): error is LienError {\n return error instanceof LienError;\n}\n\n/**\n * Extract error message from unknown error type\n * @param error - Unknown error object\n * @returns Error message string\n */\nexport function getErrorMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n}\n\n/**\n * Extract stack trace from unknown error type\n * @param error - Unknown error object\n * @returns Stack trace string or undefined\n */\nexport function getErrorStack(error: unknown): string | undefined {\n if (error instanceof Error) {\n return error.stack;\n }\n return undefined;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { LienConfig, LegacyLienConfig, defaultConfig, isLegacyConfig, isModernConfig } from './schema.js';\nimport { deepMergeConfig } from './merge.js';\nimport { needsMigration as checkNeedsMigration, migrateConfig as performMigration } from './migration.js';\nimport { ConfigError, wrapError } from '../errors/index.js';\n\n/**\n * Validation result with errors and warnings\n */\nexport interface ValidationResult {\n valid: boolean;\n errors: string[];\n warnings: string[];\n}\n\n/**\n * Migration result with status and config\n */\nexport interface MigrationResult {\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}\n\n/**\n * ConfigService encapsulates all configuration operations including\n * loading, saving, migration, and validation.\n * \n * This service provides a single point of truth for config management\n * with comprehensive error handling and validation.\n */\nexport class ConfigService {\n private static readonly CONFIG_FILENAME = '.lien.config.json';\n \n /**\n * Load configuration from the specified directory.\n * Automatically handles migration if needed.\n * \n * @param rootDir - Root directory containing the config file\n * @returns Loaded and validated configuration\n * @throws {ConfigError} If config is invalid or cannot be loaded\n */\n async load(rootDir: string = process.cwd()): Promise<LienConfig> {\n const configPath = this.getConfigPath(rootDir);\n \n try {\n const configContent = await fs.readFile(configPath, 'utf-8');\n const userConfig = JSON.parse(configContent);\n \n // Check if migration is needed\n if (this.needsMigration(userConfig)) {\n console.log('🔄 Migrating config from v0.2.0 to v0.3.0...');\n \n const result = await this.migrate(rootDir);\n \n if (result.migrated && result.backupPath) {\n const backupFilename = path.basename(result.backupPath);\n console.log(`✅ Migration complete! Backup saved as ${backupFilename}`);\n console.log('📝 Your config now uses the framework-based structure.');\n }\n \n return result.config;\n }\n \n // Merge with defaults first\n const mergedConfig = deepMergeConfig(defaultConfig, userConfig as Partial<LienConfig>);\n \n // Then validate the merged config\n const validation = this.validate(mergedConfig);\n if (!validation.valid) {\n throw new ConfigError(\n `Invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors, warnings: validation.warnings }\n );\n }\n \n // Show warnings if any\n if (validation.warnings.length > 0) {\n console.warn('⚠️ Configuration warnings:');\n validation.warnings.forEach(warning => console.warn(` ${warning}`));\n }\n \n return mergedConfig;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n // Config doesn't exist, return defaults\n return defaultConfig;\n }\n \n if (error instanceof ConfigError) {\n throw error;\n }\n \n if (error instanceof SyntaxError) {\n throw new ConfigError(\n 'Failed to parse config file: Invalid JSON syntax',\n { path: configPath, originalError: error.message }\n );\n }\n \n throw wrapError(error, 'Failed to load configuration', { path: configPath });\n }\n }\n \n /**\n * Save configuration to the specified directory.\n * Validates the config before saving.\n * \n * @param rootDir - Root directory to save the config file\n * @param config - Configuration to save\n * @throws {ConfigError} If config is invalid or cannot be saved\n */\n async save(rootDir: string, config: LienConfig): Promise<void> {\n const configPath = this.getConfigPath(rootDir);\n \n // Validate before saving\n const validation = this.validate(config);\n if (!validation.valid) {\n throw new ConfigError(\n `Cannot save invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors }\n );\n }\n \n try {\n const configJson = JSON.stringify(config, null, 2) + '\\n';\n await fs.writeFile(configPath, configJson, 'utf-8');\n } catch (error) {\n throw wrapError(error, 'Failed to save configuration', { path: configPath });\n }\n }\n \n /**\n * Check if a configuration file exists in the specified directory.\n * \n * @param rootDir - Root directory to check\n * @returns True if config file exists\n */\n async exists(rootDir: string = process.cwd()): Promise<boolean> {\n const configPath = this.getConfigPath(rootDir);\n try {\n await fs.access(configPath);\n return true;\n } catch {\n return false;\n }\n }\n \n /**\n * Migrate configuration from v0.2.0 to v0.3.0 format.\n * Creates a backup of the original config file.\n * \n * @param rootDir - Root directory containing the config file\n * @returns Migration result with status and new config\n * @throws {ConfigError} If migration fails\n */\n async migrate(rootDir: string = process.cwd()): Promise<MigrationResult> {\n const configPath = this.getConfigPath(rootDir);\n \n try {\n // Read existing config\n const configContent = await fs.readFile(configPath, 'utf-8');\n const oldConfig = JSON.parse(configContent);\n \n // Check if migration is needed\n if (!this.needsMigration(oldConfig)) {\n return {\n migrated: false,\n config: oldConfig as LienConfig,\n };\n }\n \n // Perform migration\n const newConfig = performMigration(oldConfig);\n \n // Validate migrated config\n const validation = this.validate(newConfig);\n if (!validation.valid) {\n throw new ConfigError(\n `Migration produced invalid configuration:\\n${validation.errors.join('\\n')}`,\n { errors: validation.errors }\n );\n }\n \n // Create backup\n const backupPath = `${configPath}.v0.2.0.backup`;\n await fs.copyFile(configPath, backupPath);\n \n // Write migrated config\n await this.save(rootDir, newConfig);\n \n return {\n migrated: true,\n backupPath,\n config: newConfig,\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return {\n migrated: false,\n config: defaultConfig,\n };\n }\n \n if (error instanceof ConfigError) {\n throw error;\n }\n \n throw wrapError(error, 'Configuration migration failed', { path: configPath });\n }\n }\n \n /**\n * Check if a config object needs migration from v0.2.0 to v0.3.0.\n * \n * @param config - Config object to check\n * @returns True if migration is needed\n */\n needsMigration(config: unknown): boolean {\n return checkNeedsMigration(config);\n }\n \n /**\n * Validate a configuration object.\n * Checks all constraints and returns detailed validation results.\n * \n * @param config - Configuration to validate\n * @returns Validation result with errors and warnings\n */\n validate(config: unknown): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n \n // Type check\n if (!config || typeof config !== 'object') {\n return {\n valid: false,\n errors: ['Configuration must be an object'],\n warnings: [],\n };\n }\n \n const cfg = config as Partial<LienConfig>;\n \n // Check for required top-level fields\n if (!cfg.version) {\n errors.push('Missing required field: version');\n }\n \n // Validate based on config type\n if (isModernConfig(cfg as LienConfig | LegacyLienConfig)) {\n this.validateModernConfig(cfg as LienConfig, errors, warnings);\n } else if (isLegacyConfig(cfg as LienConfig | LegacyLienConfig)) {\n this.validateLegacyConfig(cfg as LegacyLienConfig, errors, warnings);\n } else {\n errors.push('Configuration format not recognized. Must have either \"frameworks\" or \"indexing\" field');\n }\n \n return {\n valid: errors.length === 0,\n errors,\n warnings,\n };\n }\n \n /**\n * Validate a partial configuration object.\n * Useful for validating user input before merging with defaults.\n * \n * @param config - Partial configuration to validate\n * @returns Validation result with errors and warnings\n */\n validatePartial(config: Partial<LienConfig>): ValidationResult {\n const errors: string[] = [];\n const warnings: string[] = [];\n \n // Validate core settings if present\n if (config.core) {\n this.validateCoreConfig(config.core, errors, warnings);\n }\n \n // Validate MCP settings if present\n if (config.mcp) {\n this.validateMCPConfig(config.mcp, errors, warnings);\n }\n \n // Validate git detection settings if present\n if (config.gitDetection) {\n this.validateGitDetectionConfig(config.gitDetection, errors, warnings);\n }\n \n // Validate file watching settings if present\n if (config.fileWatching) {\n this.validateFileWatchingConfig(config.fileWatching, errors, warnings);\n }\n \n // Validate frameworks if present\n if (config.frameworks) {\n this.validateFrameworks(config.frameworks, errors, warnings);\n }\n \n return {\n valid: errors.length === 0,\n errors,\n warnings,\n };\n }\n \n /**\n * Get the full path to the config file\n */\n private getConfigPath(rootDir: string): string {\n return path.join(rootDir, ConfigService.CONFIG_FILENAME);\n }\n \n /**\n * Validate modern (v0.3.0+) configuration\n */\n private validateModernConfig(\n config: LienConfig,\n errors: string[],\n warnings: string[]\n ): void {\n // Validate core settings\n if (!config.core) {\n errors.push('Missing required field: core');\n return;\n }\n this.validateCoreConfig(config.core, errors, warnings);\n \n // Validate MCP settings\n if (!config.mcp) {\n errors.push('Missing required field: mcp');\n return;\n }\n this.validateMCPConfig(config.mcp, errors, warnings);\n \n // Validate git detection settings\n if (!config.gitDetection) {\n errors.push('Missing required field: gitDetection');\n return;\n }\n this.validateGitDetectionConfig(config.gitDetection, errors, warnings);\n \n // Validate file watching settings\n if (!config.fileWatching) {\n errors.push('Missing required field: fileWatching');\n return;\n }\n this.validateFileWatchingConfig(config.fileWatching, errors, warnings);\n \n // Validate frameworks\n if (!config.frameworks) {\n errors.push('Missing required field: frameworks');\n return;\n }\n this.validateFrameworks(config.frameworks, errors, warnings);\n }\n \n /**\n * Validate legacy (v0.2.0) configuration\n */\n private validateLegacyConfig(\n config: LegacyLienConfig,\n errors: string[],\n warnings: string[]\n ): void {\n warnings.push('Using legacy configuration format. Consider running \"lien init\" to migrate to v0.3.0');\n \n // Validate indexing settings\n if (!config.indexing) {\n errors.push('Missing required field: indexing');\n return;\n }\n \n const { indexing } = config;\n \n if (typeof indexing.chunkSize !== 'number' || indexing.chunkSize <= 0) {\n errors.push('indexing.chunkSize must be a positive number');\n }\n \n if (typeof indexing.chunkOverlap !== 'number' || indexing.chunkOverlap < 0) {\n errors.push('indexing.chunkOverlap must be a non-negative number');\n }\n \n if (typeof indexing.concurrency !== 'number' || indexing.concurrency < 1 || indexing.concurrency > 16) {\n errors.push('indexing.concurrency must be between 1 and 16');\n }\n \n if (typeof indexing.embeddingBatchSize !== 'number' || indexing.embeddingBatchSize <= 0) {\n errors.push('indexing.embeddingBatchSize must be a positive number');\n }\n \n // Validate MCP settings (same for both)\n if (config.mcp) {\n this.validateMCPConfig(config.mcp, errors, warnings);\n }\n }\n \n /**\n * Validate core configuration settings\n */\n private validateCoreConfig(\n core: Partial<LienConfig['core']>,\n errors: string[],\n warnings: string[]\n ): void {\n if (core.chunkSize !== undefined) {\n if (typeof core.chunkSize !== 'number' || core.chunkSize <= 0) {\n errors.push('core.chunkSize must be a positive number');\n } else if (core.chunkSize < 50) {\n warnings.push('core.chunkSize is very small (<50 lines). This may result in poor search quality');\n } else if (core.chunkSize > 500) {\n warnings.push('core.chunkSize is very large (>500 lines). This may impact performance');\n }\n }\n \n if (core.chunkOverlap !== undefined) {\n if (typeof core.chunkOverlap !== 'number' || core.chunkOverlap < 0) {\n errors.push('core.chunkOverlap must be a non-negative number');\n }\n }\n \n if (core.concurrency !== undefined) {\n if (typeof core.concurrency !== 'number' || core.concurrency < 1 || core.concurrency > 16) {\n errors.push('core.concurrency must be between 1 and 16');\n }\n }\n \n if (core.embeddingBatchSize !== undefined) {\n if (typeof core.embeddingBatchSize !== 'number' || core.embeddingBatchSize <= 0) {\n errors.push('core.embeddingBatchSize must be a positive number');\n } else if (core.embeddingBatchSize > 100) {\n warnings.push('core.embeddingBatchSize is very large (>100). This may cause memory issues');\n }\n }\n }\n \n /**\n * Validate MCP configuration settings\n */\n private validateMCPConfig(\n mcp: Partial<LienConfig['mcp']>,\n errors: string[],\n _warnings: string[]\n ): void {\n if (mcp.port !== undefined) {\n if (typeof mcp.port !== 'number' || mcp.port < 1024 || mcp.port > 65535) {\n errors.push('mcp.port must be between 1024 and 65535');\n }\n }\n \n if (mcp.transport !== undefined) {\n if (mcp.transport !== 'stdio' && mcp.transport !== 'socket') {\n errors.push('mcp.transport must be either \"stdio\" or \"socket\"');\n }\n }\n \n if (mcp.autoIndexOnFirstRun !== undefined) {\n if (typeof mcp.autoIndexOnFirstRun !== 'boolean') {\n errors.push('mcp.autoIndexOnFirstRun must be a boolean');\n }\n }\n }\n \n /**\n * Validate git detection configuration settings\n */\n private validateGitDetectionConfig(\n gitDetection: Partial<LienConfig['gitDetection']>,\n errors: string[],\n _warnings: string[]\n ): void {\n if (gitDetection.enabled !== undefined) {\n if (typeof gitDetection.enabled !== 'boolean') {\n errors.push('gitDetection.enabled must be a boolean');\n }\n }\n \n if (gitDetection.pollIntervalMs !== undefined) {\n if (typeof gitDetection.pollIntervalMs !== 'number' || gitDetection.pollIntervalMs < 100) {\n errors.push('gitDetection.pollIntervalMs must be at least 100ms');\n } else if (gitDetection.pollIntervalMs < 1000) {\n _warnings.push('gitDetection.pollIntervalMs is very short (<1s). This may impact performance');\n }\n }\n }\n \n /**\n * Validate file watching configuration settings\n */\n private validateFileWatchingConfig(\n fileWatching: Partial<LienConfig['fileWatching']>,\n errors: string[],\n warnings: string[]\n ): void {\n if (fileWatching.enabled !== undefined) {\n if (typeof fileWatching.enabled !== 'boolean') {\n errors.push('fileWatching.enabled must be a boolean');\n }\n }\n \n if (fileWatching.debounceMs !== undefined) {\n if (typeof fileWatching.debounceMs !== 'number' || fileWatching.debounceMs < 0) {\n errors.push('fileWatching.debounceMs must be a non-negative number');\n } else if (fileWatching.debounceMs < 100) {\n warnings.push('fileWatching.debounceMs is very short (<100ms). This may cause excessive reindexing');\n }\n }\n }\n \n /**\n * Validate frameworks configuration\n */\n private validateFrameworks(\n frameworks: unknown[],\n errors: string[],\n warnings: string[]\n ): void {\n if (!Array.isArray(frameworks)) {\n errors.push('frameworks must be an array');\n return;\n }\n \n frameworks.forEach((framework, index) => {\n if (!framework || typeof framework !== 'object') {\n errors.push(`frameworks[${index}] must be an object`);\n return;\n }\n \n const fw = framework as Partial<any>;\n \n // Validate required fields\n if (!fw.name) {\n errors.push(`frameworks[${index}] missing required field: name`);\n }\n \n if (fw.path === undefined) {\n errors.push(`frameworks[${index}] missing required field: path`);\n } else if (typeof fw.path !== 'string') {\n errors.push(`frameworks[${index}].path must be a string`);\n } else if (path.isAbsolute(fw.path)) {\n errors.push(`frameworks[${index}].path must be relative, got: ${fw.path}`);\n }\n \n if (fw.enabled === undefined) {\n errors.push(`frameworks[${index}] missing required field: enabled`);\n } else if (typeof fw.enabled !== 'boolean') {\n errors.push(`frameworks[${index}].enabled must be a boolean`);\n }\n \n if (!fw.config) {\n errors.push(`frameworks[${index}] missing required field: config`);\n } else {\n this.validateFrameworkConfig(fw.config, `frameworks[${index}].config`, errors, warnings);\n }\n });\n }\n \n /**\n * Validate framework-specific configuration\n */\n private validateFrameworkConfig(\n config: any,\n prefix: string,\n errors: string[],\n _warnings: string[]\n ): void {\n if (!config || typeof config !== 'object') {\n errors.push(`${prefix} must be an object`);\n return;\n }\n \n // Validate include patterns\n if (!Array.isArray(config.include)) {\n errors.push(`${prefix}.include must be an array`);\n } else {\n config.include.forEach((pattern: unknown, i: number) => {\n if (typeof pattern !== 'string') {\n errors.push(`${prefix}.include[${i}] must be a string`);\n }\n });\n }\n \n // Validate exclude patterns\n if (!Array.isArray(config.exclude)) {\n errors.push(`${prefix}.exclude must be an array`);\n } else {\n config.exclude.forEach((pattern: unknown, i: number) => {\n if (typeof pattern !== 'string') {\n errors.push(`${prefix}.exclude[${i}] must be a string`);\n }\n });\n }\n }\n}\n\n// Export a singleton instance for convenience\nexport const configService = new ConfigService();\n\n","import { exec } from 'child_process';\nimport { promisify } from 'util';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nconst execAsync = promisify(exec);\n\n/**\n * Checks if a directory is a git repository.\n * \n * @param rootDir - Directory to check\n * @returns true if directory is a git repo, false otherwise\n */\nexport async function isGitRepo(rootDir: string): Promise<boolean> {\n try {\n const gitDir = path.join(rootDir, '.git');\n await fs.access(gitDir);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Gets the current git branch name.\n * \n * @param rootDir - Root directory of the git repository\n * @returns Branch name (e.g., \"main\", \"feature-branch\")\n * @throws Error if not a git repo or git command fails\n */\nexport async function getCurrentBranch(rootDir: string): Promise<string> {\n try {\n const { stdout } = await execAsync('git rev-parse --abbrev-ref HEAD', {\n cwd: rootDir,\n timeout: 5000, // 5 second timeout\n });\n return stdout.trim();\n } catch (error) {\n throw new Error(`Failed to get current branch: ${error}`);\n }\n}\n\n/**\n * Gets the current git commit SHA (HEAD).\n * \n * @param rootDir - Root directory of the git repository\n * @returns Commit SHA (full 40-character hash)\n * @throws Error if not a git repo or git command fails\n */\nexport async function getCurrentCommit(rootDir: string): Promise<string> {\n try {\n const { stdout } = await execAsync('git rev-parse HEAD', {\n cwd: rootDir,\n timeout: 5000,\n });\n return stdout.trim();\n } catch (error) {\n throw new Error(`Failed to get current commit: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed between two git references.\n * \n * @param rootDir - Root directory of the git repository\n * @param fromRef - Starting reference (branch name, commit SHA, or tag)\n * @param toRef - Ending reference (branch name, commit SHA, or tag)\n * @returns Array of file paths (relative to repo root) that changed\n * @throws Error if git command fails\n */\nexport async function getChangedFiles(\n rootDir: string,\n fromRef: string,\n toRef: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff --name-only ${fromRef}...${toRef}`,\n {\n cwd: rootDir,\n timeout: 10000, // 10 second timeout for diffs\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed in a specific commit.\n * \n * @param rootDir - Root directory of the git repository\n * @param commitSha - Commit SHA to check\n * @returns Array of file paths (absolute) that changed in this commit\n * @throws Error if git command fails\n */\nexport async function getChangedFilesInCommit(\n rootDir: string,\n commitSha: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff-tree --no-commit-id --name-only -r ${commitSha}`,\n {\n cwd: rootDir,\n timeout: 10000,\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files in commit: ${error}`);\n }\n}\n\n/**\n * Gets the list of files that changed between two commits.\n * More efficient than getChangedFiles for commit-to-commit comparisons.\n * \n * @param rootDir - Root directory of the git repository\n * @param fromCommit - Starting commit SHA\n * @param toCommit - Ending commit SHA\n * @returns Array of file paths (absolute) that changed between commits\n * @throws Error if git command fails\n */\nexport async function getChangedFilesBetweenCommits(\n rootDir: string,\n fromCommit: string,\n toCommit: string\n): Promise<string[]> {\n try {\n const { stdout } = await execAsync(\n `git diff --name-only ${fromCommit} ${toCommit}`,\n {\n cwd: rootDir,\n timeout: 10000,\n }\n );\n \n const files = stdout\n .trim()\n .split('\\n')\n .filter(Boolean)\n .map(file => path.join(rootDir, file)); // Convert to absolute paths\n \n return files;\n } catch (error) {\n throw new Error(`Failed to get changed files between commits: ${error}`);\n }\n}\n\n/**\n * Checks if git is installed and available.\n * \n * @returns true if git is available, false otherwise\n */\nexport async function isGitAvailable(): Promise<boolean> {\n try {\n await execAsync('git --version', { timeout: 3000 });\n return true;\n } catch {\n return false;\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\n\nconst VERSION_FILE = '.lien-index-version';\n\n/**\n * Writes a version timestamp file to mark when the index was last updated.\n * This file is used by the MCP server to detect when it needs to reconnect.\n * \n * @param indexPath - Path to the index directory\n */\nexport async function writeVersionFile(indexPath: string): Promise<void> {\n try {\n const versionFilePath = path.join(indexPath, VERSION_FILE);\n const timestamp = Date.now().toString();\n await fs.writeFile(versionFilePath, timestamp, 'utf-8');\n } catch (error) {\n // Don't throw - version file is a convenience feature, not critical\n console.error(`Warning: Failed to write version file: ${error}`);\n }\n}\n\n/**\n * Reads the version timestamp from the index directory.\n * Returns 0 if the file doesn't exist (e.g., old index).\n * \n * @param indexPath - Path to the index directory\n * @returns Version timestamp, or 0 if not found\n */\nexport async function readVersionFile(indexPath: string): Promise<number> {\n try {\n const versionFilePath = path.join(indexPath, VERSION_FILE);\n const content = await fs.readFile(versionFilePath, 'utf-8');\n const timestamp = parseInt(content.trim(), 10);\n return isNaN(timestamp) ? 0 : timestamp;\n } catch (error) {\n // File doesn't exist or can't be read - treat as version 0\n return 0;\n }\n}\n\n","import { glob } from 'glob';\nimport ignore from 'ignore';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { ScanOptions } from './types.js';\nimport { LienConfig, FrameworkInstance } from '../config/schema.js';\n\n/**\n * Scan codebase using framework-aware configuration\n * @param rootDir - Project root directory\n * @param config - Lien configuration with frameworks\n * @returns Array of file paths relative to rootDir\n */\nexport async function scanCodebaseWithFrameworks(\n rootDir: string,\n config: LienConfig\n): Promise<string[]> {\n const allFiles: string[] = [];\n \n // Scan each framework\n for (const framework of config.frameworks) {\n if (!framework.enabled) {\n continue;\n }\n \n const frameworkFiles = await scanFramework(rootDir, framework);\n allFiles.push(...frameworkFiles);\n }\n \n return allFiles;\n}\n\n/**\n * Scan files for a specific framework instance\n */\nasync function scanFramework(\n rootDir: string,\n framework: FrameworkInstance\n): Promise<string[]> {\n const frameworkPath = path.join(rootDir, framework.path);\n \n // Load .gitignore from framework path\n const gitignorePath = path.join(frameworkPath, '.gitignore');\n let ig = ignore();\n \n try {\n const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore in framework path, try root\n const rootGitignorePath = path.join(rootDir, '.gitignore');\n try {\n const gitignoreContent = await fs.readFile(rootGitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore at all, that's fine\n }\n }\n \n // Add framework-specific exclusions\n ig.add([\n ...framework.config.exclude,\n '.lien/**',\n ]);\n \n // Find all files matching framework patterns\n const allFiles: string[] = [];\n \n for (const pattern of framework.config.include) {\n const files = await glob(pattern, {\n cwd: frameworkPath,\n absolute: false, // Get paths relative to framework path\n nodir: true,\n ignore: framework.config.exclude,\n });\n allFiles.push(...files);\n }\n \n // Remove duplicates\n const uniqueFiles = Array.from(new Set(allFiles));\n \n // Filter using ignore patterns and prefix with framework path\n return uniqueFiles\n .filter(file => !ig.ignores(file))\n .map(file => {\n // Return path relative to root: framework.path/file\n return framework.path === '.' \n ? file \n : path.join(framework.path, file);\n });\n}\n\n/**\n * Legacy scan function for backwards compatibility\n * @deprecated Use scanCodebaseWithFrameworks instead\n */\nexport async function scanCodebase(options: ScanOptions): Promise<string[]> {\n const { rootDir, includePatterns = [], excludePatterns = [] } = options;\n \n // Load .gitignore\n const gitignorePath = path.join(rootDir, '.gitignore');\n let ig = ignore();\n \n try {\n const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');\n ig = ignore().add(gitignoreContent);\n } catch (e) {\n // No .gitignore, that's fine\n }\n \n // Add default exclusions\n ig.add([\n 'node_modules/**',\n '.git/**',\n 'dist/**',\n 'build/**',\n '*.min.js',\n '*.min.css',\n '.lien/**',\n ...excludePatterns,\n ]);\n \n // Determine patterns to search for\n const patterns = includePatterns.length > 0 \n ? includePatterns \n : ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,cpp,c,cs,h,md,mdx}'];\n \n // Find all code files\n const allFiles: string[] = [];\n \n for (const pattern of patterns) {\n const files = await glob(pattern, {\n cwd: rootDir,\n absolute: true,\n nodir: true,\n ignore: ['node_modules/**', '.git/**'],\n });\n allFiles.push(...files);\n }\n \n // Remove duplicates\n const uniqueFiles = Array.from(new Set(allFiles));\n \n // Filter using ignore patterns\n return uniqueFiles.filter(file => {\n const relativePath = path.relative(rootDir, file);\n return !ig.ignores(relativePath);\n });\n}\n\nexport function detectLanguage(filepath: string): string {\n const ext = path.extname(filepath).toLowerCase();\n \n const languageMap: Record<string, string> = {\n '.ts': 'typescript',\n '.tsx': 'typescript',\n '.js': 'javascript',\n '.jsx': 'javascript',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n '.vue': 'vue',\n '.py': 'python',\n '.go': 'go',\n '.rs': 'rust',\n '.java': 'java',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.c': 'c',\n '.h': 'c',\n '.hpp': 'cpp',\n '.php': 'php',\n '.rb': 'ruby',\n '.swift': 'swift',\n '.kt': 'kotlin',\n '.cs': 'csharp',\n '.scala': 'scala',\n '.liquid': 'liquid',\n '.md': 'markdown',\n '.mdx': 'markdown',\n '.markdown': 'markdown',\n };\n \n return languageMap[ext] || 'unknown';\n}\n\n","/**\n * Symbol extraction utilities for different programming languages.\n * Extracts function, class, and interface names from code chunks for better indexing.\n */\n\nexport interface ExtractedSymbols {\n functions: string[];\n classes: string[];\n interfaces: string[];\n}\n\n/**\n * Extract symbols (functions, classes, interfaces) from code content.\n * \n * @param content - The code content to extract symbols from\n * @param language - The programming language of the content\n * @returns Extracted symbols organized by type\n */\nexport function extractSymbols(\n content: string,\n language: string\n): ExtractedSymbols {\n const symbols: ExtractedSymbols = {\n functions: [],\n classes: [],\n interfaces: [],\n };\n \n const normalizedLang = language.toLowerCase();\n \n switch (normalizedLang) {\n case 'typescript':\n case 'tsx':\n symbols.functions = extractTSFunctions(content);\n symbols.classes = extractTSClasses(content);\n symbols.interfaces = extractTSInterfaces(content);\n break;\n \n case 'javascript':\n case 'jsx':\n symbols.functions = extractJSFunctions(content);\n symbols.classes = extractJSClasses(content);\n break;\n \n case 'python':\n case 'py':\n symbols.functions = extractPythonFunctions(content);\n symbols.classes = extractPythonClasses(content);\n break;\n \n case 'php':\n symbols.functions = extractPHPFunctions(content);\n symbols.classes = extractPHPClasses(content);\n symbols.interfaces = extractPHPInterfaces(content);\n break;\n \n case 'vue':\n // Extract from <script> blocks (handles both Options API and Composition API)\n symbols.functions = extractVueFunctions(content);\n symbols.classes = extractVueComponents(content);\n break;\n \n case 'go':\n symbols.functions = extractGoFunctions(content);\n symbols.interfaces = extractGoInterfaces(content);\n break;\n \n case 'java':\n symbols.functions = extractJavaFunctions(content);\n symbols.classes = extractJavaClasses(content);\n symbols.interfaces = extractJavaInterfaces(content);\n break;\n \n case 'csharp':\n case 'cs':\n symbols.functions = extractCSharpFunctions(content);\n symbols.classes = extractCSharpClasses(content);\n symbols.interfaces = extractCSharpInterfaces(content);\n break;\n \n case 'ruby':\n case 'rb':\n symbols.functions = extractRubyFunctions(content);\n symbols.classes = extractRubyClasses(content);\n break;\n \n case 'rust':\n case 'rs':\n symbols.functions = extractRustFunctions(content);\n break;\n }\n \n return symbols;\n}\n\n// TypeScript / JavaScript Functions\nfunction extractTSFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Regular functions: function name(...) or async function name(...)\n const functionMatches = content.matchAll(/(?:async\\s+)?function\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Arrow functions: const/let/var name = (...) =>\n const arrowMatches = content.matchAll(/(?:const|let|var)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\([^)]*\\)\\s*=>/g);\n for (const match of arrowMatches) {\n names.add(match[1]);\n }\n \n // Method definitions: name(...) { or async name(...) {\n const methodMatches = content.matchAll(/(?:async\\s+)?(\\w+)\\s*\\([^)]*\\)\\s*[:{]/g);\n for (const match of methodMatches) {\n // Exclude common keywords\n if (!['if', 'for', 'while', 'switch', 'catch'].includes(match[1])) {\n names.add(match[1]);\n }\n }\n \n // Export function\n const exportMatches = content.matchAll(/export\\s+(?:async\\s+)?function\\s+(\\w+)\\s*\\(/g);\n for (const match of exportMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJSFunctions(content: string): string[] {\n return extractTSFunctions(content); // Same patterns\n}\n\nfunction extractTSClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class declarations: class Name or export class Name\n const classMatches = content.matchAll(/(?:export\\s+)?(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJSClasses(content: string): string[] {\n return extractTSClasses(content); // Same patterns\n}\n\nfunction extractTSInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface declarations: interface Name or export interface Name\n const interfaceMatches = content.matchAll(/(?:export\\s+)?interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Type aliases: type Name = or export type Name =\n const typeMatches = content.matchAll(/(?:export\\s+)?type\\s+(\\w+)\\s*=/g);\n for (const match of typeMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Python Functions\nfunction extractPythonFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: def name(...):\n const functionMatches = content.matchAll(/def\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Async functions: async def name(...):\n const asyncMatches = content.matchAll(/async\\s+def\\s+(\\w+)\\s*\\(/g);\n for (const match of asyncMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPythonClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or class Name(Base):\n const classMatches = content.matchAll(/class\\s+(\\w+)(?:\\s*\\(|:)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// PHP Functions\nfunction extractPHPFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: function name(...) or public function name(...)\n const functionMatches = content.matchAll(/(?:public|private|protected)?\\s*function\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPHPClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or abstract class Name\n const classMatches = content.matchAll(/(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractPHPInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: interface Name\n const interfaceMatches = content.matchAll(/interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Trait definitions: trait Name\n const traitMatches = content.matchAll(/trait\\s+(\\w+)/g);\n for (const match of traitMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Go Functions\nfunction extractGoFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: func Name(...) or func (r *Receiver) Name(...)\n const functionMatches = content.matchAll(/func\\s+(?:\\(\\w+\\s+\\*?\\w+\\)\\s+)?(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractGoInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: type Name interface {\n const interfaceMatches = content.matchAll(/type\\s+(\\w+)\\s+interface\\s*\\{/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n // Struct definitions: type Name struct {\n const structMatches = content.matchAll(/type\\s+(\\w+)\\s+struct\\s*\\{/g);\n for (const match of structMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Java Functions\nfunction extractJavaFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: public/private/protected return_type name(...)\n const methodMatches = content.matchAll(/(?:public|private|protected)\\s+(?:static\\s+)?(?:\\w+(?:<[^>]+>)?)\\s+(\\w+)\\s*\\(/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJavaClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: public class Name or abstract class Name\n const classMatches = content.matchAll(/(?:public\\s+)?(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractJavaInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: public interface Name\n const interfaceMatches = content.matchAll(/(?:public\\s+)?interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// C# Functions\nfunction extractCSharpFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: public/private/protected return_type Name(...)\n const methodMatches = content.matchAll(/(?:public|private|protected|internal)\\s+(?:static\\s+)?(?:async\\s+)?(?:\\w+(?:<[^>]+>)?)\\s+(\\w+)\\s*\\(/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractCSharpClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: public class Name or abstract class Name\n const classMatches = content.matchAll(/(?:public|internal)?\\s*(?:abstract\\s+)?class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractCSharpInterfaces(content: string): string[] {\n const names = new Set<string>();\n \n // Interface definitions: public interface Name\n const interfaceMatches = content.matchAll(/(?:public|internal)?\\s*interface\\s+(\\w+)/g);\n for (const match of interfaceMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Ruby Functions\nfunction extractRubyFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Method definitions: def name or def self.name\n const methodMatches = content.matchAll(/def\\s+(?:self\\.)?(\\w+)/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\nfunction extractRubyClasses(content: string): string[] {\n const names = new Set<string>();\n \n // Class definitions: class Name or class Name < Base\n const classMatches = content.matchAll(/class\\s+(\\w+)/g);\n for (const match of classMatches) {\n names.add(match[1]);\n }\n \n // Module definitions: module Name\n const moduleMatches = content.matchAll(/module\\s+(\\w+)/g);\n for (const match of moduleMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Rust Functions\nfunction extractRustFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Function definitions: fn name(...) or pub fn name(...)\n const functionMatches = content.matchAll(/(?:pub\\s+)?fn\\s+(\\w+)\\s*\\(/g);\n for (const match of functionMatches) {\n names.add(match[1]);\n }\n \n // Struct definitions: struct Name {\n const structMatches = content.matchAll(/(?:pub\\s+)?struct\\s+(\\w+)/g);\n for (const match of structMatches) {\n names.add(match[1]);\n }\n \n // Trait definitions: trait Name {\n const traitMatches = content.matchAll(/(?:pub\\s+)?trait\\s+(\\w+)/g);\n for (const match of traitMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Vue Functions\nfunction extractVueFunctions(content: string): string[] {\n const names = new Set<string>();\n \n // Extract script content from Vue SFC\n const scriptMatch = content.match(/<script[^>]*>([\\s\\S]*?)<\\/script>/);\n if (!scriptMatch) return [];\n \n const scriptContent = scriptMatch[1];\n \n // Composition API: const/function name = ...\n const compositionMatches = scriptContent.matchAll(/(?:const|function)\\s+(\\w+)\\s*=/g);\n for (const match of compositionMatches) {\n names.add(match[1]);\n }\n \n // Options API methods\n const methodMatches = scriptContent.matchAll(/(\\w+)\\s*\\([^)]*\\)\\s*{/g);\n for (const match of methodMatches) {\n names.add(match[1]);\n }\n \n return Array.from(names);\n}\n\n// Vue Components\nfunction extractVueComponents(content: string): string[] {\n const names = new Set<string>();\n \n // Extract component name from filename convention or export\n const scriptMatch = content.match(/<script[^>]*>([\\s\\S]*?)<\\/script>/);\n if (!scriptMatch) return [];\n \n const scriptContent = scriptMatch[1];\n \n // export default { name: 'ComponentName' }\n const nameMatch = scriptContent.match(/name:\\s*['\"](\\w+)['\"]/);\n if (nameMatch) {\n names.add(nameMatch[1]);\n }\n \n // defineComponent or <script setup> components\n const defineComponentMatch = scriptContent.match(/defineComponent\\s*\\(/);\n if (defineComponentMatch) {\n names.add('VueComponent');\n }\n \n return Array.from(names);\n}\n\n","import Parser from 'tree-sitter';\nimport TypeScript from 'tree-sitter-typescript';\nimport JavaScript from 'tree-sitter-javascript';\nimport PHPParser from 'tree-sitter-php';\nimport Python from 'tree-sitter-python';\nimport { extname } from 'path';\nimport type { ASTParseResult, SupportedLanguage } from './types.js';\n\n/**\n * Cache for parser instances to avoid recreating them\n */\nconst parserCache = new Map<SupportedLanguage, Parser>();\n\n/**\n * Tree-sitter language grammar type\n * Using any here due to type incompatibility between parser packages and tree-sitter core\n */\ntype TreeSitterLanguage = any;\n\n/**\n * Language configuration mapping\n */\nconst languageConfig: Record<SupportedLanguage, TreeSitterLanguage> = {\n typescript: TypeScript.typescript,\n javascript: JavaScript,\n php: PHPParser.php, // Note: tree-sitter-php exports both 'php' (mixed HTML/PHP) and 'php_only'\n python: Python,\n};\n\n/**\n * Get or create a cached parser instance for a language\n */\nfunction getParser(language: SupportedLanguage): Parser {\n if (!parserCache.has(language)) {\n const parser = new Parser();\n const grammar = languageConfig[language];\n \n if (!grammar) {\n throw new Error(`No grammar available for language: ${language}`);\n }\n \n parser.setLanguage(grammar);\n parserCache.set(language, parser);\n }\n \n return parserCache.get(language)!;\n}\n\n/**\n * Detect language from file extension\n * Uses path.extname() to handle edge cases like multiple dots in filenames\n */\nexport function detectLanguage(filePath: string): SupportedLanguage | null {\n // extname returns extension with leading dot (e.g., '.ts')\n // Remove the dot and convert to lowercase\n const ext = extname(filePath).slice(1).toLowerCase();\n \n switch (ext) {\n case 'ts':\n case 'tsx':\n return 'typescript';\n case 'js':\n case 'jsx':\n case 'mjs':\n case 'cjs':\n return 'javascript';\n case 'php':\n return 'php';\n case 'py':\n return 'python';\n default:\n return null;\n }\n}\n\n/**\n * Check if a file is supported for AST parsing\n */\nexport function isASTSupported(filePath: string): boolean {\n return detectLanguage(filePath) !== null;\n}\n\n/**\n * Parse source code into an AST using Tree-sitter\n * \n * **Known Limitation:** Tree-sitter may throw \"Invalid argument\" errors on very large files\n * (1000+ lines). This is a limitation of Tree-sitter's internal buffer handling. When this\n * occurs, callers should fall back to line-based chunking (handled automatically by chunker.ts).\n * \n * @param content - Source code to parse\n * @param language - Programming language\n * @returns Parse result with tree or error\n */\nexport function parseAST(content: string, language: SupportedLanguage): ASTParseResult {\n try {\n const parser = getParser(language);\n const tree = parser.parse(content);\n \n // Check for parse errors (hasError is a property, not a method)\n if (tree.rootNode.hasError) {\n return {\n tree,\n error: 'Parse completed with errors',\n };\n }\n \n return { tree };\n } catch (error) {\n return {\n tree: null,\n error: error instanceof Error ? error.message : 'Unknown parse error',\n };\n }\n}\n\n/**\n * Clear parser cache (useful for testing)\n */\nexport function clearParserCache(): void {\n parserCache.clear();\n}\n\n","import type Parser from 'tree-sitter';\n\n/**\n * Decision point node types for cyclomatic complexity calculation.\n * \n * These AST node types represent branch points in code flow.\n */\nconst DECISION_POINTS = [\n // Common across languages (TypeScript/JavaScript/Python/PHP)\n 'if_statement', // if conditions\n 'while_statement', // while loops\n 'for_statement', // for loops\n 'switch_case', // switch/case statements\n 'catch_clause', // try/catch error handling\n 'ternary_expression', // Ternary operator (a ? b : c)\n 'binary_expression', // For && and || logical operators\n \n // TypeScript/JavaScript specific\n 'do_statement', // do...while loops\n 'for_in_statement', // for...in loops\n 'for_of_statement', // for...of loops\n \n // PHP specific\n 'foreach_statement', // PHP foreach loops\n \n // Python specific\n 'elif_clause', // Python elif (adds decision point)\n // Note: 'else_clause' is NOT a decision point (it's the default path)\n 'except_clause', // Python except (try/except)\n 'conditional_expression', // Python ternary (x if cond else y)\n];\n\n/**\n * Calculate cyclomatic complexity of a function\n * \n * Complexity = 1 (base) + number of decision points\n * Decision points: if, while, do...while, for, for...in, for...of, foreach, case, catch, &&, ||, ?:\n * \n * @param node - AST node to analyze (typically a function/method)\n * @returns Cyclomatic complexity score (minimum 1)\n */\nexport function calculateComplexity(node: Parser.SyntaxNode): number {\n let complexity = 1; // Base complexity\n \n function traverse(n: Parser.SyntaxNode) {\n if (DECISION_POINTS.includes(n.type)) {\n // For binary expressions, only count && and ||\n if (n.type === 'binary_expression') {\n const operator = n.childForFieldName('operator');\n if (operator && (operator.text === '&&' || operator.text === '||')) {\n complexity++;\n }\n } else {\n complexity++;\n }\n }\n \n // Traverse children\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) traverse(child);\n }\n }\n \n traverse(node);\n return complexity;\n}\n","import type Parser from 'tree-sitter';\n\n// Node types that increase complexity AND increment nesting for children\nconst NESTING_TYPES = new Set([\n 'if_statement', 'for_statement', 'while_statement', 'switch_statement',\n 'catch_clause', 'except_clause', 'do_statement', 'for_in_statement',\n 'for_of_statement', 'foreach_statement', 'match_statement',\n]);\n\n// Types that add complexity but DON'T nest (hybrid increments)\nconst NON_NESTING_TYPES = new Set([\n 'else_clause', 'elif_clause', 'ternary_expression', 'conditional_expression',\n]);\n\n// Lambda types that add complexity when nested\nconst LAMBDA_TYPES = new Set(['arrow_function', 'function_expression', 'lambda']);\n\n/** Traversal context passed to handlers */\ninterface TraversalContext {\n traverse: (n: Parser.SyntaxNode, level: number, lastOp: string | null) => void;\n}\n\n/**\n * Check if node is a logical operator and return normalized form\n */\nfunction getLogicalOperator(node: Parser.SyntaxNode): string | null {\n if (node.type !== 'binary_expression' && node.type !== 'boolean_operator') {\n return null;\n }\n const operator = node.childForFieldName('operator');\n const opText = operator?.text;\n \n if (opText === '&&' || opText === 'and') return '&&';\n if (opText === '||' || opText === 'or') return '||';\n return null;\n}\n\n/**\n * Determine nesting level for a child node based on SonarSource spec.\n */\nfunction getChildNestingLevel(\n parent: Parser.SyntaxNode,\n child: Parser.SyntaxNode,\n currentLevel: number\n): number {\n const isCondition = parent.childForFieldName('condition') === child;\n const isElseClause = NON_NESTING_TYPES.has(child.type);\n return (!isCondition && !isElseClause) ? currentLevel + 1 : currentLevel;\n}\n\n/**\n * Get complexity increment for nested lambda (only adds if already nested)\n */\nfunction getNestedLambdaIncrement(nodeType: string, nestingLevel: number): number {\n return (LAMBDA_TYPES.has(nodeType) && nestingLevel > 0) ? 1 : 0;\n}\n\n/** Traverse logical operator children, passing the operator type */\nfunction traverseLogicalChildren(\n n: Parser.SyntaxNode,\n level: number,\n op: string,\n ctx: TraversalContext\n): void {\n const operator = n.childForFieldName('operator');\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child && child !== operator) ctx.traverse(child, level, op);\n }\n}\n\n/** Traverse nesting type children with proper nesting level adjustment */\nfunction traverseNestingChildren(\n n: Parser.SyntaxNode,\n level: number,\n ctx: TraversalContext\n): void {\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) ctx.traverse(child, getChildNestingLevel(n, child, level), null);\n }\n}\n\n/** Traverse all children at specified level */\nfunction traverseAllChildren(\n n: Parser.SyntaxNode,\n level: number,\n ctx: TraversalContext\n): void {\n for (let i = 0; i < n.namedChildCount; i++) {\n const child = n.namedChild(i);\n if (child) ctx.traverse(child, level, null);\n }\n}\n\n/**\n * Calculate cognitive complexity of a function\n * \n * Based on SonarSource's Cognitive Complexity specification:\n * - +1 for each break from linear flow (if, for, while, catch, etc.)\n * - +1 for each nesting level when inside a control structure\n * - +1 for each logical operator sequence break (a && b || c)\n * \n * @see https://www.sonarsource.com/docs/CognitiveComplexity.pdf\n * \n * @param node - AST node to analyze (typically a function/method)\n * @returns Cognitive complexity score (minimum 0)\n */\nexport function calculateCognitiveComplexity(node: Parser.SyntaxNode): number {\n let complexity = 0;\n const ctx: TraversalContext = { traverse };\n \n function traverse(n: Parser.SyntaxNode, nestingLevel: number, lastLogicalOp: string | null): void {\n const logicalOp = getLogicalOperator(n);\n \n if (logicalOp) {\n complexity += (lastLogicalOp !== logicalOp) ? 1 : 0;\n traverseLogicalChildren(n, nestingLevel, logicalOp, ctx);\n return;\n }\n \n if (NESTING_TYPES.has(n.type)) {\n complexity += 1 + nestingLevel;\n traverseNestingChildren(n, nestingLevel, ctx);\n return;\n }\n \n if (NON_NESTING_TYPES.has(n.type)) {\n complexity += 1;\n traverseAllChildren(n, nestingLevel + 1, ctx);\n return;\n }\n \n complexity += getNestedLambdaIncrement(n.type, nestingLevel);\n traverseAllChildren(n, nestingLevel, ctx);\n }\n \n traverse(node, 0, null);\n return complexity;\n}\n","import type Parser from 'tree-sitter';\n\n/** Raw Halstead counts from AST */\nexport interface HalsteadCounts {\n n1: number; // distinct operators\n n2: number; // distinct operands\n N1: number; // total operators\n N2: number; // total operands\n operators: Map<string, number>; // operator -> count\n operands: Map<string, number>; // operand -> count\n}\n\n/** Calculated Halstead metrics */\nexport interface HalsteadMetrics {\n vocabulary: number; // n = n1 + n2\n length: number; // N = N1 + N2\n volume: number; // V = N × log₂(n)\n difficulty: number; // D = (n1/2) × (N2/n2)\n effort: number; // E = D × V\n time: number; // T = E / 18 (seconds to understand)\n bugs: number; // B = V / 3000 (estimated delivered bugs)\n}\n\n/** \n * Language-specific operator symbols.\n * These are the actual text values we match against.\n */\nconst OPERATOR_SYMBOLS: Record<string, Set<string>> = {\n typescript: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**',\n // Comparison\n '==', '===', '!=', '!==', '<', '>', '<=', '>=',\n // Logical\n '&&', '||', '!', '??',\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '&&=', '||=', '??=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>', '>>>',\n '&=', '|=', '^=', '<<=', '>>=', '>>>=',\n // Other\n '?', ':', '.', '?.', '++', '--', '...', '=>',\n // Brackets/parens (counted as operators)\n '(', ')', '[', ']', '{', '}',\n ]),\n python: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**', '//',\n // Comparison\n '==', '!=', '<', '>', '<=', '>=',\n // Logical (handled via keywords below)\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '//=',\n '&=', '|=', '^=', '<<=', '>>=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>',\n // Other\n '.', ':', '->', '@',\n '(', ')', '[', ']', '{', '}',\n ]),\n php: new Set([\n // Arithmetic\n '+', '-', '*', '/', '%', '**',\n // Comparison\n '==', '===', '!=', '!==', '<>', '<', '>', '<=', '>=', '<=>',\n // Logical\n '&&', '||', '!', 'and', 'or', 'xor',\n // Assignment\n '=', '+=', '-=', '*=', '/=', '%=', '**=', '.=',\n '&=', '|=', '^=', '<<=', '>>=', '??=',\n // Bitwise\n '&', '|', '^', '~', '<<', '>>',\n // String\n '.',\n // Other\n '?', ':', '::', '->', '=>', '??', '@',\n '(', ')', '[', ']', '{', '}',\n ]),\n};\n\n/** \n * Language-specific operator keywords.\n * These are keywords that act as operators.\n */\nconst OPERATOR_KEYWORDS: Record<string, Set<string>> = {\n typescript: new Set([\n 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default',\n 'return', 'throw', 'try', 'catch', 'finally',\n 'new', 'delete', 'typeof', 'instanceof', 'in', 'of',\n 'await', 'yield', 'break', 'continue',\n 'const', 'let', 'var', 'function', 'class', 'extends', 'implements',\n 'import', 'export', 'from', 'as',\n ]),\n python: new Set([\n 'if', 'elif', 'else', 'for', 'while', 'match', 'case',\n 'return', 'raise', 'try', 'except', 'finally',\n 'and', 'or', 'not', 'is', 'in',\n 'await', 'yield', 'break', 'continue', 'pass',\n 'def', 'class', 'lambda', 'async',\n 'import', 'from', 'as', 'with',\n 'global', 'nonlocal', 'del', 'assert',\n ]),\n php: new Set([\n 'if', 'elseif', 'else', 'for', 'foreach', 'while', 'do', 'switch', 'case', 'default', 'match',\n 'return', 'throw', 'try', 'catch', 'finally',\n 'new', 'clone', 'instanceof',\n 'yield', 'break', 'continue',\n 'function', 'class', 'extends', 'implements', 'trait', 'interface',\n 'use', 'namespace', 'as',\n 'echo', 'print', 'include', 'require', 'include_once', 'require_once',\n 'global', 'static', 'const', 'public', 'private', 'protected', 'readonly',\n ]),\n};\n\n/** \n * AST node types that represent operators (language-agnostic).\n * These are the tree-sitter node types, not the text content.\n */\nconst OPERATOR_NODE_TYPES = new Set([\n // Expression operators\n 'binary_expression',\n 'unary_expression',\n 'update_expression',\n 'assignment_expression',\n 'augmented_assignment_expression',\n 'ternary_expression',\n 'conditional_expression',\n \n // Call/access operators\n 'call_expression',\n 'method_call',\n 'member_expression',\n 'subscript_expression',\n 'attribute',\n \n // Object/array literals ([] and {} are operators)\n 'array',\n 'object',\n 'dictionary',\n 'list',\n]);\n\n/**\n * AST node types that represent operands.\n */\nconst OPERAND_NODE_TYPES = new Set([\n // Identifiers\n 'identifier',\n 'property_identifier',\n 'shorthand_property_identifier',\n 'variable_name',\n 'name',\n \n // Literals\n 'number',\n 'integer',\n 'float',\n 'string',\n 'string_fragment',\n 'template_string',\n 'true',\n 'false',\n 'null',\n 'undefined',\n 'none',\n \n // Special\n 'this',\n 'self',\n 'super',\n]);\n\n/**\n * Get the operator set for a language (with fallback to typescript)\n */\nfunction getOperatorSymbols(language: string): Set<string> {\n return OPERATOR_SYMBOLS[language] || OPERATOR_SYMBOLS.typescript;\n}\n\n/**\n * Get the keyword set for a language (with fallback to typescript)\n */\nfunction getOperatorKeywords(language: string): Set<string> {\n return OPERATOR_KEYWORDS[language] || OPERATOR_KEYWORDS.typescript;\n}\n\n/**\n * Check if a node represents an operator\n */\nfunction isOperator(node: Parser.SyntaxNode, language: string): boolean {\n const nodeType = node.type;\n const nodeText = node.text;\n \n // Check if it's an operator node type\n if (OPERATOR_NODE_TYPES.has(nodeType)) {\n return true;\n }\n \n // Check if it's an operator symbol or keyword\n const symbols = getOperatorSymbols(language);\n const keywords = getOperatorKeywords(language);\n \n return symbols.has(nodeText) || keywords.has(nodeText);\n}\n\n/**\n * Check if a node represents an operand\n */\nfunction isOperand(node: Parser.SyntaxNode): boolean {\n return OPERAND_NODE_TYPES.has(node.type);\n}\n\n/**\n * Get the canonical key for an operator (for counting distinct operators)\n */\nfunction getOperatorKey(node: Parser.SyntaxNode): string {\n // For complex expressions, use the operator type\n if (OPERATOR_NODE_TYPES.has(node.type)) {\n // For binary/unary expressions, extract the actual operator\n const operator = node.childForFieldName('operator');\n if (operator) {\n return operator.text;\n }\n return node.type;\n }\n return node.text;\n}\n\n/**\n * Get the canonical key for an operand (for counting distinct operands)\n */\nfunction getOperandKey(node: Parser.SyntaxNode): string {\n return node.text;\n}\n\n/**\n * Sum all values in a map\n */\nfunction sumValues(map: Map<string, number>): number {\n let sum = 0;\n for (const count of map.values()) {\n sum += count;\n }\n return sum;\n}\n\n/**\n * Count operators and operands in an AST node\n * \n * @param node - AST node to analyze (typically a function/method)\n * @param language - Programming language for language-specific handling\n * @returns HalsteadCounts with raw operator/operand counts\n */\nexport function countHalstead(node: Parser.SyntaxNode, language: string): HalsteadCounts {\n const operators = new Map<string, number>();\n const operands = new Map<string, number>();\n \n function traverse(n: Parser.SyntaxNode): void {\n // Check if this is an operator\n if (isOperator(n, language)) {\n const key = getOperatorKey(n);\n operators.set(key, (operators.get(key) || 0) + 1);\n }\n \n // Check if this is an operand\n if (isOperand(n)) {\n const key = getOperandKey(n);\n operands.set(key, (operands.get(key) || 0) + 1);\n }\n \n // Recurse into children\n for (const child of n.children) {\n traverse(child);\n }\n }\n \n traverse(node);\n \n return {\n n1: operators.size,\n n2: operands.size,\n N1: sumValues(operators),\n N2: sumValues(operands),\n operators,\n operands,\n };\n}\n\n/**\n * Calculate derived Halstead metrics from raw counts\n * \n * Formulas based on Maurice Halstead's \"Elements of Software Science\" (1977):\n * - Vocabulary (n) = n1 + n2\n * - Length (N) = N1 + N2\n * - Volume (V) = N × log₂(n) - size of implementation\n * - Difficulty (D) = (n1/2) × (N2/n2) - error-proneness\n * - Effort (E) = D × V - mental effort required\n * - Time (T) = E / 18 - seconds to understand (Stroud number)\n * - Bugs (B) = V / 3000 - estimated delivered bugs\n * \n * @param counts - Raw Halstead counts from countHalstead()\n * @returns Calculated HalsteadMetrics\n */\nexport function calculateHalsteadMetrics(counts: HalsteadCounts): HalsteadMetrics {\n const { n1, n2, N1, N2 } = counts;\n \n const vocabulary = n1 + n2;\n const length = N1 + N2;\n \n // Avoid log(0) and division by zero\n const volume = vocabulary > 0 ? length * Math.log2(vocabulary) : 0;\n const difficulty = n2 > 0 ? (n1 / 2) * (N2 / n2) : 0;\n const effort = difficulty * volume;\n const time = effort / 18; // Stroud number (18 mental discriminations per second)\n const bugs = volume / 3000;\n \n return {\n vocabulary: Math.round(vocabulary),\n length: Math.round(length),\n volume: Math.round(volume * 100) / 100,\n difficulty: Math.round(difficulty * 100) / 100,\n effort: Math.round(effort),\n time: Math.round(time),\n bugs: Math.round(bugs * 1000) / 1000,\n };\n}\n\n/**\n * Calculate Halstead metrics for an AST node in one call\n * \n * Convenience function that combines countHalstead and calculateHalsteadMetrics.\n * \n * @param node - AST node to analyze\n * @param language - Programming language\n * @returns Calculated HalsteadMetrics\n */\nexport function calculateHalstead(node: Parser.SyntaxNode, language: string): HalsteadMetrics {\n const counts = countHalstead(node, language);\n return calculateHalsteadMetrics(counts);\n}\n","/**\n * Complexity metrics module\n * \n * This module provides various code complexity metrics:\n * - Cyclomatic complexity: Counts decision points (branches) in code\n * - Cognitive complexity: Measures mental effort to understand code (SonarSource spec)\n * - Halstead metrics: Measures complexity based on operators/operands\n */\n\nexport { calculateComplexity } from './cyclomatic.js';\nexport { calculateCognitiveComplexity } from './cognitive.js';\nexport { \n countHalstead, \n calculateHalsteadMetrics, \n calculateHalstead,\n} from './halstead.js';\nexport type { HalsteadCounts, HalsteadMetrics } from './halstead.js';\n","import type Parser from 'tree-sitter';\nimport type { SymbolInfo } from './types.js';\nimport { calculateComplexity } from './complexity/index.js';\n\n/**\n * Type for symbol extractor functions\n */\ntype SymbolExtractor = (\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n) => SymbolInfo | null;\n\n/**\n * Extract function declaration info (function_declaration, function)\n */\nfunction extractFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n returnType: extractReturnType(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract arrow function or function expression info\n */\nfunction extractArrowFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n // Try to find variable name for arrow functions\n const parent = node.parent;\n let name = 'anonymous';\n \n if (parent?.type === 'variable_declarator') {\n const nameNode = parent.childForFieldName('name');\n name = nameNode?.text || 'anonymous';\n }\n \n return {\n name,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract method definition info\n */\nfunction extractMethodInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'method',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n returnType: extractReturnType(node, content),\n complexity: calculateComplexity(node),\n };\n }\n \n/**\n * Extract class declaration info\n */\nfunction extractClassInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'class',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `class ${nameNode.text}`,\n };\n }\n \n/**\n * Extract interface declaration info (TypeScript)\n */\nfunction extractInterfaceInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'interface',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `interface ${nameNode.text}`,\n };\n }\n\n/**\n * Extract Python function info (def and async def)\n */\nfunction extractPythonFunctionInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: parentClass ? 'method' : 'function',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n parentClass,\n signature: extractSignature(node, content),\n parameters: extractParameters(node, content),\n complexity: calculateComplexity(node),\n };\n }\n\n/**\n * Extract Python class info\n */\nfunction extractPythonClassInfo(\n node: Parser.SyntaxNode,\n _content: string,\n _parentClass?: string\n): SymbolInfo | null {\n const nameNode = node.childForFieldName('name');\n if (!nameNode) return null;\n \n return {\n name: nameNode.text,\n type: 'class',\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n signature: `class ${nameNode.text}`,\n };\n }\n \n/**\n * Map of AST node types to their specialized extractors\n * \n * Note: There is intentional overlap in node type names across languages:\n * - 'function_definition': Used by both PHP and Python\n * - 'class_declaration': Used by TypeScript/JavaScript\n * - 'class_definition': Used by Python\n * \n * This is handled correctly because each file is parsed with its specific language parser.\n */\nconst symbolExtractors: Record<string, SymbolExtractor> = {\n // TypeScript/JavaScript\n 'function_declaration': extractFunctionInfo,\n 'function': extractFunctionInfo,\n 'arrow_function': extractArrowFunctionInfo,\n 'function_expression': extractArrowFunctionInfo,\n 'method_definition': extractMethodInfo,\n 'class_declaration': extractClassInfo,\n 'interface_declaration': extractInterfaceInfo,\n \n // PHP\n 'function_definition': extractFunctionInfo, // PHP functions (Python handled via language check in extractSymbolInfo)\n 'method_declaration': extractMethodInfo, // PHP methods\n \n // Python\n 'async_function_definition': extractPythonFunctionInfo, // Python async functions\n 'class_definition': extractPythonClassInfo, // Python classes\n // Note: Python regular functions use 'function_definition' (same as PHP)\n // They are dispatched to extractPythonFunctionInfo via language check in extractSymbolInfo()\n};\n\n/**\n * Extract symbol information from an AST node using specialized extractors\n * \n * @param node - AST node to extract info from\n * @param content - Source code content\n * @param parentClass - Parent class name if this is a method\n * @param language - Programming language (for disambiguating shared node types)\n * @returns Symbol information or null\n */\nexport function extractSymbolInfo(\n node: Parser.SyntaxNode,\n content: string,\n parentClass?: string,\n language?: string\n): SymbolInfo | null {\n // Handle ambiguous node types that are shared between languages\n // PHP and Python both use 'function_definition', but need different extractors\n if (node.type === 'function_definition' && language === 'python') {\n return extractPythonFunctionInfo(node, content, parentClass);\n }\n \n const extractor = symbolExtractors[node.type];\n return extractor ? extractor(node, content, parentClass) : null;\n}\n\n/**\n * Extract function/method signature\n */\nfunction extractSignature(node: Parser.SyntaxNode, content: string): string {\n // Get the first line of the function (up to opening brace or arrow)\n const startLine = node.startPosition.row;\n const lines = content.split('\\n');\n let signature = lines[startLine] || '';\n \n // If signature spans multiple lines, try to get up to the opening brace\n let currentLine = startLine;\n while (currentLine < node.endPosition.row && !signature.includes('{') && !signature.includes('=>')) {\n currentLine++;\n signature += ' ' + (lines[currentLine] || '');\n }\n \n // Clean up signature\n signature = signature.split('{')[0].split('=>')[0].trim();\n \n // Limit length\n if (signature.length > 200) {\n signature = signature.substring(0, 197) + '...';\n }\n \n return signature;\n}\n\n/**\n * Extract parameter list from function node\n * \n * Note: The `_content` parameter is unused in this function, but is kept for API consistency\n * with other extract functions (e.g., extractSignature).\n */\nfunction extractParameters(node: Parser.SyntaxNode, _content: string): string[] {\n const parameters: string[] = [];\n \n // Find parameters node\n const paramsNode = node.childForFieldName('parameters');\n if (!paramsNode) return parameters;\n \n // Traverse parameter nodes\n for (let i = 0; i < paramsNode.namedChildCount; i++) {\n const param = paramsNode.namedChild(i);\n if (param) {\n parameters.push(param.text);\n }\n }\n \n return parameters;\n}\n\n/**\n * Extract return type from function node (TypeScript)\n * \n * Note: The `_content` parameter is unused in this function, but is kept for API consistency\n * with other extract functions (e.g., extractSignature).\n */\nfunction extractReturnType(node: Parser.SyntaxNode, _content: string): string | undefined {\n const returnTypeNode = node.childForFieldName('return_type');\n if (!returnTypeNode) return undefined;\n \n return returnTypeNode.text;\n}\n\n/**\n * Extract import statements from a file\n */\nexport function extractImports(rootNode: Parser.SyntaxNode): string[] {\n const imports: string[] = [];\n \n function traverse(node: Parser.SyntaxNode) {\n // Handle import statements (shared node type between languages)\n if (node.type === 'import_statement') {\n // TypeScript/JavaScript: Extract just the module path from 'source' field\n const sourceNode = node.childForFieldName('source');\n if (sourceNode) {\n // TS/JS import with source field\n const importPath = sourceNode.text.replace(/['\"]/g, '');\n imports.push(importPath);\n } else {\n // Python import without source field (e.g., \"import os\")\n const importText = node.text.split('\\n')[0];\n imports.push(importText);\n }\n }\n // Python-specific: from...import statements\n else if (node.type === 'import_from_statement') {\n // Python: Get the entire import line (first line only)\n const importText = node.text.split('\\n')[0];\n imports.push(importText);\n }\n \n // Only traverse top-level nodes for imports\n if (node === rootNode) {\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) traverse(child);\n }\n }\n }\n \n traverse(rootNode);\n return imports;\n}\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * TypeScript/JavaScript AST traverser\n * \n * Handles TypeScript and JavaScript AST node types and traversal patterns.\n * Both languages share the same AST structure (via tree-sitter-typescript).\n */\nexport class TypeScriptTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_declaration',\n 'function',\n 'interface_declaration',\n 'method_definition',\n 'lexical_declaration', // For const/let with arrow functions\n 'variable_declaration', // For var with functions\n ];\n \n containerTypes = [\n 'class_declaration', // We extract methods, not the class itself\n ];\n \n declarationTypes = [\n 'lexical_declaration', // const/let\n 'variable_declaration', // var\n ];\n \n functionTypes = [\n 'arrow_function',\n 'function_expression',\n 'function',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(node: Parser.SyntaxNode): boolean {\n return this.declarationTypes.includes(node.type);\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_declaration') {\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'program' || \n node.type === 'export_statement' ||\n node.type === 'class_body';\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_declaration') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n /**\n * Check if a declaration node contains a function (arrow, function expression, etc.)\n */\n findFunctionInDeclaration(node: Parser.SyntaxNode): DeclarationFunctionInfo {\n const search = (n: Parser.SyntaxNode, depth: number): Parser.SyntaxNode | null => {\n if (depth > 3) return null; // Don't search too deep\n \n if (this.functionTypes.includes(n.type)) {\n return n;\n }\n \n for (let i = 0; i < n.childCount; i++) {\n const child = n.child(i);\n if (child) {\n const result = search(child, depth + 1);\n if (result) return result;\n }\n }\n \n return null;\n };\n \n const functionNode = search(node, 0);\n return {\n hasFunction: functionNode !== null,\n functionNode,\n };\n }\n}\n\n/**\n * JavaScript uses the same traverser as TypeScript\n */\nexport class JavaScriptTraverser extends TypeScriptTraverser {}\n\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * PHP AST traverser\n * \n * Handles PHP AST node types and traversal patterns.\n * PHP uses tree-sitter-php grammar.\n */\nexport class PHPTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_definition', // function foo() {}\n 'method_declaration', // public function bar() {}\n ];\n \n containerTypes = [\n 'class_declaration', // We extract methods, not the class itself\n 'trait_declaration', // PHP traits\n 'interface_declaration', // PHP interfaces (for interface methods)\n ];\n \n declarationTypes = [\n // PHP doesn't have arrow functions or const/let like JS\n // Functions are always defined with 'function' keyword\n ];\n \n functionTypes = [\n 'function_definition',\n 'method_declaration',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean {\n // PHP doesn't have variable declarations with functions like JS/TS\n // Functions are always defined with 'function' keyword\n return false;\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_declaration' || \n node.type === 'trait_declaration' ||\n node.type === 'interface_declaration') {\n // In PHP, the body is called 'declaration_list'\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'program' || // Top-level PHP file\n node.type === 'php' || // PHP block\n node.type === 'declaration_list'; // Body of class/trait/interface\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_declaration' || \n current.type === 'trait_declaration') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo {\n // PHP doesn't have this pattern\n return {\n hasFunction: false,\n functionNode: null,\n };\n }\n}\n\n","import type Parser from 'tree-sitter';\nimport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * Python AST traverser\n * \n * Handles Python AST node types and traversal patterns.\n * Python has a simpler structure than TypeScript/JavaScript:\n * - Functions are defined with 'def' or 'async def'\n * - No variable declarations with functions (unlike JS const x = () => {})\n * - Classes contain methods (which are just functions)\n */\nexport class PythonTraverser implements LanguageTraverser {\n targetNodeTypes = [\n 'function_definition',\n 'async_function_definition',\n ];\n \n containerTypes = [\n 'class_definition', // We extract methods, not the class itself\n ];\n \n declarationTypes = [\n // Python doesn't have const/let/var declarations like JS/TS\n // Functions are always defined with 'def' or 'async def'\n ];\n \n functionTypes = [\n 'function_definition',\n 'async_function_definition',\n ];\n \n shouldExtractChildren(node: Parser.SyntaxNode): boolean {\n return this.containerTypes.includes(node.type);\n }\n \n isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean {\n // Python doesn't have variable declarations with functions like JS/TS\n // Functions are always defined with 'def' or 'async def'\n return false;\n }\n \n getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null {\n if (node.type === 'class_definition') {\n // In Python, the class body is called 'block'\n return node.childForFieldName('body');\n }\n return null;\n }\n \n shouldTraverseChildren(node: Parser.SyntaxNode): boolean {\n return node.type === 'module' || // Top-level Python file\n node.type === 'block'; // Body of class/function\n }\n \n findParentContainerName(node: Parser.SyntaxNode): string | undefined {\n let current = node.parent;\n while (current) {\n if (current.type === 'class_definition') {\n const nameNode = current.childForFieldName('name');\n return nameNode?.text;\n }\n current = current.parent;\n }\n return undefined;\n }\n \n /**\n * Python doesn't have this pattern (const x = () => {})\n * Functions are always defined with 'def' or 'async def'\n */\n findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo {\n return {\n hasFunction: false,\n functionNode: null,\n };\n }\n}\n\n","import type { SupportedLanguage } from '../types.js';\nimport type { LanguageTraverser } from './types.js';\nimport { TypeScriptTraverser, JavaScriptTraverser } from './typescript.js';\nimport { PHPTraverser } from './php.js';\nimport { PythonTraverser } from './python.js';\n\nexport type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';\n\n/**\n * Registry of language traversers\n * \n * Maps each supported language to its traverser implementation.\n * When adding a new language:\n * 1. Create a new traverser class implementing LanguageTraverser\n * 2. Add it to this registry\n * 3. Update SupportedLanguage type in ../types.ts\n */\nconst traverserRegistry: Record<SupportedLanguage, LanguageTraverser> = {\n typescript: new TypeScriptTraverser(),\n javascript: new JavaScriptTraverser(),\n php: new PHPTraverser(),\n python: new PythonTraverser(),\n};\n\n/**\n * Get the traverser for a specific language\n * \n * @param language - Programming language\n * @returns Language-specific traverser\n * @throws Error if language is not supported\n */\nexport function getTraverser(language: SupportedLanguage): LanguageTraverser {\n const traverser = traverserRegistry[language];\n \n if (!traverser) {\n throw new Error(`No traverser available for language: ${language}`);\n }\n \n return traverser;\n}\n\n/**\n * Check if a language has a traverser implementation\n * \n * @param language - Programming language\n * @returns True if traverser exists\n */\nexport function hasTraverser(language: SupportedLanguage): boolean {\n return language in traverserRegistry;\n}\n\n","import type Parser from 'tree-sitter';\nimport type { ASTChunk } from './types.js';\nimport { parseAST, detectLanguage, isASTSupported } from './parser.js';\nimport { extractSymbolInfo, extractImports } from './symbols.js';\nimport { calculateCognitiveComplexity, calculateHalstead } from './complexity/index.js';\nimport { getTraverser } from './traversers/index.js';\n\nexport interface ASTChunkOptions {\n maxChunkSize?: number; // Reserved for future use (smart splitting of large functions)\n minChunkSize?: number;\n}\n\n/**\n * Chunk a file using AST-based semantic boundaries\n * \n * Uses Tree-sitter to parse code into an AST and extract semantic chunks\n * (functions, classes, methods) that respect code structure.\n * \n * **Known Limitations:**\n * - Tree-sitter may fail with \"Invalid argument\" error on very large files (1000+ lines)\n * - When this occurs, Lien automatically falls back to line-based chunking\n * - Configure fallback behavior via `chunking.astFallback` ('line-based' or 'error')\n * \n * @param filepath - Path to the file\n * @param content - File content\n * @param options - Chunking options\n * @returns Array of AST-aware chunks\n * @throws Error if AST parsing fails and astFallback is 'error'\n */\nexport function chunkByAST(\n filepath: string,\n content: string,\n options: ASTChunkOptions = {}\n): ASTChunk[] {\n const { minChunkSize = 5 } = options;\n \n // Check if AST is supported for this file\n const language = detectLanguage(filepath);\n if (!language) {\n throw new Error(`Unsupported language for file: ${filepath}`);\n }\n \n // Parse the file\n const parseResult = parseAST(content, language);\n \n // If parsing failed, throw error (caller should fallback to line-based)\n if (!parseResult.tree) {\n throw new Error(`Failed to parse ${filepath}: ${parseResult.error}`);\n }\n \n const chunks: ASTChunk[] = [];\n const lines = content.split('\\n');\n const rootNode = parseResult.tree.rootNode;\n \n // Get language-specific traverser\n const traverser = getTraverser(language);\n \n // Extract file-level imports once\n const fileImports = extractImports(rootNode);\n \n // Find all top-level function and class declarations\n const topLevelNodes = findTopLevelNodes(rootNode, traverser);\n \n for (const node of topLevelNodes) {\n // For variable declarations, try to find the function inside\n let actualNode = node;\n if (traverser.isDeclarationWithFunction(node)) {\n const declInfo = traverser.findFunctionInDeclaration(node);\n if (declInfo.functionNode) {\n actualNode = declInfo.functionNode;\n }\n }\n \n // For methods, find the parent container name (e.g., class name)\n const parentClassName = traverser.findParentContainerName(actualNode);\n \n const symbolInfo = extractSymbolInfo(actualNode, content, parentClassName, language);\n \n // Extract the code for this node (use original node for full declaration)\n const nodeContent = getNodeContent(node, lines);\n \n // Create a chunk for this semantic unit\n // Note: Large functions are kept as single chunks (may exceed maxChunkSize)\n // This preserves semantic boundaries - better than splitting mid-function\n chunks.push(createChunk(filepath, node, nodeContent, symbolInfo, fileImports, language));\n }\n \n // Handle remaining code (imports, exports, top-level statements)\n const coveredRanges = topLevelNodes.map(n => ({\n start: n.startPosition.row,\n end: n.endPosition.row,\n }));\n \n const uncoveredChunks = extractUncoveredCode(\n lines,\n coveredRanges,\n filepath,\n minChunkSize,\n fileImports,\n language\n );\n \n chunks.push(...uncoveredChunks);\n \n // Sort chunks by line number\n chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n \n return chunks;\n}\n\n/** Check if node is a function-containing declaration at top level */\nfunction isFunctionDeclaration(\n node: Parser.SyntaxNode,\n depth: number,\n traverser: ReturnType<typeof getTraverser>\n): boolean {\n if (depth !== 0 || !traverser.isDeclarationWithFunction(node)) return false;\n return traverser.findFunctionInDeclaration(node).hasFunction;\n}\n\n/** Check if node is a target type at valid depth */\nfunction isTargetNode(\n node: Parser.SyntaxNode,\n depth: number,\n traverser: ReturnType<typeof getTraverser>\n): boolean {\n return depth <= 1 && traverser.targetNodeTypes.includes(node.type);\n}\n\n/**\n * Find all top-level nodes that should become chunks\n * \n * Uses a language-specific traverser to handle different AST structures.\n * This function is now language-agnostic - all language-specific logic\n * is delegated to the traverser.\n * \n * @param rootNode - Root AST node\n * @param traverser - Language-specific traverser\n * @returns Array of nodes to extract as chunks\n */\nfunction findTopLevelNodes(\n rootNode: Parser.SyntaxNode,\n traverser: ReturnType<typeof getTraverser>\n): Parser.SyntaxNode[] {\n const nodes: Parser.SyntaxNode[] = [];\n \n function traverse(node: Parser.SyntaxNode, depth: number): void {\n // Capture function declarations and target nodes\n if (isFunctionDeclaration(node, depth, traverser) || isTargetNode(node, depth, traverser)) {\n nodes.push(node);\n return;\n }\n \n // Handle containers - traverse body at increased depth\n if (traverser.shouldExtractChildren(node)) {\n const body = traverser.getContainerBody(node);\n if (body) traverse(body, depth + 1);\n return;\n }\n \n // Traverse children of traversable nodes\n if (!traverser.shouldTraverseChildren(node)) return;\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i);\n if (child) traverse(child, depth);\n }\n }\n \n traverse(rootNode, 0);\n return nodes;\n}\n\n/**\n * Extract content for a specific AST node\n */\nfunction getNodeContent(node: Parser.SyntaxNode, lines: string[]): string {\n const startLine = node.startPosition.row;\n const endLine = node.endPosition.row;\n \n return lines.slice(startLine, endLine + 1).join('\\n');\n}\n\n/** Maps symbol types to legacy symbol array keys */\nconst SYMBOL_TYPE_TO_ARRAY: Record<string, 'functions' | 'classes' | 'interfaces'> = {\n function: 'functions',\n method: 'functions',\n class: 'classes',\n interface: 'interfaces',\n};\n\n/** Symbol types that have meaningful complexity metrics */\nconst COMPLEXITY_SYMBOL_TYPES = new Set(['function', 'method']);\n\n/**\n * Build legacy symbols object for backward compatibility\n */\nfunction buildLegacySymbols(symbolInfo: ReturnType<typeof extractSymbolInfo>): {\n functions: string[];\n classes: string[];\n interfaces: string[];\n} {\n const symbols = { functions: [] as string[], classes: [] as string[], interfaces: [] as string[] };\n \n if (symbolInfo?.name && symbolInfo.type) {\n const arrayKey = SYMBOL_TYPE_TO_ARRAY[symbolInfo.type];\n if (arrayKey) symbols[arrayKey].push(symbolInfo.name);\n }\n \n return symbols;\n}\n\n/**\n * Determine chunk type from symbol info\n */\nfunction getChunkType(symbolInfo: ReturnType<typeof extractSymbolInfo>): 'block' | 'class' | 'function' {\n if (!symbolInfo) return 'block';\n return symbolInfo.type === 'class' ? 'class' : 'function';\n}\n\n/**\n * Create a chunk from an AST node\n */\nfunction createChunk(\n filepath: string,\n node: Parser.SyntaxNode,\n content: string,\n symbolInfo: ReturnType<typeof extractSymbolInfo>,\n imports: string[],\n language: string\n): ASTChunk {\n const symbols = buildLegacySymbols(symbolInfo);\n const shouldCalcComplexity = symbolInfo?.type && COMPLEXITY_SYMBOL_TYPES.has(symbolInfo.type);\n \n // Calculate complexity metrics only for functions and methods\n const cognitiveComplexity = shouldCalcComplexity\n ? calculateCognitiveComplexity(node)\n : undefined;\n \n // Calculate Halstead metrics only for functions and methods\n const halstead = shouldCalcComplexity\n ? calculateHalstead(node, language)\n : undefined;\n \n return {\n content,\n metadata: {\n file: filepath,\n startLine: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n type: getChunkType(symbolInfo),\n language,\n symbols,\n symbolName: symbolInfo?.name,\n symbolType: symbolInfo?.type,\n parentClass: symbolInfo?.parentClass,\n complexity: symbolInfo?.complexity,\n cognitiveComplexity,\n parameters: symbolInfo?.parameters,\n signature: symbolInfo?.signature,\n imports,\n // Halstead metrics\n halsteadVolume: halstead?.volume,\n halsteadDifficulty: halstead?.difficulty,\n halsteadEffort: halstead?.effort,\n halsteadBugs: halstead?.bugs,\n },\n };\n}\n\n/**\n * Represents a range of lines in a file\n */\ninterface LineRange {\n start: number;\n end: number;\n}\n\n/**\n * Find gaps between covered ranges (uncovered code)\n */\nfunction findUncoveredRanges(\n coveredRanges: LineRange[],\n totalLines: number\n): LineRange[] {\n const uncoveredRanges: LineRange[] = [];\n let currentStart = 0;\n \n // Sort covered ranges\n const sortedRanges = [...coveredRanges].sort((a, b) => a.start - b.start);\n \n for (const range of sortedRanges) {\n if (currentStart < range.start) {\n // There's a gap before this range\n uncoveredRanges.push({\n start: currentStart,\n end: range.start - 1,\n });\n }\n currentStart = range.end + 1;\n }\n \n // Handle remaining code after last covered range\n if (currentStart < totalLines) {\n uncoveredRanges.push({\n start: currentStart,\n end: totalLines - 1,\n });\n }\n \n return uncoveredRanges;\n}\n\n/**\n * Create a chunk from a line range\n */\nfunction createChunkFromRange(\n range: LineRange,\n lines: string[],\n filepath: string,\n language: string,\n imports: string[]\n): ASTChunk {\n const uncoveredLines = lines.slice(range.start, range.end + 1);\n const content = uncoveredLines.join('\\n').trim();\n \n return {\n content,\n metadata: {\n file: filepath,\n startLine: range.start + 1,\n endLine: range.end + 1,\n type: 'block',\n language,\n // Empty symbols for uncovered code (imports, exports, etc.)\n symbols: { functions: [], classes: [], interfaces: [] },\n imports,\n },\n };\n}\n\n/**\n * Validate that a chunk meets the minimum size requirements\n */\nfunction isValidChunk(chunk: ASTChunk, minChunkSize: number): boolean {\n const lineCount = chunk.metadata.endLine - chunk.metadata.startLine + 1;\n return chunk.content.length > 0 && lineCount >= minChunkSize;\n}\n\n/**\n * Extract code that wasn't covered by function/class chunks\n * (imports, exports, top-level statements)\n */\nfunction extractUncoveredCode(\n lines: string[],\n coveredRanges: Array<{ start: number; end: number }>,\n filepath: string,\n minChunkSize: number,\n imports: string[],\n language: string\n): ASTChunk[] {\n const uncoveredRanges = findUncoveredRanges(coveredRanges, lines.length);\n \n return uncoveredRanges\n .map(range => createChunkFromRange(range, lines, filepath, language, imports))\n .filter(chunk => isValidChunk(chunk, minChunkSize));\n}\n\n/**\n * Check if AST chunking should be used for a file\n */\nexport function shouldUseAST(filepath: string): boolean {\n return isASTSupported(filepath);\n}\n\n","import type { CodeChunk } from './types.js';\n\n/**\n * Liquid-specific chunking for Shopify themes\n * \n * Uses regex to identify special Liquid blocks (schema, style, javascript)\n * and keeps them as single semantic units\n */\n\ninterface LiquidBlock {\n type: 'schema' | 'style' | 'javascript' | 'template';\n startLine: number;\n endLine: number;\n content: string;\n}\n\n/**\n * Extract schema name from JSON content\n * \n * Extracts the \"name\" field from Shopify schema JSON.\n * Uses JSON.parse to properly handle escaped quotes and other JSON edge cases.\n * \n * Example:\n * {% schema %}\n * {\n * \"name\": \"My \\\"Special\\\" Section\",\n * \"settings\": []\n * }\n * {% endschema %}\n * \n * Returns: 'My \"Special\" Section' (with literal quotes, unescaped)\n */\nfunction extractSchemaName(schemaContent: string): string | undefined {\n try {\n // Remove Liquid tags to isolate JSON content\n // Replace {% schema %} and {% endschema %} (with optional whitespace control)\n let jsonContent = schemaContent\n .replace(/\\{%-?\\s*schema\\s*-?%\\}/g, '')\n .replace(/\\{%-?\\s*endschema\\s*-?%\\}/g, '')\n .trim();\n \n // Parse the JSON\n const schema = JSON.parse(jsonContent);\n // Ensure name is a string before returning\n return typeof schema.name === 'string' ? schema.name : undefined;\n } catch (error) {\n // Invalid JSON - return undefined\n // This is acceptable: schema blocks with invalid JSON won't have names extracted\n }\n return undefined;\n}\n\n/**\n * Remove Liquid comment blocks from content to avoid extracting tags from comments\n * \n * Example:\n * {% comment %}Don't use {% render 'old-snippet' %}{% endcomment %}\n * → (removed)\n */\nfunction removeComments(content: string): string {\n // Remove {% comment %}...{% endcomment %} blocks (with optional whitespace control)\n return content.replace(/\\{%-?\\s*comment\\s*-?%\\}[\\s\\S]*?\\{%-?\\s*endcomment\\s*-?%\\}/g, '');\n}\n\n/**\n * Extract dependencies from {% render %}, {% include %}, and {% section %} tags\n * \n * Examples:\n * - {% render 'product-card' %} → 'product-card'\n * - {% render \"cart-item\", product: product %} → 'cart-item'\n * - {% include 'snippets/header' %} → 'snippets/header'\n * - {% section 'announcement-bar' %} → 'announcement-bar'\n * \n * Limitations:\n * - Does not handle escaped quotes in snippet names (e.g., {% render 'name\\'s' %})\n * - This is acceptable because Shopify snippet names map to filenames, and\n * filesystem restrictions prevent quotes in filenames (snippets/name's.liquid is invalid)\n * - In practice, Shopify snippet names use only alphanumeric, dash, and underscore\n * \n * Note: Expects content with comments already removed for performance\n * \n * @param contentWithoutComments - Content with Liquid comments already removed\n */\nfunction extractRenderTags(contentWithoutComments: string): string[] {\n const dependencies = new Set<string>();\n \n // Match {% render 'snippet-name' %} or {% render \"snippet-name\" %}\n // Note: Does not handle escaped quotes - see function docs for rationale\n const renderPattern = /\\{%-?\\s*render\\s+['\"]([^'\"]+)['\"]/g;\n let match;\n \n while ((match = renderPattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n // Match {% include 'snippet-name' %} or {% include \"snippet-name\" %}\n const includePattern = /\\{%-?\\s*include\\s+['\"]([^'\"]+)['\"]/g;\n \n while ((match = includePattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n // Match {% section 'section-name' %} or {% section \"section-name\" %}\n const sectionPattern = /\\{%-?\\s*section\\s+['\"]([^'\"]+)['\"]/g;\n \n while ((match = sectionPattern.exec(contentWithoutComments)) !== null) {\n dependencies.add(match[1]);\n }\n \n return Array.from(dependencies);\n}\n\n/**\n * Find all special Liquid blocks in the template\n * \n * Limitation: Does not support nested blocks of the same type.\n * - Matches first start tag with first end tag\n * - This is acceptable because Shopify Liquid does not allow nested blocks\n * - Example invalid: {% schema %}...{% schema %}...{% endschema %} (Shopify rejects this)\n * - If malformed input contains nested blocks, only outermost block is extracted\n */\nfunction findLiquidBlocks(content: string): LiquidBlock[] {\n const lines = content.split('\\n');\n const blocks: LiquidBlock[] = [];\n \n // Regex patterns for Liquid blocks\n // Note: Matches first start → first end (no nesting support, which is correct for Shopify)\n const blockPatterns = [\n { type: 'schema' as const, start: /\\{%-?\\s*schema\\s*-?%\\}/, end: /\\{%-?\\s*endschema\\s*-?%\\}/ },\n { type: 'style' as const, start: /\\{%-?\\s*style\\s*-?%\\}/, end: /\\{%-?\\s*endstyle\\s*-?%\\}/ },\n { type: 'javascript' as const, start: /\\{%-?\\s*javascript\\s*-?%\\}/, end: /\\{%-?\\s*endjavascript\\s*-?%\\}/ },\n ];\n \n for (const pattern of blockPatterns) {\n let searchStart = 0;\n \n while (searchStart < lines.length) {\n // Find start tag\n const startIdx = lines.findIndex((line, idx) => \n idx >= searchStart && pattern.start.test(line)\n );\n \n if (startIdx === -1) break;\n \n // Find end tag (allow same line for single-line blocks)\n const endIdx = lines.findIndex((line, idx) => \n idx >= startIdx && pattern.end.test(line)\n );\n \n if (endIdx === -1) {\n // No end tag found, treat rest as template\n break;\n }\n \n // Extract block content\n const blockContent = lines.slice(startIdx, endIdx + 1).join('\\n');\n \n blocks.push({\n type: pattern.type,\n startLine: startIdx,\n endLine: endIdx,\n content: blockContent,\n });\n \n searchStart = endIdx + 1;\n }\n }\n \n return blocks.sort((a, b) => a.startLine - b.startLine);\n}\n\n/**\n * Chunk a Liquid template file\n * \n * Special handling for:\n * - {% schema %} blocks (kept together, extract section name)\n * - {% style %} blocks (kept together) \n * - {% javascript %} blocks (kept together)\n * - {% render %}, {% include %}, and {% section %} tags (tracked as imports)\n * - Regular template content (chunked by lines)\n */\nexport function chunkLiquidFile(\n filepath: string,\n content: string,\n chunkSize: number = 75,\n chunkOverlap: number = 10\n): CodeChunk[] {\n const lines = content.split('\\n');\n const blocks = findLiquidBlocks(content);\n const chunks: CodeChunk[] = [];\n \n // Remove comments once for performance (avoids repeated regex operations)\n const contentWithoutComments = removeComments(content);\n const linesWithoutComments = contentWithoutComments.split('\\n');\n \n // Track which lines are covered by special blocks\n const coveredLines = new Set<number>();\n \n // Create chunks for special blocks\n for (const block of blocks) {\n // Mark lines as covered\n for (let i = block.startLine; i <= block.endLine; i++) {\n coveredLines.add(i);\n }\n \n // Extract metadata\n let symbolName: string | undefined;\n if (block.type === 'schema') {\n symbolName = extractSchemaName(block.content);\n }\n \n // Extract render/include tags from cleaned content (comments already removed)\n const blockContentWithoutComments = linesWithoutComments\n .slice(block.startLine, block.endLine + 1)\n .join('\\n');\n const imports = extractRenderTags(blockContentWithoutComments);\n \n const blockLineCount = block.endLine - block.startLine + 1;\n const maxBlockSize = chunkSize * 3; // Allow blocks up to 3x chunk size before splitting\n \n // If block is reasonably sized, keep it as one chunk\n if (blockLineCount <= maxBlockSize) {\n chunks.push({\n content: block.content,\n metadata: {\n file: filepath,\n startLine: block.startLine + 1, // 1-indexed\n endLine: block.endLine + 1,\n language: 'liquid',\n type: 'block',\n symbolName,\n symbolType: block.type,\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n } else {\n // Block is too large - split it into multiple chunks with overlap\n const blockLines = block.content.split('\\n');\n \n for (let offset = 0; offset < blockLines.length; offset += chunkSize - chunkOverlap) {\n const endOffset = Math.min(offset + chunkSize, blockLines.length);\n const chunkContent = blockLines.slice(offset, endOffset).join('\\n');\n \n if (chunkContent.trim().length > 0) {\n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: block.startLine + offset + 1, // 1-indexed\n endLine: block.startLine + endOffset, // 1-indexed (endOffset already accounts for exclusivity)\n language: 'liquid',\n type: 'block',\n symbolName, // Preserve symbol name for all split chunks\n symbolType: block.type,\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n if (endOffset >= blockLines.length) break;\n }\n }\n }\n \n // Chunk uncovered template content\n let currentChunk: string[] = [];\n let chunkStartLine = 0;\n \n for (let i = 0; i < lines.length; i++) {\n // Skip lines covered by special blocks\n if (coveredLines.has(i)) {\n // Flush current chunk if any\n if (currentChunk.length > 0) {\n const chunkContent = currentChunk.join('\\n');\n \n // Only push non-empty chunks\n if (chunkContent.trim().length > 0) {\n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, i).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: i,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n currentChunk = [];\n }\n continue;\n }\n \n // Start new chunk if needed\n if (currentChunk.length === 0) {\n chunkStartLine = i;\n }\n \n currentChunk.push(lines[i]);\n \n // Flush if chunk is full\n if (currentChunk.length >= chunkSize) {\n const chunkContent = currentChunk.join('\\n');\n \n // Only push non-empty chunks\n if (chunkContent.trim().length > 0) {\n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, i + 1).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: i + 1,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n // Add overlap for next chunk\n currentChunk = currentChunk.slice(-chunkOverlap);\n chunkStartLine = Math.max(0, i + 1 - chunkOverlap);\n }\n }\n \n // Flush remaining chunk\n if (currentChunk.length > 0) {\n const chunkContent = currentChunk.join('\\n');\n \n // Skip empty or whitespace-only chunks\n if (chunkContent.trim().length === 0) {\n return chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n }\n \n // Extract from cleaned content (comments already removed)\n const cleanedChunk = linesWithoutComments.slice(chunkStartLine, lines.length).join('\\n');\n const imports = extractRenderTags(cleanedChunk);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: chunkStartLine + 1,\n endLine: lines.length,\n language: 'liquid',\n type: 'template',\n imports: imports.length > 0 ? imports : undefined,\n },\n });\n }\n \n // Sort by line number\n return chunks.sort((a, b) => a.metadata.startLine - b.metadata.startLine);\n}\n\n","import type { CodeChunk } from './types.js';\n\n/**\n * Shopify JSON template chunking\n * \n * JSON template files define which sections appear on a template page.\n * We extract section references to track dependencies.\n * \n * Example structure:\n * {\n * \"sections\": {\n * \"main\": { \"type\": \"main-product\", \"settings\": {...} },\n * \"recommendations\": { \"type\": \"product-recommendations\", \"settings\": {...} }\n * },\n * \"order\": [\"main\", \"recommendations\"]\n * }\n */\n\n/**\n * Extract section types from a Shopify JSON template\n * \n * These are the actual section file names (e.g., \"main-product\" → sections/main-product.liquid)\n */\nfunction extractSectionReferences(jsonContent: string): string[] {\n try {\n const template = JSON.parse(jsonContent);\n const sectionTypes = new Set<string>();\n \n // Extract from sections object\n if (template.sections && typeof template.sections === 'object') {\n for (const section of Object.values(template.sections)) {\n if (\n typeof section === 'object' && \n section !== null && \n 'type' in section && \n typeof section.type === 'string'\n ) {\n sectionTypes.add(section.type);\n }\n }\n }\n \n return Array.from(sectionTypes);\n } catch (error) {\n // Invalid JSON - return empty array\n console.warn(`[Lien] Failed to parse JSON template: ${error instanceof Error ? error.message : String(error)}`);\n return [];\n }\n}\n\n/**\n * Extract the template name from the filepath\n * \n * templates/customers/account.json → \"customers/account\"\n * templates/product.json → \"product\"\n */\nfunction extractTemplateName(filepath: string): string | undefined {\n // Match everything after templates/ up to .json\n const match = filepath.match(/templates\\/(.+)\\.json$/);\n return match ? match[1] : undefined;\n}\n\n/**\n * Chunk a Shopify JSON template file\n * \n * JSON templates are typically small (define section layout),\n * so we keep them as a single chunk and extract section references.\n */\nexport function chunkJSONTemplate(\n filepath: string,\n content: string\n): CodeChunk[] {\n // Skip empty files\n if (content.trim().length === 0) {\n return [];\n }\n \n const lines = content.split('\\n');\n const templateName = extractTemplateName(filepath);\n const sectionReferences = extractSectionReferences(content);\n \n return [{\n content,\n metadata: {\n file: filepath,\n startLine: 1,\n endLine: lines.length,\n language: 'json',\n type: 'template',\n symbolName: templateName,\n symbolType: 'template',\n imports: sectionReferences.length > 0 ? sectionReferences : undefined,\n },\n }];\n}\n\n","import { CodeChunk } from './types.js';\nimport { detectLanguage } from './scanner.js';\nimport { extractSymbols } from './symbol-extractor.js';\nimport { shouldUseAST, chunkByAST } from './ast/chunker.js';\nimport { chunkLiquidFile } from './liquid-chunker.js';\nimport { chunkJSONTemplate } from './json-template-chunker.js';\n\nexport interface ChunkOptions {\n chunkSize?: number;\n chunkOverlap?: number;\n useAST?: boolean; // Flag to enable AST-based chunking\n astFallback?: 'line-based' | 'error'; // How to handle AST parsing errors\n}\n\nexport function chunkFile(\n filepath: string,\n content: string,\n options: ChunkOptions = {}\n): CodeChunk[] {\n const { chunkSize = 75, chunkOverlap = 10, useAST = true, astFallback = 'line-based' } = options;\n \n // Special handling for Liquid files\n if (filepath.endsWith('.liquid')) {\n return chunkLiquidFile(filepath, content, chunkSize, chunkOverlap);\n }\n \n // Special handling for Shopify JSON template files (templates/**/*.json)\n // Use regex to ensure 'templates/' is a path segment, not part of another name\n // Matches: templates/product.json OR some-path/templates/customers/account.json\n // Rejects: my-templates/config.json OR node_modules/pkg/templates/file.json (filtered by scanner)\n if (filepath.endsWith('.json') && /(?:^|\\/)templates\\//.test(filepath)) {\n return chunkJSONTemplate(filepath, content);\n }\n \n // Try AST-based chunking for supported languages\n if (useAST && shouldUseAST(filepath)) {\n try {\n return chunkByAST(filepath, content, {\n minChunkSize: Math.floor(chunkSize / 10),\n });\n } catch (error) {\n // Handle AST errors based on configuration\n if (astFallback === 'error') {\n // Throw error if user wants strict AST-only behavior\n throw new Error(`AST chunking failed for ${filepath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n // Otherwise fallback to line-based chunking\n console.warn(`AST chunking failed for ${filepath}, falling back to line-based:`, error);\n }\n }\n \n // Line-based chunking (original implementation)\n return chunkByLines(filepath, content, chunkSize, chunkOverlap);\n}\n\n/**\n * Original line-based chunking implementation\n */\nfunction chunkByLines(\n filepath: string,\n content: string,\n chunkSize: number,\n chunkOverlap: number\n): CodeChunk[] {\n const lines = content.split('\\n');\n const chunks: CodeChunk[] = [];\n const language = detectLanguage(filepath);\n \n // Handle empty files\n if (lines.length === 0 || (lines.length === 1 && lines[0].trim() === '')) {\n return chunks;\n }\n \n // Chunk by lines with overlap\n for (let i = 0; i < lines.length; i += chunkSize - chunkOverlap) {\n const endLine = Math.min(i + chunkSize, lines.length);\n const chunkLines = lines.slice(i, endLine);\n const chunkContent = chunkLines.join('\\n');\n \n // Skip empty chunks\n if (chunkContent.trim().length === 0) {\n continue;\n }\n \n // Extract symbols from the chunk\n const symbols = extractSymbols(chunkContent, language);\n \n chunks.push({\n content: chunkContent,\n metadata: {\n file: filepath,\n startLine: i + 1,\n endLine: endLine,\n type: 'block', // MVP: all chunks are 'block' type\n language,\n symbols,\n },\n });\n \n // If we've reached the end, break\n if (endLine >= lines.length) {\n break;\n }\n }\n \n return chunks;\n}\n\nexport function chunkText(text: string, options: ChunkOptions = {}): string[] {\n const { chunkSize = 75, chunkOverlap = 10 } = options;\n \n const lines = text.split('\\n');\n const chunks: string[] = [];\n \n for (let i = 0; i < lines.length; i += chunkSize - chunkOverlap) {\n const endLine = Math.min(i + chunkSize, lines.length);\n const chunkLines = lines.slice(i, endLine);\n const chunkContent = chunkLines.join('\\n');\n \n if (chunkContent.trim().length > 0) {\n chunks.push(chunkContent);\n }\n \n if (endLine >= lines.length) {\n break;\n }\n }\n \n return chunks;\n}\n\n","import { pipeline, env, type FeatureExtractionPipeline } from '@xenova/transformers';\nimport { EmbeddingService } from './types.js';\nimport { EmbeddingError, wrapError } from '../errors/index.js';\nimport { DEFAULT_EMBEDDING_MODEL } from '../constants.js';\n\n// Configure transformers.js to cache models locally\nenv.allowRemoteModels = true;\nenv.allowLocalModels = true;\n\nexport class LocalEmbeddings implements EmbeddingService {\n private extractor: FeatureExtractionPipeline | null = null;\n private readonly modelName = DEFAULT_EMBEDDING_MODEL;\n private initPromise: Promise<void> | null = null;\n \n async initialize(): Promise<void> {\n // Prevent multiple simultaneous initializations\n if (this.initPromise) {\n return this.initPromise;\n }\n \n if (this.extractor) {\n return;\n }\n \n this.initPromise = (async () => {\n try {\n // This downloads ~100MB on first run, then caches in ~/.cache/huggingface\n this.extractor = await pipeline('feature-extraction', this.modelName) as FeatureExtractionPipeline;\n } catch (error: unknown) {\n this.initPromise = null;\n throw wrapError(error, 'Failed to initialize embedding model');\n }\n })();\n \n return this.initPromise;\n }\n \n async embed(text: string): Promise<Float32Array> {\n await this.initialize();\n \n if (!this.extractor) {\n throw new EmbeddingError('Embedding model not initialized');\n }\n \n try {\n const output = await this.extractor(text, {\n pooling: 'mean',\n normalize: true,\n });\n \n return output.data as Float32Array;\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to generate embedding', { textLength: text.length });\n }\n }\n \n async embedBatch(texts: string[]): Promise<Float32Array[]> {\n await this.initialize();\n \n if (!this.extractor) {\n throw new EmbeddingError('Embedding model not initialized');\n }\n \n try {\n // Process embeddings with Promise.all for concurrent execution\n // Each call is sequential but Promise.all allows task interleaving\n const results = await Promise.all(\n texts.map(text => this.embed(text))\n );\n return results;\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to generate batch embeddings', { batchSize: texts.length });\n }\n }\n}\n\n","import { EMBEDDING_DIMENSIONS } from '../constants.js';\n\nexport interface EmbeddingService {\n initialize(): Promise<void>;\n embed(text: string): Promise<Float32Array>;\n embedBatch(texts: string[]): Promise<Float32Array[]>;\n}\n\nexport const EMBEDDING_DIMENSION = EMBEDDING_DIMENSIONS;\n\n","/**\n * Relevance category based on semantic similarity score\n */\nexport type RelevanceCategory = 'highly_relevant' | 'relevant' | 'loosely_related' | 'not_relevant';\n\n/**\n * Calculate relevance category from cosine distance score.\n * \n * Lower scores indicate higher similarity (closer in vector space).\n * Thresholds based on observed score distributions from dogfooding.\n * \n * @param score - Cosine distance score from vector search\n * @returns Human-readable relevance category\n */\nexport function calculateRelevance(score: number): RelevanceCategory {\n if (score < 1.0) return 'highly_relevant';\n if (score < 1.3) return 'relevant';\n if (score < 1.5) return 'loosely_related';\n return 'not_relevant';\n}\n\n","/**\n * Query Intent Classification\n * \n * Classifies user search queries into three categories to apply\n * appropriate relevance boosting strategies:\n * \n * - LOCATION: \"Where is X?\" - User wants to find specific files/code\n * - CONCEPTUAL: \"How does X work?\" - User wants to understand concepts\n * - IMPLEMENTATION: \"How is X implemented?\" - User wants implementation details\n * \n * Examples:\n * - \"where is the auth handler\" → LOCATION\n * - \"how does authentication work\" → CONCEPTUAL\n * - \"how is authentication implemented\" → IMPLEMENTATION\n */\n\n/**\n * Query intent types for semantic search\n */\nexport enum QueryIntent {\n /** User wants to locate specific files or code (e.g., \"where is X\") */\n LOCATION = 'location',\n \n /** User wants to understand concepts/processes (e.g., \"how does X work\") */\n CONCEPTUAL = 'conceptual',\n \n /** User wants implementation details (e.g., \"how is X implemented\") */\n IMPLEMENTATION = 'implementation',\n}\n\n/**\n * Intent classification rule with patterns and priority\n */\nexport interface IntentRule {\n intent: QueryIntent;\n patterns: RegExp[];\n priority: number;\n}\n\n/**\n * Intent classification rules.\n * Rules are checked in priority order (higher priority first).\n */\nconst INTENT_RULES: IntentRule[] = [\n // LOCATION intent (highest priority - most specific)\n {\n intent: QueryIntent.LOCATION,\n priority: 3,\n patterns: [\n /where\\s+(is|are|does|can\\s+i\\s+find)/,\n /find\\s+the\\s+/,\n /locate\\s+/,\n ],\n },\n \n // CONCEPTUAL intent (medium priority)\n {\n intent: QueryIntent.CONCEPTUAL,\n priority: 2,\n patterns: [\n /how\\s+does\\s+.*\\s+work/,\n /what\\s+(is|are|does)/,\n /explain\\s+/,\n /understand\\s+/,\n /\\b(process|workflow|architecture)\\b/,\n ],\n },\n \n // IMPLEMENTATION intent (low priority - catches \"how is X implemented\")\n {\n intent: QueryIntent.IMPLEMENTATION,\n priority: 1,\n patterns: [\n /how\\s+(is|are)\\s+.*\\s+(implemented|built|coded)/,\n /implementation\\s+of/,\n /source\\s+code\\s+for/,\n ],\n },\n];\n\n/**\n * Capture the initial number of built-in rules.\n * This is used by resetIntentRules() to distinguish built-in rules from custom rules.\n */\nconst INITIAL_RULE_COUNT = INTENT_RULES.length;\n\n/**\n * Cached sorted rules to avoid re-sorting on every query.\n * Invalidated when rules are modified via addIntentRule() or resetIntentRules().\n */\nlet cachedSortedRules: IntentRule[] | null = null;\n\n/**\n * Get sorted rules (cached).\n * Lazy-computes and caches the sorted array on first access.\n */\nfunction getSortedRules(): IntentRule[] {\n if (cachedSortedRules === null) {\n cachedSortedRules = [...INTENT_RULES].sort((a, b) => b.priority - a.priority);\n }\n return cachedSortedRules;\n}\n\n/**\n * Invalidate the sorted rules cache.\n * Called when rules are modified.\n */\nfunction invalidateSortedRulesCache(): void {\n cachedSortedRules = null;\n}\n\n/**\n * Classifies a search query into one of three intent categories.\n * \n * Uses data-driven pattern matching to detect query intent.\n * Rules are checked in priority order, with the first match winning.\n * \n * @param query - The search query string\n * @returns The detected query intent (defaults to IMPLEMENTATION)\n * \n * @example\n * classifyQueryIntent(\"where is the user controller\") // → LOCATION\n * classifyQueryIntent(\"how does authentication work\") // → CONCEPTUAL\n * classifyQueryIntent(\"how is the API implemented\") // → IMPLEMENTATION\n */\nexport function classifyQueryIntent(query: string): QueryIntent {\n const lower = query.toLowerCase().trim();\n \n // Use cached sorted rules to avoid re-sorting on every query\n const sortedRules = getSortedRules();\n \n for (const rule of sortedRules) {\n if (rule.patterns.some(pattern => pattern.test(lower))) {\n return rule.intent;\n }\n }\n \n // Default to IMPLEMENTATION for ambiguous queries\n // This is the most common use case for code search\n return QueryIntent.IMPLEMENTATION;\n}\n\n/**\n * Add a custom intent rule (useful for testing or extensions).\n * \n * Returns a cleanup function that removes the added rule.\n * This prevents test pollution and allows proper cleanup.\n * \n * @param rule - The intent rule to add\n * @returns A cleanup function that removes the added rule\n * \n * @example\n * const cleanup = addIntentRule({\n * intent: QueryIntent.LOCATION,\n * priority: 4,\n * patterns: [/custom pattern/]\n * });\n * // ... use the rule ...\n * cleanup(); // removes the rule\n */\nexport function addIntentRule(rule: IntentRule): () => void {\n INTENT_RULES.push(rule);\n \n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n \n // Return cleanup function to remove the rule\n return () => {\n const idx = INTENT_RULES.indexOf(rule);\n if (idx !== -1) {\n INTENT_RULES.splice(idx, 1);\n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n }\n };\n}\n\n/**\n * Get all patterns for a specific intent (useful for debugging).\n * \n * @param intent - The intent to get patterns for\n * @returns Array of regex patterns for the intent\n * \n * @example\n * const locationPatterns = getPatternsForIntent(QueryIntent.LOCATION);\n */\nexport function getPatternsForIntent(intent: QueryIntent): RegExp[] {\n return INTENT_RULES\n .filter(rule => rule.intent === intent)\n .flatMap(rule => rule.patterns);\n}\n\n/**\n * Get all intent rules (useful for testing/debugging).\n * \n * @returns A copy of the current intent rules\n */\nexport function getIntentRules(): IntentRule[] {\n return [...INTENT_RULES];\n}\n\n/**\n * Reset intent rules to initial state.\n * \n * WARNING: This function is intended for testing only.\n * It removes all custom rules added via addIntentRule().\n * The original built-in rules are preserved.\n * \n * @example\n * // In test cleanup\n * afterEach(() => {\n * resetIntentRules();\n * });\n */\nexport function resetIntentRules(): void {\n // Remove all custom rules, preserving only the original built-in rules\n INTENT_RULES.splice(INITIAL_RULE_COUNT);\n \n // Invalidate cache since rules have changed\n invalidateSortedRulesCache();\n}\n\n","/**\n * Boosting strategy interface.\n * \n * Each strategy applies a specific relevance boosting technique\n * to search results based on file characteristics.\n */\nexport interface BoostingStrategy {\n /** Name of the strategy (for debugging/logging) */\n name: string;\n \n /**\n * Apply the boosting strategy to a score.\n * \n * @param query - The search query string\n * @param filepath - The file path being scored\n * @param baseScore - The base relevance score from vector similarity\n * @returns The boosted score (lower is better, following LanceDB distance metric)\n */\n apply(query: string, filepath: string, baseScore: number): number;\n}\n\n","import type { BoostingStrategy } from './types.js';\nimport path from 'path';\nimport { QueryIntent } from '../intent-classifier.js';\n\n/**\n * File type detection helpers\n */\n\nfunction isDocumentationFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n const filename = path.basename(filepath).toLowerCase();\n \n if (filename.startsWith('readme')) return true;\n if (filename.startsWith('changelog')) return true;\n if (filename.endsWith('.md') || filename.endsWith('.mdx') || filename.endsWith('.markdown')) {\n return true;\n }\n if (\n lower.includes('/docs/') ||\n lower.includes('/documentation/') ||\n lower.includes('/wiki/') ||\n lower.includes('/.github/')\n ) {\n return true;\n }\n if (\n lower.includes('architecture') ||\n lower.includes('workflow') ||\n lower.includes('/flow/')\n ) {\n return true;\n }\n \n return false;\n}\n\nfunction isTestFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n \n if (\n lower.includes('/test/') ||\n lower.includes('/tests/') ||\n lower.includes('/__tests__/')\n ) {\n return true;\n }\n \n if (\n lower.includes('.test.') ||\n lower.includes('.spec.') ||\n lower.includes('_test.') ||\n lower.includes('_spec.')\n ) {\n return true;\n }\n \n return false;\n}\n\nfunction isUtilityFile(filepath: string): boolean {\n const lower = filepath.toLowerCase();\n \n if (\n lower.includes('/utils/') ||\n lower.includes('/utilities/') ||\n lower.includes('/helpers/') ||\n lower.includes('/lib/')\n ) {\n return true;\n }\n \n if (\n lower.includes('.util.') ||\n lower.includes('.helper.') ||\n lower.includes('-util.') ||\n lower.includes('-helper.')\n ) {\n return true;\n }\n \n return false;\n}\n\n/**\n * Boosting Strategies\n */\n\n/**\n * Boosts relevance based on path segment matching.\n * Files with query tokens in their path are boosted.\n */\nexport class PathBoostingStrategy implements BoostingStrategy {\n name = 'path-matching';\n \n apply(query: string, filepath: string, baseScore: number): number {\n const queryTokens = query.toLowerCase().split(/\\s+/);\n const pathSegments = filepath.toLowerCase().split('/');\n \n let boostFactor = 1.0;\n \n for (const token of queryTokens) {\n if (token.length <= 2) continue;\n if (pathSegments.some(seg => seg.includes(token))) {\n boostFactor *= 0.9; // Reduce distance = increase relevance\n }\n }\n \n return baseScore * boostFactor;\n }\n}\n\n/**\n * Boosts relevance based on filename matching.\n * Files with query tokens in their filename are strongly boosted.\n */\nexport class FilenameBoostingStrategy implements BoostingStrategy {\n name = 'filename-matching';\n \n apply(query: string, filepath: string, baseScore: number): number {\n const filename = path.basename(filepath, path.extname(filepath)).toLowerCase();\n const queryTokens = query.toLowerCase().split(/\\s+/);\n \n let boostFactor = 1.0;\n \n for (const token of queryTokens) {\n if (token.length <= 2) continue;\n \n if (filename === token) {\n boostFactor *= 0.70; // Strong boost for exact match\n } else if (filename.includes(token)) {\n boostFactor *= 0.80; // Moderate boost for partial match\n }\n }\n \n return baseScore * boostFactor;\n }\n}\n\n/**\n * Boosts relevance based on file type and query intent.\n * Different file types are boosted for different query intents.\n * \n * Note: This strategy focuses on file-type-specific boosting (test files,\n * documentation files, utility files, etc.). Path and filename boosting\n * are handled separately by PathBoostingStrategy and FilenameBoostingStrategy\n * in the BoostingComposer to avoid double-boosting.\n */\nexport class FileTypeBoostingStrategy implements BoostingStrategy {\n name = 'file-type';\n \n constructor(private intent: QueryIntent) {}\n \n apply(query: string, filepath: string, baseScore: number): number {\n switch (this.intent) {\n case QueryIntent.LOCATION:\n return this.applyLocationBoosting(query, filepath, baseScore);\n \n case QueryIntent.CONCEPTUAL:\n return this.applyConceptualBoosting(query, filepath, baseScore);\n \n case QueryIntent.IMPLEMENTATION:\n return this.applyImplementationBoosting(query, filepath, baseScore);\n \n default:\n return baseScore;\n }\n }\n \n private applyLocationBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for location queries.\n \n // Slightly deprioritize test files (users want implementation location, not tests)\n if (isTestFile(filepath)) {\n score *= 1.10;\n }\n \n return score;\n }\n \n private applyConceptualBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for conceptual queries.\n \n // Strong boost for documentation files\n if (isDocumentationFile(filepath)) {\n score *= 0.65;\n \n const lower = filepath.toLowerCase();\n if (\n lower.includes('architecture') ||\n lower.includes('workflow') ||\n lower.includes('flow')\n ) {\n score *= 0.90; // Extra boost for architectural docs\n }\n }\n \n // Slight boost for utility files (often contain reusable logic)\n if (isUtilityFile(filepath)) {\n score *= 0.95;\n }\n \n return score;\n }\n \n private applyImplementationBoosting(_query: string, filepath: string, score: number): number {\n // Note: Path and filename boosting are handled by PathBoostingStrategy and\n // FilenameBoostingStrategy in the composer. This method only handles\n // file-type-specific boosting for implementation queries.\n \n // Slightly deprioritize test files (user wants implementation, not tests)\n if (isTestFile(filepath)) {\n score *= 1.10;\n }\n \n return score;\n }\n}\n\n","import type { BoostingStrategy } from './types.js';\n\n/**\n * Composes multiple boosting strategies into a single pipeline.\n * \n * Strategies are applied sequentially, with each strategy\n * receiving the output of the previous strategy as input.\n * \n * @example\n * ```typescript\n * const composer = new BoostingComposer()\n * .addStrategy(new PathBoostingStrategy())\n * .addStrategy(new FilenameBoostingStrategy())\n * .addStrategy(new FileTypeBoostingStrategy(intent));\n * \n * const boostedScore = composer.apply(query, filepath, baseScore);\n * ```\n */\nexport class BoostingComposer {\n private strategies: BoostingStrategy[] = [];\n \n /**\n * Add a boosting strategy to the pipeline.\n * Strategies are applied in the order they are added.\n * \n * @param strategy - The strategy to add\n * @returns This composer for chaining\n */\n addStrategy(strategy: BoostingStrategy): this {\n this.strategies.push(strategy);\n return this;\n }\n \n /**\n * Apply all strategies to a base score.\n * \n * @param query - The search query\n * @param filepath - The file path being scored\n * @param baseScore - The initial score from vector similarity\n * @returns The final boosted score after all strategies\n */\n apply(query: string, filepath: string, baseScore: number): number {\n let score = baseScore;\n \n for (const strategy of this.strategies) {\n score = strategy.apply(query, filepath, score);\n }\n \n return score;\n }\n \n /**\n * Get the names of all strategies in this composer.\n * Useful for debugging and logging.\n */\n getStrategyNames(): string[] {\n return this.strategies.map(s => s.name);\n }\n \n /**\n * Get the number of strategies in this composer.\n */\n getStrategyCount(): number {\n return this.strategies.length;\n }\n \n /**\n * Clear all strategies from this composer.\n */\n clear(): void {\n this.strategies = [];\n }\n}\n\n","/**\n * Composable boosting strategies for semantic search relevance.\n * \n * This module provides a strategy pattern implementation for applying\n * relevance boosting to search results. Strategies can be composed\n * together to create complex boosting pipelines.\n * \n * @example\n * ```typescript\n * import { BoostingComposer, PathBoostingStrategy, FilenameBoostingStrategy } from './boosting';\n * \n * const composer = new BoostingComposer()\n * .addStrategy(new PathBoostingStrategy())\n * .addStrategy(new FilenameBoostingStrategy());\n * \n * const boostedScore = composer.apply(query, filepath, baseScore);\n * ```\n */\n\nexport * from './types.js';\nexport * from './strategies.js';\nexport * from './composer.js';\n\n","import { SearchResult } from './types.js';\nimport { EMBEDDING_DIMENSION } from '../embeddings/types.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport { calculateRelevance } from './relevance.js';\nimport { classifyQueryIntent, QueryIntent } from './intent-classifier.js';\nimport { BoostingComposer, PathBoostingStrategy, FilenameBoostingStrategy, FileTypeBoostingStrategy } from './boosting/index.js';\n\n// TODO: Replace with proper type from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// See: https://github.com/getlien/lien/issues/XXX\ntype LanceDBTable = any;\n\n/**\n * Cached strategy instances to avoid repeated instantiation overhead.\n * These strategies are stateless and can be safely reused across queries.\n */\nconst PATH_STRATEGY = new PathBoostingStrategy();\nconst FILENAME_STRATEGY = new FilenameBoostingStrategy();\n\n/**\n * Cached FileTypeBoostingStrategy instances for each intent.\n * Since there are only three possible intents, we can cache all three.\n */\nconst FILE_TYPE_STRATEGIES = {\n [QueryIntent.LOCATION]: new FileTypeBoostingStrategy(QueryIntent.LOCATION),\n [QueryIntent.CONCEPTUAL]: new FileTypeBoostingStrategy(QueryIntent.CONCEPTUAL),\n [QueryIntent.IMPLEMENTATION]: new FileTypeBoostingStrategy(QueryIntent.IMPLEMENTATION),\n};\n\n/**\n * Cached BoostingComposer instances for each intent.\n * Pre-configured with the appropriate strategy pipeline for each intent type.\n * This avoids creating a new composer instance on every search result.\n */\nconst BOOSTING_COMPOSERS = {\n [QueryIntent.LOCATION]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.LOCATION]),\n [QueryIntent.CONCEPTUAL]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.CONCEPTUAL]),\n [QueryIntent.IMPLEMENTATION]: new BoostingComposer()\n .addStrategy(PATH_STRATEGY)\n .addStrategy(FILENAME_STRATEGY)\n .addStrategy(FILE_TYPE_STRATEGIES[QueryIntent.IMPLEMENTATION]),\n};\n\n/**\n * Database record structure as stored in LanceDB\n */\ninterface DBRecord {\n vector: number[];\n content: string;\n file: string;\n startLine: number;\n endLine: number;\n type: string;\n language: string;\n functionNames: string[];\n classNames: string[];\n interfaceNames: string[];\n // AST-derived metadata (v0.13.0)\n symbolName?: string;\n symbolType?: string;\n parentClass?: string;\n complexity?: number;\n cognitiveComplexity?: number;\n parameters?: string[];\n signature?: string;\n imports?: string[];\n // Halstead metrics (v0.19.0)\n halsteadVolume?: number;\n halsteadDifficulty?: number;\n halsteadEffort?: number;\n halsteadBugs?: number;\n _distance?: number; // Added by LanceDB for search results\n}\n\n/**\n * Check if a DB record has valid content and file path.\n * Used to filter out empty/invalid records from query results.\n */\nfunction isValidRecord(r: DBRecord): boolean {\n return Boolean(\n r.content && \n r.content.trim().length > 0 &&\n r.file && \n r.file.length > 0\n );\n}\n\n/**\n * Check if an array field has valid (non-empty) entries.\n * LanceDB stores empty arrays as [''] which we need to filter out.\n */\nfunction hasValidArrayEntries(arr: string[] | undefined): boolean {\n return Boolean(arr && arr.length > 0 && arr[0] !== '');\n}\n\n/**\n * Get symbols for a specific type from a DB record.\n * Consolidates the symbol extraction logic used across query functions.\n */\nfunction getSymbolsForType(\n r: DBRecord, \n symbolType?: 'function' | 'class' | 'interface'\n): string[] {\n if (symbolType === 'function') return r.functionNames || [];\n if (symbolType === 'class') return r.classNames || [];\n if (symbolType === 'interface') return r.interfaceNames || [];\n return [\n ...(r.functionNames || []),\n ...(r.classNames || []),\n ...(r.interfaceNames || []),\n ];\n}\n\n/**\n * Convert a DB record to base SearchResult metadata.\n * Shared between all query functions to avoid duplication.\n */\nfunction buildSearchResultMetadata(r: DBRecord): SearchResult['metadata'] {\n return {\n file: r.file,\n startLine: r.startLine,\n endLine: r.endLine,\n type: r.type as 'function' | 'class' | 'block',\n language: r.language,\n symbolName: r.symbolName || undefined,\n symbolType: r.symbolType as 'function' | 'method' | 'class' | 'interface' | undefined,\n parentClass: r.parentClass || undefined,\n complexity: r.complexity || undefined,\n cognitiveComplexity: r.cognitiveComplexity || undefined,\n parameters: hasValidArrayEntries(r.parameters) ? r.parameters : undefined,\n signature: r.signature || undefined,\n imports: hasValidArrayEntries(r.imports) ? r.imports : undefined,\n // Halstead metrics (v0.19.0) - use explicit null check to preserve valid 0 values\n halsteadVolume: r.halsteadVolume != null ? r.halsteadVolume : undefined,\n halsteadDifficulty: r.halsteadDifficulty != null ? r.halsteadDifficulty : undefined,\n halsteadEffort: r.halsteadEffort != null ? r.halsteadEffort : undefined,\n halsteadBugs: r.halsteadBugs != null ? r.halsteadBugs : undefined,\n };\n}\n\n/**\n * Apply relevance boosting strategies to a search score.\n * \n * Uses composable boosting strategies based on query intent:\n * - Path matching: Boost files with query tokens in path\n * - Filename matching: Boost files with query tokens in filename\n * - File type boosting: Intent-specific boosting (docs for conceptual, etc.)\n */\nfunction applyRelevanceBoosting(\n query: string | undefined,\n filepath: string,\n baseScore: number\n): number {\n if (!query) {\n return baseScore;\n }\n \n const intent = classifyQueryIntent(query);\n \n // Use cached composer instance configured for this intent\n return BOOSTING_COMPOSERS[intent].apply(query, filepath, baseScore);\n}\n\n/**\n * Convert a DBRecord to a SearchResult\n */\nfunction dbRecordToSearchResult(\n r: DBRecord,\n query?: string\n): SearchResult {\n const baseScore = r._distance ?? 0;\n const boostedScore = applyRelevanceBoosting(query, r.file, baseScore);\n \n return {\n content: r.content,\n metadata: buildSearchResultMetadata(r),\n score: boostedScore,\n relevance: calculateRelevance(boostedScore),\n };\n}\n\n/**\n * Search the vector database\n */\nexport async function search(\n table: LanceDBTable,\n queryVector: Float32Array,\n limit: number = 5,\n query?: string\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n const results = await table\n .search(Array.from(queryVector))\n .limit(limit + 20)\n .toArray();\n \n const filtered = (results as unknown as DBRecord[])\n .filter(isValidRecord)\n .map((r: DBRecord) => dbRecordToSearchResult(r, query))\n .sort((a, b) => a.score - b.score)\n .slice(0, limit);\n \n return filtered;\n } catch (error) {\n const errorMsg = String(error);\n \n // Detect corrupted index\n if (errorMsg.includes('Not found:') || errorMsg.includes('.lance')) {\n throw new DatabaseError(\n `Index appears corrupted or outdated. Please restart the MCP server or run 'lien reindex' in the project directory.`,\n { originalError: error }\n );\n }\n \n throw wrapError(error, 'Failed to search vector database');\n }\n}\n\n/**\n * Scan the database with filters\n */\nexport async function scanWithFilter(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n limit?: number;\n }\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n const { language, pattern, limit = 100 } = options;\n \n try {\n const zeroVector = Array(EMBEDDING_DIMENSION).fill(0);\n const query = table.search(zeroVector)\n .where('file != \"\"')\n .limit(Math.max(limit * 5, 200));\n \n const results = await query.toArray();\n \n let filtered = (results as unknown as DBRecord[]).filter(isValidRecord);\n \n if (language) {\n filtered = filtered.filter((r: DBRecord) => \n r.language && r.language.toLowerCase() === language.toLowerCase()\n );\n }\n \n if (pattern) {\n const regex = new RegExp(pattern, 'i');\n filtered = filtered.filter((r: DBRecord) =>\n regex.test(r.content) || regex.test(r.file)\n );\n }\n \n return filtered.slice(0, limit).map((r: DBRecord) => ({\n content: r.content,\n metadata: buildSearchResultMetadata(r),\n score: 0,\n relevance: calculateRelevance(0),\n }));\n } catch (error) {\n throw wrapError(error, 'Failed to scan with filter');\n }\n}\n\n/**\n * Helper to check if a record matches the requested symbol type\n */\n/** Maps query symbolType to acceptable AST symbolType values */\nconst SYMBOL_TYPE_MATCHES: Record<string, Set<string>> = {\n function: new Set(['function', 'method']),\n class: new Set(['class']),\n interface: new Set(['interface']),\n};\n\nfunction matchesSymbolType(\n record: DBRecord,\n symbolType: 'function' | 'class' | 'interface',\n symbols: string[]\n): boolean {\n // If AST-based symbolType exists, use lookup table\n if (record.symbolType) {\n return SYMBOL_TYPE_MATCHES[symbolType]?.has(record.symbolType) ?? false;\n }\n\n // Fallback: check if pre-AST symbols array has valid entries\n return symbols.length > 0 && symbols.some((s: string) => s.length > 0 && s !== '');\n}\n\ninterface SymbolQueryOptions {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n}\n\n/**\n * Check if a record matches the symbol query filters.\n * Extracted to reduce complexity of querySymbols.\n */\nfunction matchesSymbolFilter(\n r: DBRecord, \n { language, pattern, symbolType }: SymbolQueryOptions\n): boolean {\n // Language filter\n if (language && (!r.language || r.language.toLowerCase() !== language.toLowerCase())) {\n return false;\n }\n \n const symbols = getSymbolsForType(r, symbolType);\n const astSymbolName = r.symbolName || '';\n \n // Must have at least one symbol (legacy or AST-based)\n if (symbols.length === 0 && !astSymbolName) {\n return false;\n }\n \n // Pattern filter (if provided)\n if (pattern) {\n const regex = new RegExp(pattern, 'i');\n const nameMatches = symbols.some((s: string) => regex.test(s)) || regex.test(astSymbolName);\n if (!nameMatches) return false;\n }\n \n // Symbol type filter (if provided)\n if (symbolType) {\n return matchesSymbolType(r, symbolType, symbols);\n }\n \n return true;\n}\n\n/**\n * Build legacy symbols object for backwards compatibility.\n */\nfunction buildLegacySymbols(r: DBRecord) {\n return {\n functions: hasValidArrayEntries(r.functionNames) ? r.functionNames : [],\n classes: hasValidArrayEntries(r.classNames) ? r.classNames : [],\n interfaces: hasValidArrayEntries(r.interfaceNames) ? r.interfaceNames : [],\n };\n}\n\n/**\n * Query symbols (functions, classes, interfaces)\n */\nexport async function querySymbols(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n limit?: number;\n }\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n const { language, pattern, symbolType, limit = 50 } = options;\n const filterOpts: SymbolQueryOptions = { language, pattern, symbolType };\n \n try {\n const zeroVector = Array(EMBEDDING_DIMENSION).fill(0);\n const query = table.search(zeroVector)\n .where('file != \"\"')\n .limit(Math.max(limit * 10, 500));\n \n const results = await query.toArray();\n \n const filtered = (results as unknown as DBRecord[])\n .filter((r) => isValidRecord(r) && matchesSymbolFilter(r, filterOpts));\n \n return filtered.slice(0, limit).map((r: DBRecord) => ({\n content: r.content,\n metadata: {\n ...buildSearchResultMetadata(r),\n symbols: buildLegacySymbols(r),\n },\n score: 0,\n relevance: calculateRelevance(0),\n }));\n } catch (error) {\n throw wrapError(error, 'Failed to query symbols');\n }\n}\n\n/**\n * Scan all chunks in the database\n * First gets the total count, then fetches all with a single query\n * This is more efficient than pagination for local/embedded databases like LanceDB\n */\nexport async function scanAll(\n table: LanceDBTable,\n options: {\n language?: string;\n pattern?: string;\n } = {}\n): Promise<SearchResult[]> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // Get total row count to determine limit\n const totalRows = await table.countRows();\n \n // Fetch all rows in one query (LanceDB is local, this is efficient)\n // Note: scanWithFilter internally fetches 5x the limit to handle filtering overhead,\n // then caps output to 'limit'. We pass totalRows so we get all rows back after\n // filtering. The 5x overfetch is acceptable overhead for local DBs.\n const MIN_SCAN_LIMIT = 1000;\n const results = await scanWithFilter(table, {\n ...options,\n limit: Math.max(totalRows, MIN_SCAN_LIMIT),\n });\n \n return results;\n } catch (error) {\n throw wrapError(error, 'Failed to scan all chunks');\n }\n}\n","import { ChunkMetadata } from '../indexer/types.js';\nimport { DatabaseError } from '../errors/index.js';\nimport { VECTOR_DB_MAX_BATCH_SIZE, VECTOR_DB_MIN_BATCH_SIZE } from '../constants.js';\n\n// TODO: Replace with proper types from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// Proper types: Awaited<ReturnType<typeof lancedb.connect>> and Awaited<ReturnType<Connection['openTable']>>\ntype LanceDBConnection = any;\ntype LanceDBTable = any;\n\n/**\n * Batch of data to be inserted into the vector database\n */\ninterface BatchToProcess {\n vectors: Float32Array[];\n metadatas: ChunkMetadata[];\n contents: string[];\n}\n\n/**\n * Database record format for LanceDB storage\n */\ninterface DatabaseRecord {\n vector: number[];\n content: string;\n file: string;\n startLine: number;\n endLine: number;\n type: string;\n language: string;\n functionNames: string[];\n classNames: string[];\n interfaceNames: string[];\n symbolName: string;\n symbolType: string;\n parentClass: string;\n complexity: number;\n cognitiveComplexity: number;\n parameters: string[];\n signature: string;\n imports: string[];\n // Halstead metrics (v0.19.0)\n halsteadVolume: number;\n halsteadDifficulty: number;\n halsteadEffort: number;\n halsteadBugs: number;\n}\n\n/**\n * Transform a chunk's data into a database record.\n * Handles missing/empty metadata by providing defaults for Arrow type inference.\n */\nfunction transformChunkToRecord(\n vector: Float32Array,\n content: string,\n metadata: ChunkMetadata\n): DatabaseRecord {\n return {\n vector: Array.from(vector),\n content,\n file: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n type: metadata.type,\n language: metadata.language,\n // Ensure arrays have at least empty string for Arrow type inference\n functionNames: getNonEmptyArray(metadata.symbols?.functions),\n classNames: getNonEmptyArray(metadata.symbols?.classes),\n interfaceNames: getNonEmptyArray(metadata.symbols?.interfaces),\n // AST-derived metadata (v0.13.0)\n symbolName: metadata.symbolName || '',\n symbolType: metadata.symbolType || '',\n parentClass: metadata.parentClass || '',\n complexity: metadata.complexity || 0,\n cognitiveComplexity: metadata.cognitiveComplexity || 0,\n parameters: getNonEmptyArray(metadata.parameters),\n signature: metadata.signature || '',\n imports: getNonEmptyArray(metadata.imports),\n // Halstead metrics (v0.19.0)\n halsteadVolume: metadata.halsteadVolume || 0,\n halsteadDifficulty: metadata.halsteadDifficulty || 0,\n halsteadEffort: metadata.halsteadEffort || 0,\n halsteadBugs: metadata.halsteadBugs || 0,\n };\n}\n\n/**\n * Returns the array if non-empty, otherwise returns [''] for Arrow type inference\n */\nfunction getNonEmptyArray(arr: string[] | undefined): string[] {\n return arr && arr.length > 0 ? arr : [''];\n}\n\n/**\n * Split a batch in half for retry logic\n */\nfunction splitBatchInHalf(batch: BatchToProcess): [BatchToProcess, BatchToProcess] {\n const half = Math.floor(batch.vectors.length / 2);\n return [\n {\n vectors: batch.vectors.slice(0, half),\n metadatas: batch.metadatas.slice(0, half),\n contents: batch.contents.slice(0, half),\n },\n {\n vectors: batch.vectors.slice(half),\n metadatas: batch.metadatas.slice(half),\n contents: batch.contents.slice(half),\n },\n ];\n}\n\n/**\n * Transform all chunks in a batch to database records\n */\nfunction transformBatchToRecords(batch: BatchToProcess): DatabaseRecord[] {\n return batch.vectors.map((vector, i) =>\n transformChunkToRecord(vector, batch.contents[i], batch.metadatas[i])\n );\n}\n\n/**\n * Insert a batch of vectors into the database\n * \n * @returns The table instance after insertion, or null only when:\n * - vectors.length === 0 AND table === null (no-op case)\n * For non-empty batches, always returns a valid table or throws.\n * @throws {DatabaseError} If database not initialized or insertion fails\n */\nexport async function insertBatch(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable | null> {\n if (!db) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n if (vectors.length !== metadatas.length || vectors.length !== contents.length) {\n throw new DatabaseError('Vectors, metadatas, and contents arrays must have the same length', {\n vectorsLength: vectors.length,\n metadatasLength: metadatas.length,\n contentsLength: contents.length,\n });\n }\n \n // Handle empty batch gracefully - return table as-is (could be null)\n if (vectors.length === 0) {\n return table;\n }\n \n // Split large batches into smaller chunks\n if (vectors.length > VECTOR_DB_MAX_BATCH_SIZE) {\n let currentTable = table;\n for (let i = 0; i < vectors.length; i += VECTOR_DB_MAX_BATCH_SIZE) {\n const batchVectors = vectors.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n const batchMetadata = metadatas.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n const batchContents = contents.slice(i, Math.min(i + VECTOR_DB_MAX_BATCH_SIZE, vectors.length));\n \n currentTable = await insertBatchInternal(db, currentTable, tableName, batchVectors, batchMetadata, batchContents);\n }\n if (!currentTable) {\n throw new DatabaseError('Failed to create table during batch insert');\n }\n return currentTable;\n } else {\n return insertBatchInternal(db, table, tableName, vectors, metadatas, contents);\n }\n}\n\n/**\n * Internal method to insert a single batch with iterative retry logic.\n * Uses a queue-based approach to handle batch splitting on failure.\n * \n * @returns Always returns a valid LanceDBTable or throws DatabaseError\n */\nasync function insertBatchInternal(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable> {\n const queue: BatchToProcess[] = [{ vectors, metadatas, contents }];\n const failedBatches: BatchToProcess[] = [];\n let currentTable = table;\n let lastError: Error | undefined;\n \n while (queue.length > 0) {\n const batch = queue.shift()!;\n const insertResult = await tryInsertBatch(db, currentTable, tableName, batch);\n \n if (insertResult.success) {\n currentTable = insertResult.table;\n } else {\n lastError = insertResult.error;\n handleBatchFailure(batch, queue, failedBatches);\n }\n }\n \n throwIfBatchesFailed(failedBatches, lastError);\n \n if (!currentTable) {\n throw new DatabaseError('Failed to create table during batch insert');\n }\n \n return currentTable;\n}\n\n/**\n * Result of attempting to insert a batch\n */\ninterface InsertResult {\n success: boolean;\n table: LanceDBTable | null;\n error?: Error;\n}\n\n/**\n * Attempt to insert a batch of records into the database.\n * Errors are captured and returned (not thrown) to support retry logic.\n */\nasync function tryInsertBatch(\n db: LanceDBConnection,\n currentTable: LanceDBTable | null,\n tableName: string,\n batch: BatchToProcess\n): Promise<InsertResult> {\n try {\n const records = transformBatchToRecords(batch);\n \n if (!currentTable) {\n const newTable = await db.createTable(tableName, records);\n return { success: true, table: newTable };\n } else {\n await currentTable.add(records);\n return { success: true, table: currentTable };\n }\n } catch (error) {\n // Error is captured for retry logic - will be included in final error if all retries fail\n return { success: false, table: currentTable, error: error as Error };\n }\n}\n\n/**\n * Handle a failed batch insertion by either splitting and retrying or marking as failed\n */\nfunction handleBatchFailure(\n batch: BatchToProcess,\n queue: BatchToProcess[],\n failedBatches: BatchToProcess[]\n): void {\n if (batch.vectors.length > VECTOR_DB_MIN_BATCH_SIZE) {\n // Split and retry\n const [firstHalf, secondHalf] = splitBatchInHalf(batch);\n queue.push(firstHalf, secondHalf);\n } else {\n // Can't split further, mark as failed\n failedBatches.push(batch);\n }\n}\n\n/**\n * Throw an error if any batches failed after all retry attempts.\n * Includes the last error encountered for debugging.\n */\nfunction throwIfBatchesFailed(failedBatches: BatchToProcess[], lastError?: Error): void {\n if (failedBatches.length === 0) return;\n \n const totalFailed = failedBatches.reduce((sum, batch) => sum + batch.vectors.length, 0);\n throw new DatabaseError(\n `Failed to insert ${totalFailed} record(s) after retry attempts`,\n {\n failedBatches: failedBatches.length,\n totalRecords: totalFailed,\n sampleFile: failedBatches[0].metadatas[0].file,\n lastError: lastError?.message,\n }\n );\n}\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport { writeVersionFile } from './version.js';\nimport { insertBatch } from './batch-insert.js';\n\n// TODO: Replace with proper types from lancedb-types.ts\n// Currently using 'any' because tests use incomplete mocks that don't satisfy full LanceDB interface\n// Proper types: Awaited<ReturnType<typeof lancedb.connect>> and Awaited<ReturnType<Connection['openTable']>>\ntype LanceDBConnection = any;\ntype LanceDBTable = any;\n\n/**\n * Clear all data from the vector database.\n * Drops the table AND cleans up the .lance directory to prevent corrupted state.\n */\nexport async function clear(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n dbPath?: string\n): Promise<void> {\n if (!db) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // Drop table if it exists\n if (table) {\n await db.dropTable(tableName);\n }\n \n // Clean up the .lance directory if dbPath provided\n // This prevents corrupted state after dropTable\n if (dbPath) {\n const lanceDir = path.join(dbPath, `${tableName}.lance`);\n try {\n await fs.rm(lanceDir, { recursive: true, force: true });\n } catch {\n // Ignore errors - directory may not exist\n }\n }\n } catch (error) {\n throw wrapError(error, 'Failed to clear vector database');\n }\n}\n\n/**\n * Delete all chunks from a specific file\n */\nexport async function deleteByFile(\n table: LanceDBTable,\n filepath: string\n): Promise<void> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n await table.delete(`file = \"${filepath}\"`);\n } catch (error) {\n throw wrapError(error, 'Failed to delete file from vector database');\n }\n}\n\n/**\n * Update a file in the index by atomically deleting old chunks and inserting new ones\n */\nexport async function updateFile(\n db: LanceDBConnection,\n table: LanceDBTable | null,\n tableName: string,\n dbPath: string,\n filepath: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n): Promise<LanceDBTable> {\n if (!table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n // 1. Delete old chunks from this file\n await deleteByFile(table, filepath);\n \n // 2. Insert new chunks (if any)\n let updatedTable = table;\n if (vectors.length > 0) {\n updatedTable = await insertBatch(db, table, tableName, vectors, metadatas, contents);\n if (!updatedTable) {\n throw new DatabaseError('insertBatch unexpectedly returned null');\n }\n }\n \n // 3. Update version file to trigger MCP reconnection\n await writeVersionFile(dbPath);\n \n return updatedTable;\n } catch (error) {\n throw wrapError(error, 'Failed to update file in vector database');\n }\n}\n\n","import * as lancedb from '@lancedb/lancedb';\nimport path from 'path';\nimport os from 'os';\nimport crypto from 'crypto';\nimport { SearchResult, VectorDBInterface } from './types.js';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { EMBEDDING_DIMENSION } from '../embeddings/types.js';\nimport { readVersionFile } from './version.js';\nimport { DatabaseError, wrapError } from '../errors/index.js';\nimport * as queryOps from './query.js';\nimport * as batchOps from './batch-insert.js';\nimport * as maintenanceOps from './maintenance.js';\n\ntype LanceDBConnection = Awaited<ReturnType<typeof lancedb.connect>>;\ntype LanceDBTable = Awaited<ReturnType<LanceDBConnection['openTable']>>;\n\nexport class VectorDB implements VectorDBInterface {\n private db: LanceDBConnection | null = null;\n private table: LanceDBTable | null = null;\n public readonly dbPath: string;\n private readonly tableName = 'code_chunks';\n private lastVersionCheck: number = 0;\n private currentVersion: number = 0;\n \n constructor(projectRoot: string) {\n // Store in user's home directory under ~/.lien/indices/{projectName-hash}\n const projectName = path.basename(projectRoot);\n \n // Create unique identifier from full path to prevent collisions\n const pathHash = crypto\n .createHash('md5')\n .update(projectRoot)\n .digest('hex')\n .substring(0, 8);\n \n this.dbPath = path.join(\n os.homedir(),\n '.lien',\n 'indices',\n `${projectName}-${pathHash}`\n );\n }\n \n async initialize(): Promise<void> {\n try {\n this.db = await lancedb.connect(this.dbPath);\n \n try {\n this.table = await this.db.openTable(this.tableName);\n } catch {\n // Table doesn't exist yet - will be created on first insert\n this.table = null;\n }\n \n // Read and cache the current version\n try {\n this.currentVersion = await readVersionFile(this.dbPath);\n } catch {\n // Version file doesn't exist yet, will be created on first index\n this.currentVersion = 0;\n }\n } catch (error: unknown) {\n throw wrapError(error, 'Failed to initialize vector database', { dbPath: this.dbPath });\n }\n }\n \n async insertBatch(\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n ): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database not initialized');\n }\n // Note: insertBatch may return null for empty batches when table is null\n // This is correct behavior - empty batches are no-ops and don't create tables\n this.table = await batchOps.insertBatch(\n this.db,\n this.table,\n this.tableName,\n vectors,\n metadatas,\n contents\n );\n }\n \n async search(\n queryVector: Float32Array,\n limit: number = 5,\n query?: string\n ): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n \n try {\n return await queryOps.search(this.table, queryVector, limit, query);\n } catch (error) {\n const errorMsg = String(error);\n \n // Detect corrupted index or missing data files\n if (errorMsg.includes('Not found:') || errorMsg.includes('.lance')) {\n // Attempt to reconnect - index may have been rebuilt\n try {\n await this.initialize();\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized after reconnection');\n }\n return await queryOps.search(this.table, queryVector, limit, query);\n } catch (retryError: unknown) {\n throw new DatabaseError(\n `Index appears corrupted or outdated. Please restart the MCP server or run 'lien reindex' in the project directory.`,\n { originalError: retryError }\n );\n }\n }\n \n throw error;\n }\n }\n \n async scanWithFilter(options: {\n language?: string;\n pattern?: string;\n limit?: number;\n }): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.scanWithFilter(this.table, options);\n }\n \n /**\n * Scan all chunks in the database\n * Fetches total count first, then retrieves all chunks in a single optimized query\n * @param options - Filter options (language, pattern)\n * @returns All matching chunks\n */\n async scanAll(options: {\n language?: string;\n pattern?: string;\n } = {}): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.scanAll(this.table, options);\n }\n \n async querySymbols(options: {\n language?: string;\n pattern?: string;\n symbolType?: 'function' | 'class' | 'interface';\n limit?: number;\n }): Promise<SearchResult[]> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n return queryOps.querySymbols(this.table, options);\n }\n \n async clear(): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database not initialized');\n }\n await maintenanceOps.clear(this.db, this.table, this.tableName, this.dbPath);\n this.table = null;\n }\n \n async deleteByFile(filepath: string): Promise<void> {\n if (!this.table) {\n throw new DatabaseError('Vector database not initialized');\n }\n await maintenanceOps.deleteByFile(this.table, filepath);\n }\n \n async updateFile(\n filepath: string,\n vectors: Float32Array[],\n metadatas: ChunkMetadata[],\n contents: string[]\n ): Promise<void> {\n if (!this.db) {\n throw new DatabaseError('Vector database connection not initialized');\n }\n if (!this.table) {\n throw new DatabaseError('Vector database table not initialized');\n }\n this.table = await maintenanceOps.updateFile(\n this.db,\n this.table,\n this.tableName,\n this.dbPath,\n filepath,\n vectors,\n metadatas,\n contents\n );\n }\n \n async checkVersion(): Promise<boolean> {\n const now = Date.now();\n \n // Cache version checks for 1 second to minimize I/O\n if (now - this.lastVersionCheck < 1000) {\n return false;\n }\n \n this.lastVersionCheck = now;\n \n try {\n const version = await readVersionFile(this.dbPath);\n \n if (version > this.currentVersion) {\n this.currentVersion = version;\n return true;\n }\n \n return false;\n } catch (error) {\n // If we can't read version file, don't reconnect\n return false;\n }\n }\n \n async reconnect(): Promise<void> {\n try {\n // Close existing connections to force reload from disk\n this.table = null;\n this.db = null;\n \n // Reinitialize with fresh connection\n await this.initialize();\n } catch (error) {\n throw wrapError(error, 'Failed to reconnect to vector database');\n }\n }\n \n getCurrentVersion(): number {\n return this.currentVersion;\n }\n \n getVersionDate(): string {\n if (this.currentVersion === 0) {\n return 'Unknown';\n }\n return new Date(this.currentVersion).toLocaleString();\n }\n \n async hasData(): Promise<boolean> {\n if (!this.table) {\n return false;\n }\n \n try {\n const count = await this.table.countRows();\n \n if (count === 0) {\n return false;\n }\n \n // Sample a few rows to verify they contain real data\n const sample = await this.table\n .search(Array(EMBEDDING_DIMENSION).fill(0))\n .limit(Math.min(count, 5))\n .toArray();\n \n const hasRealData = (sample as unknown as any[]).some((r: any) => \n r.content && \n r.content.trim().length > 0\n );\n \n return hasRealData;\n } catch {\n // If any error occurs, assume no data\n return false;\n }\n }\n \n static async load(projectRoot: string): Promise<VectorDB> {\n const db = new VectorDB(projectRoot);\n await db.initialize();\n return db;\n }\n}\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { INDEX_FORMAT_VERSION } from '../constants.js';\nimport { GitState } from '../git/tracker.js';\nimport { getPackageVersion } from '../utils/version.js';\n\nconst MANIFEST_FILE = 'manifest.json';\n\n/**\n * Represents a single file in the index manifest\n */\nexport interface FileEntry {\n filepath: string;\n lastModified: number;\n chunkCount: number;\n}\n\n/**\n * Index manifest tracking all indexed files and version information\n */\nexport interface IndexManifest {\n formatVersion: number; // Index format version for compatibility checking\n lienVersion: string; // Lien package version (for reference)\n lastIndexed: number; // Timestamp of last indexing operation\n gitState?: GitState; // Last known git state\n files: Record<string, FileEntry>; // Map of filepath -> FileEntry (stored as object for JSON)\n}\n\n/**\n * Manages the index manifest file, tracking which files are indexed\n * and their metadata for incremental indexing support.\n * \n * The manifest includes version checking to invalidate indices when\n * Lien's indexing format changes (e.g., new chunking algorithm,\n * different embedding model, schema changes).\n */\nexport class ManifestManager {\n private manifestPath: string;\n private indexPath: string;\n \n /**\n * Promise-based lock to prevent race conditions during concurrent updates.\n * Ensures read-modify-write operations are atomic.\n */\n private updateLock = Promise.resolve();\n \n /**\n * Creates a new ManifestManager\n * @param indexPath - Path to the index directory (same as VectorDB path)\n */\n constructor(indexPath: string) {\n this.indexPath = indexPath;\n this.manifestPath = path.join(indexPath, MANIFEST_FILE);\n }\n \n /**\n * Loads the manifest from disk.\n * Returns null if:\n * - Manifest doesn't exist (first run)\n * - Manifest is corrupt\n * - Format version is incompatible (triggers full reindex)\n * \n * @returns Loaded manifest or null\n */\n async load(): Promise<IndexManifest | null> {\n try {\n const content = await fs.readFile(this.manifestPath, 'utf-8');\n const manifest = JSON.parse(content) as IndexManifest;\n \n // VERSION CHECK: Invalidate if format version doesn't match\n if (manifest.formatVersion !== INDEX_FORMAT_VERSION) {\n console.error(\n `[Lien] Index format v${manifest.formatVersion} is incompatible with current v${INDEX_FORMAT_VERSION}`\n );\n console.error(`[Lien] Full reindex required after Lien upgrade`);\n \n // Clear old manifest and return null (triggers full reindex)\n await this.clear();\n return null;\n }\n \n return manifest;\n } catch (error) {\n // File doesn't exist or is invalid - return null for first run\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return null;\n }\n \n // Corrupt manifest - log warning and return null\n console.error(`[Lien] Warning: Failed to load manifest: ${error}`);\n return null;\n }\n }\n \n /**\n * Saves the manifest to disk.\n * Always saves with current format and package versions.\n * \n * @param manifest - Manifest to save\n */\n async save(manifest: IndexManifest): Promise<void> {\n try {\n // Ensure index directory exists\n await fs.mkdir(this.indexPath, { recursive: true });\n \n // Always save with current versions\n const manifestToSave: IndexManifest = {\n ...manifest,\n formatVersion: INDEX_FORMAT_VERSION,\n lienVersion: getPackageVersion(),\n lastIndexed: Date.now(),\n };\n \n const content = JSON.stringify(manifestToSave, null, 2);\n await fs.writeFile(this.manifestPath, content, 'utf-8');\n } catch (error) {\n // Don't throw - manifest is best-effort\n console.error(`[Lien] Warning: Failed to save manifest: ${error}`);\n }\n }\n \n /**\n * Adds or updates a file entry in the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param filepath - Path to the file\n * @param entry - File entry metadata\n */\n async updateFile(filepath: string, entry: FileEntry): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n manifest.files[filepath] = entry;\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update manifest for ${filepath}: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Removes a file entry from the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * Note: If the manifest doesn't exist, this is a no-op (not an error).\n * This can happen legitimately after clearing the index or on fresh installs.\n * \n * @param filepath - Path to the file to remove\n */\n async removeFile(filepath: string): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load();\n if (!manifest) {\n // No manifest exists - nothing to remove from (expected in some scenarios)\n return;\n }\n \n delete manifest.files[filepath];\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to remove manifest entry for ${filepath}: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Updates multiple files at once (more efficient than individual updates).\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param entries - Array of file entries to update\n */\n async updateFiles(entries: FileEntry[]): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n \n for (const entry of entries) {\n manifest.files[entry.filepath] = entry;\n }\n \n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update manifest for ${entries.length} files: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Updates the git state in the manifest.\n * Protected by lock to prevent race conditions during concurrent updates.\n * \n * @param gitState - Current git state\n */\n async updateGitState(gitState: GitState): Promise<void> {\n // Chain this operation to the lock to ensure atomicity\n this.updateLock = this.updateLock.then(async () => {\n const manifest = await this.load() || this.createEmpty();\n \n manifest.gitState = gitState;\n await this.save(manifest);\n }).catch(error => {\n console.error(`[Lien] Failed to update git state in manifest: ${error}`);\n // Return to reset lock - don't let errors block future operations\n return undefined;\n });\n \n // Wait for this operation to complete\n await this.updateLock;\n }\n \n /**\n * Gets the list of files currently in the manifest\n * \n * @returns Array of filepaths\n */\n async getIndexedFiles(): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) return [];\n \n return Object.keys(manifest.files);\n }\n \n /**\n * Detects which files have changed based on mtime comparison\n * \n * @param currentFiles - Map of current files with their mtimes\n * @returns Array of filepaths that have changed\n */\n async getChangedFiles(currentFiles: Map<string, number>): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) {\n // No manifest = all files are \"changed\" (need full index)\n return Array.from(currentFiles.keys());\n }\n \n const changedFiles: string[] = [];\n \n for (const [filepath, mtime] of currentFiles) {\n const entry = manifest.files[filepath];\n \n if (!entry) {\n // New file\n changedFiles.push(filepath);\n } else if (entry.lastModified < mtime) {\n // File modified since last index\n changedFiles.push(filepath);\n }\n }\n \n return changedFiles;\n }\n \n /**\n * Gets files that are in the manifest but not in the current file list\n * (i.e., deleted files)\n * \n * @param currentFiles - Set of current file paths\n * @returns Array of deleted file paths\n */\n async getDeletedFiles(currentFiles: Set<string>): Promise<string[]> {\n const manifest = await this.load();\n if (!manifest) return [];\n \n const deletedFiles: string[] = [];\n \n for (const filepath of Object.keys(manifest.files)) {\n if (!currentFiles.has(filepath)) {\n deletedFiles.push(filepath);\n }\n }\n \n return deletedFiles;\n }\n \n /**\n * Clears the manifest file\n */\n async clear(): Promise<void> {\n try {\n await fs.unlink(this.manifestPath);\n } catch (error) {\n // Ignore error if file doesn't exist\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n console.error(`[Lien] Warning: Failed to clear manifest: ${error}`);\n }\n }\n }\n \n /**\n * Creates an empty manifest with current version information\n * \n * @returns Empty manifest\n */\n private createEmpty(): IndexManifest {\n return {\n formatVersion: INDEX_FORMAT_VERSION,\n lienVersion: getPackageVersion(),\n lastIndexed: Date.now(),\n files: {},\n };\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport {\n isGitRepo,\n getCurrentBranch,\n getCurrentCommit,\n getChangedFiles,\n getChangedFilesBetweenCommits,\n} from './utils.js';\n\nexport interface GitState {\n branch: string;\n commit: string;\n timestamp: number;\n}\n\n/**\n * Tracks git state (branch and commit) and detects changes.\n * Persists state to disk to survive server restarts.\n */\nexport class GitStateTracker {\n private stateFile: string;\n private rootDir: string;\n private currentState: GitState | null = null;\n \n constructor(rootDir: string, indexPath: string) {\n this.rootDir = rootDir;\n this.stateFile = path.join(indexPath, '.git-state.json');\n }\n \n /**\n * Loads the last known git state from disk.\n * Returns null if no state file exists (first run).\n */\n private async loadState(): Promise<GitState | null> {\n try {\n const content = await fs.readFile(this.stateFile, 'utf-8');\n return JSON.parse(content);\n } catch {\n // File doesn't exist or is invalid - this is fine for first run\n return null;\n }\n }\n \n /**\n * Saves the current git state to disk.\n */\n private async saveState(state: GitState): Promise<void> {\n try {\n const content = JSON.stringify(state, null, 2);\n await fs.writeFile(this.stateFile, content, 'utf-8');\n } catch (error) {\n // Log but don't throw - state persistence is best-effort\n console.error(`[Lien] Warning: Failed to save git state: ${error}`);\n }\n }\n \n /**\n * Gets the current git state from the repository.\n * \n * @returns Current git state\n * @throws Error if git commands fail\n */\n private async getCurrentGitState(): Promise<GitState> {\n const branch = await getCurrentBranch(this.rootDir);\n const commit = await getCurrentCommit(this.rootDir);\n \n return {\n branch,\n commit,\n timestamp: Date.now(),\n };\n }\n \n /**\n * Initializes the tracker by loading saved state and checking current state.\n * Should be called once when MCP server starts.\n * \n * @returns Array of changed files if state changed, null if no changes or first run\n */\n async initialize(): Promise<string[] | null> {\n // Check if this is a git repo\n const isRepo = await isGitRepo(this.rootDir);\n if (!isRepo) {\n return null;\n }\n \n try {\n // Get current state\n this.currentState = await this.getCurrentGitState();\n \n // Load previous state\n const previousState = await this.loadState();\n \n if (!previousState) {\n // First run - save current state\n await this.saveState(this.currentState);\n return null;\n }\n \n // Check if state changed\n const branchChanged = previousState.branch !== this.currentState.branch;\n const commitChanged = previousState.commit !== this.currentState.commit;\n \n if (!branchChanged && !commitChanged) {\n // No changes\n return null;\n }\n \n // State changed - get list of changed files\n let changedFiles: string[] = [];\n \n if (branchChanged) {\n // Branch changed - compare current branch with previous branch\n try {\n changedFiles = await getChangedFiles(\n this.rootDir,\n previousState.branch,\n this.currentState.branch\n );\n } catch (error) {\n // If branches diverged too much or don't exist, fall back to commit diff\n console.error(`[Lien] Branch diff failed, using commit diff: ${error}`);\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n previousState.commit,\n this.currentState.commit\n );\n }\n } else if (commitChanged) {\n // Same branch, different commit\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n previousState.commit,\n this.currentState.commit\n );\n }\n \n // Save new state\n await this.saveState(this.currentState);\n \n return changedFiles;\n } catch (error) {\n console.error(`[Lien] Failed to initialize git tracker: ${error}`);\n return null;\n }\n }\n \n /**\n * Checks for git state changes since last check.\n * This is called periodically by the MCP server.\n * \n * @returns Array of changed files if state changed, null if no changes\n */\n async detectChanges(): Promise<string[] | null> {\n // Check if this is a git repo\n const isRepo = await isGitRepo(this.rootDir);\n if (!isRepo) {\n return null;\n }\n \n try {\n // Get current state\n const newState = await this.getCurrentGitState();\n \n // If we don't have a previous state, just save current and return\n if (!this.currentState) {\n this.currentState = newState;\n await this.saveState(newState);\n return null;\n }\n \n // Check if state changed\n const branchChanged = this.currentState.branch !== newState.branch;\n const commitChanged = this.currentState.commit !== newState.commit;\n \n if (!branchChanged && !commitChanged) {\n // No changes\n return null;\n }\n \n // State changed - get list of changed files\n let changedFiles: string[] = [];\n \n if (branchChanged) {\n // Branch changed\n try {\n changedFiles = await getChangedFiles(\n this.rootDir,\n this.currentState.branch,\n newState.branch\n );\n } catch (error) {\n // Fall back to commit diff\n console.error(`[Lien] Branch diff failed, using commit diff: ${error}`);\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n this.currentState.commit,\n newState.commit\n );\n }\n } else if (commitChanged) {\n // Same branch, different commit\n changedFiles = await getChangedFilesBetweenCommits(\n this.rootDir,\n this.currentState.commit,\n newState.commit\n );\n }\n \n // Update current state\n this.currentState = newState;\n await this.saveState(newState);\n \n return changedFiles;\n } catch (error) {\n console.error(`[Lien] Failed to detect git changes: ${error}`);\n return null;\n }\n }\n \n /**\n * Gets the current git state.\n * Useful for status display.\n */\n getState(): GitState | null {\n return this.currentState;\n }\n \n /**\n * Manually updates the saved state.\n * Useful after manual reindexing to sync state.\n */\n async updateState(): Promise<void> {\n try {\n this.currentState = await this.getCurrentGitState();\n await this.saveState(this.currentState);\n } catch (error) {\n console.error(`[Lien] Failed to update git state: ${error}`);\n }\n }\n}\n\n","/**\n * Result type for explicit error handling.\n * \n * Provides a type-safe alternative to throwing exceptions, making error\n * handling explicit in function signatures.\n * \n * @example\n * ```typescript\n * function divide(a: number, b: number): Result<number, string> {\n * if (b === 0) {\n * return Err('Division by zero');\n * }\n * return Ok(a / b);\n * }\n * \n * const result = divide(10, 2);\n * if (isOk(result)) {\n * console.log(result.value); // 5\n * } else {\n * console.error(result.error);\n * }\n * ```\n */\n\n/**\n * Result type representing either success (Ok) or failure (Err)\n */\nexport type Result<T, E = Error> = \n | { ok: true; value: T }\n | { ok: false; error: E };\n\n/**\n * Creates a successful Result containing a value\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/**\n * Creates a failed Result containing an error\n */\nexport function Err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n\n/**\n * Type guard to check if a Result is Ok\n */\nexport function isOk<T, E>(result: Result<T, E>): result is { ok: true; value: T } {\n return result.ok;\n}\n\n/**\n * Type guard to check if a Result is Err\n */\nexport function isErr<T, E>(result: Result<T, E>): result is { ok: false; error: E } {\n return !result.ok;\n}\n\n/**\n * Unwraps a Result, throwing if it's an error\n * @throws {E} The error if Result is Err\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n if (isOk(result)) {\n return result.value;\n }\n throw result.error;\n}\n\n/**\n * Unwraps a Result or returns a default value if it's an error\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n if (isOk(result)) {\n return result.value;\n }\n return defaultValue;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { chunkFile } from './chunker.js';\nimport { EmbeddingService } from '../embeddings/types.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { LienConfig, LegacyLienConfig, isModernConfig, isLegacyConfig } from '../config/schema.js';\nimport { ManifestManager } from './manifest.js';\nimport { EMBEDDING_MICRO_BATCH_SIZE } from '../constants.js';\nimport { CodeChunk } from './types.js';\nimport { Result, Ok, Err, isOk } from '../utils/result.js';\n\n/**\n * Normalize a file path to a consistent relative format.\n * This ensures paths from different sources (git diff, scanner, etc.)\n * are stored and queried consistently in the index.\n * \n * @param filepath - Absolute or relative file path\n * @param rootDir - Workspace root directory (defaults to cwd)\n * @returns Relative path from rootDir\n */\nexport function normalizeToRelativePath(filepath: string, rootDir?: string): string {\n // Normalize root and strip trailing slash to ensure consistent comparison\n const root = (rootDir || process.cwd()).replace(/\\\\/g, '/').replace(/\\/$/, '');\n const normalized = filepath.replace(/\\\\/g, '/');\n \n // If already relative, return as-is\n if (!path.isAbsolute(filepath)) {\n return normalized;\n }\n \n // Convert absolute to relative\n if (normalized.startsWith(root + '/')) {\n return normalized.slice(root.length + 1);\n }\n if (normalized.startsWith(root)) {\n return normalized.slice(root.length);\n }\n \n // Fallback: use path.relative\n return path.relative(root, filepath).replace(/\\\\/g, '/');\n}\n\nexport interface IncrementalIndexOptions {\n verbose?: boolean;\n}\n\n/**\n * Result of processing a file's content into chunks and embeddings.\n */\ninterface ProcessFileResult {\n chunkCount: number;\n vectors: Float32Array[];\n chunks: CodeChunk[];\n texts: string[];\n}\n\n/**\n * Result of processing a single file for incremental indexing.\n */\ninterface FileProcessResult {\n filepath: string;\n result: ProcessFileResult | null; // null for empty files\n mtime: number;\n}\n\n/**\n * Shared helper that processes file content into chunks and embeddings.\n * This is the core logic shared between indexSingleFile and indexMultipleFiles.\n * \n * Returns null for empty files (0 chunks), which callers should handle appropriately.\n * \n * @param filepath - Path to the file being processed\n * @param content - File content\n * @param embeddings - Embeddings service\n * @param config - Lien configuration\n * @param verbose - Whether to log verbose output\n * @returns ProcessFileResult for non-empty files, null for empty files\n */\nasync function processFileContent(\n filepath: string,\n content: string,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n verbose: boolean\n): Promise<ProcessFileResult | null> {\n // Get chunk settings (support both v0.3.0 and legacy v0.2.0 configs)\n const chunkSize = isModernConfig(config)\n ? config.core.chunkSize\n : (isLegacyConfig(config) ? config.indexing.chunkSize : 75);\n const chunkOverlap = isModernConfig(config)\n ? config.core.chunkOverlap\n : (isLegacyConfig(config) ? config.indexing.chunkOverlap : 10);\n const useAST = isModernConfig(config)\n ? config.chunking.useAST\n : true;\n const astFallback = isModernConfig(config)\n ? config.chunking.astFallback\n : 'line-based';\n \n // Chunk the file\n const chunks = chunkFile(filepath, content, {\n chunkSize,\n chunkOverlap,\n useAST,\n astFallback,\n });\n \n if (chunks.length === 0) {\n // Empty file - return null so caller can handle appropriately\n if (verbose) {\n console.error(`[Lien] Empty file: ${filepath}`);\n }\n return null;\n }\n \n // Generate embeddings for all chunks\n // Use micro-batching to prevent event loop blocking\n const texts = chunks.map(c => c.content);\n const vectors: Float32Array[] = [];\n \n for (let j = 0; j < texts.length; j += EMBEDDING_MICRO_BATCH_SIZE) {\n const microBatch = texts.slice(j, Math.min(j + EMBEDDING_MICRO_BATCH_SIZE, texts.length));\n const microResults = await embeddings.embedBatch(microBatch);\n vectors.push(...microResults);\n \n // Yield to event loop for responsiveness\n if (texts.length > EMBEDDING_MICRO_BATCH_SIZE) {\n await new Promise(resolve => setImmediate(resolve));\n }\n }\n \n return {\n chunkCount: chunks.length,\n vectors,\n chunks,\n texts,\n };\n}\n\n/**\n * Indexes a single file incrementally by updating its chunks in the vector database.\n * This is the core function for incremental reindexing - it handles file changes,\n * deletions, and additions.\n * \n * @param filepath - Absolute path to the file to index\n * @param vectorDB - Initialized VectorDB instance\n * @param embeddings - Initialized embeddings service\n * @param config - Lien configuration\n * @param options - Optional settings\n */\nexport async function indexSingleFile(\n filepath: string,\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IncrementalIndexOptions = {}\n): Promise<void> {\n const { verbose } = options;\n \n // Normalize to relative path for consistent storage and queries\n // This ensures paths from git diff (absolute) match paths from scanner (relative)\n const normalizedPath = normalizeToRelativePath(filepath);\n \n try {\n // Check if file exists (use original filepath for filesystem operations)\n try {\n await fs.access(filepath);\n } catch {\n // File doesn't exist - delete from index and manifest using normalized path\n if (verbose) {\n console.error(`[Lien] File deleted: ${normalizedPath}`);\n }\n await vectorDB.deleteByFile(normalizedPath);\n \n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(normalizedPath);\n return;\n }\n \n // Read file content\n const content = await fs.readFile(filepath, 'utf-8');\n \n // Process file content (chunking + embeddings) - use normalized path for storage\n const result = await processFileContent(normalizedPath, content, embeddings, config, verbose || false);\n \n // Get actual file mtime for manifest\n const stats = await fs.stat(filepath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n \n if (result === null) {\n // Empty file - remove from vector DB but keep in manifest with chunkCount: 0\n await vectorDB.deleteByFile(normalizedPath);\n await manifest.updateFile(normalizedPath, {\n filepath: normalizedPath,\n lastModified: stats.mtimeMs,\n chunkCount: 0,\n });\n return;\n }\n \n // Non-empty file - update in database (atomic: delete old + insert new)\n await vectorDB.updateFile(\n normalizedPath,\n result.vectors,\n result.chunks.map(c => c.metadata),\n result.texts\n );\n \n // Update manifest after successful indexing\n await manifest.updateFile(normalizedPath, {\n filepath: normalizedPath,\n lastModified: stats.mtimeMs,\n chunkCount: result.chunkCount,\n });\n \n if (verbose) {\n console.error(`[Lien] ✓ Updated ${normalizedPath} (${result.chunkCount} chunks)`);\n }\n } catch (error) {\n // Log error but don't throw - we want to continue with other files\n console.error(`[Lien] ⚠️ Failed to index ${normalizedPath}: ${error}`);\n }\n}\n\n/**\n * Process a single file, returning a Result type.\n * This helper makes error handling explicit and testable.\n * \n * @param filepath - Original filepath (may be absolute)\n * @param normalizedPath - Normalized relative path for storage\n */\nasync function processSingleFileForIndexing(\n filepath: string,\n normalizedPath: string,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n verbose: boolean\n): Promise<Result<FileProcessResult, string>> {\n try {\n // Read file stats and content using original path (for filesystem access)\n const stats = await fs.stat(filepath);\n const content = await fs.readFile(filepath, 'utf-8');\n \n // Process content using normalized path (for storage)\n const result = await processFileContent(normalizedPath, content, embeddings, config, verbose);\n \n return Ok({\n filepath: normalizedPath, // Store normalized path\n result,\n mtime: stats.mtimeMs,\n });\n } catch (error) {\n return Err(`Failed to process ${normalizedPath}: ${error}`);\n }\n}\n\n/**\n * Indexes multiple files incrementally.\n * Processes files sequentially for simplicity and reliability.\n * \n * Uses Result type for explicit error handling, making it easier to test\n * and reason about failure modes.\n * \n * Note: This function counts both successfully indexed files AND successfully\n * handled deletions (files that don't exist but were removed from the index).\n * \n * @param filepaths - Array of absolute file paths to index\n * @param vectorDB - Initialized VectorDB instance\n * @param embeddings - Initialized embeddings service\n * @param config - Lien configuration\n * @param options - Optional settings\n * @returns Number of successfully processed files (indexed or deleted)\n */\nexport async function indexMultipleFiles(\n filepaths: string[],\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IncrementalIndexOptions = {}\n): Promise<number> {\n const { verbose } = options;\n let processedCount = 0;\n \n // Batch manifest updates for performance\n const manifestEntries: Array<{ filepath: string; chunkCount: number; mtime: number }> = [];\n \n // Process each file sequentially (simple and reliable)\n for (const filepath of filepaths) {\n // Normalize to relative path for consistent storage and queries\n // This ensures paths from git diff (absolute) match paths from scanner (relative)\n const normalizedPath = normalizeToRelativePath(filepath);\n \n const result = await processSingleFileForIndexing(filepath, normalizedPath, embeddings, config, verbose || false);\n \n if (isOk(result)) {\n const { filepath: storedPath, result: processResult, mtime } = result.value;\n \n if (processResult === null) {\n // Empty file - remove from vector DB but keep in manifest with chunkCount: 0\n try {\n await vectorDB.deleteByFile(storedPath);\n } catch (error) {\n // Ignore errors if file wasn't in index\n }\n \n // Update manifest immediately for empty files (not batched)\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFile(storedPath, {\n filepath: storedPath,\n lastModified: mtime,\n chunkCount: 0,\n });\n \n processedCount++;\n continue;\n }\n \n // Non-empty file - delete old chunks if they exist\n try {\n await vectorDB.deleteByFile(storedPath);\n } catch (error) {\n // Ignore - file might not be in index yet\n }\n \n // Insert new chunks\n await vectorDB.insertBatch(\n processResult.vectors,\n processResult.chunks.map(c => c.metadata),\n processResult.texts\n );\n \n // Queue manifest update (batch at end)\n manifestEntries.push({\n filepath: storedPath,\n chunkCount: processResult.chunkCount,\n mtime,\n });\n \n if (verbose) {\n console.error(`[Lien] ✓ Updated ${storedPath} (${processResult.chunkCount} chunks)`);\n }\n \n processedCount++;\n } else {\n // File doesn't exist or couldn't be read - handle deletion\n if (verbose) {\n console.error(`[Lien] ${result.error}`);\n }\n \n try {\n await vectorDB.deleteByFile(normalizedPath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(normalizedPath);\n } catch (error) {\n // Ignore errors if file wasn't in index\n if (verbose) {\n console.error(`[Lien] Note: ${normalizedPath} not in index`);\n }\n }\n \n // Count as processed regardless of deletion success/failure\n processedCount++;\n }\n }\n \n // Batch update manifest at the end (much faster than updating after each file)\n if (manifestEntries.length > 0) {\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFiles(\n manifestEntries.map(entry => ({\n filepath: entry.filepath,\n lastModified: entry.mtime, // Use actual file mtime for accurate change detection\n chunkCount: entry.chunkCount,\n }))\n );\n }\n \n return processedCount;\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { ManifestManager, IndexManifest } from './manifest.js';\nimport { scanCodebase, scanCodebaseWithFrameworks } from './scanner.js';\nimport { LienConfig, LegacyLienConfig, isModernConfig, isLegacyConfig } from '../config/schema.js';\nimport { GitStateTracker } from '../git/tracker.js';\nimport { isGitAvailable, isGitRepo, getChangedFiles } from '../git/utils.js';\nimport { normalizeToRelativePath } from './incremental.js';\n\n/**\n * Result of change detection, categorized by type of change\n */\nexport interface ChangeDetectionResult {\n added: string[]; // New files not in previous index\n modified: string[]; // Existing files that have been modified\n deleted: string[]; // Files that were indexed but no longer exist\n reason: 'mtime' | 'full' | 'git-state-changed'; // How changes were detected\n}\n\n/**\n * Check if git state has changed (branch switch, new commits).\n */\nasync function hasGitStateChanged(\n rootDir: string,\n dbPath: string,\n savedGitState: IndexManifest['gitState']\n): Promise<{ changed: boolean; currentState?: ReturnType<GitStateTracker['getState']> }> {\n if (!savedGitState) return { changed: false };\n\n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n if (!gitAvailable || !isRepo) return { changed: false };\n\n const gitTracker = new GitStateTracker(rootDir, dbPath);\n await gitTracker.initialize();\n const currentState = gitTracker.getState();\n\n if (!currentState) return { changed: false };\n\n const changed = currentState.branch !== savedGitState.branch ||\n currentState.commit !== savedGitState.commit;\n\n return { changed, currentState };\n}\n\n/**\n * Categorize files from git diff into added, modified, deleted.\n */\nfunction categorizeChangedFiles(\n changedFilesPaths: string[],\n currentFileSet: Set<string>,\n normalizedManifestFiles: Set<string>,\n allFiles: string[]\n): { added: string[]; modified: string[]; deleted: string[] } {\n const changedFilesSet = new Set(changedFilesPaths);\n const added: string[] = [];\n const modified: string[] = [];\n const deleted: string[] = [];\n\n // Categorize files from git diff\n for (const filepath of changedFilesPaths) {\n if (currentFileSet.has(filepath)) {\n if (normalizedManifestFiles.has(filepath)) {\n modified.push(filepath);\n } else {\n added.push(filepath);\n }\n }\n }\n\n // Find truly new files (not in git diff, but not in old manifest)\n for (const filepath of allFiles) {\n if (!normalizedManifestFiles.has(filepath) && !changedFilesSet.has(filepath)) {\n added.push(filepath);\n }\n }\n\n // Find deleted files (in old manifest but not in current)\n for (const normalizedPath of normalizedManifestFiles) {\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n\n return { added, modified, deleted };\n}\n\n/**\n * Build normalized set of manifest file paths for comparison.\n */\nfunction normalizeManifestPaths(\n manifestFiles: IndexManifest['files'],\n rootDir: string\n): Set<string> {\n const normalized = new Set<string>();\n for (const filepath of Object.keys(manifestFiles)) {\n normalized.add(normalizeToRelativePath(filepath, rootDir));\n }\n return normalized;\n}\n\n/**\n * Detect changes using git diff between commits.\n */\nasync function detectGitBasedChanges(\n rootDir: string,\n savedManifest: IndexManifest,\n currentCommit: string,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const changedFilesAbsolute = await getChangedFiles(\n rootDir,\n savedManifest.gitState!.commit,\n currentCommit\n );\n const changedFilesPaths = changedFilesAbsolute.map(fp => normalizeToRelativePath(fp, rootDir));\n\n const allFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(allFiles);\n const normalizedManifestFiles = normalizeManifestPaths(savedManifest.files, rootDir);\n\n const { added, modified, deleted } = categorizeChangedFiles(\n changedFilesPaths,\n currentFileSet,\n normalizedManifestFiles,\n allFiles\n );\n\n return { added, modified, deleted, reason: 'git-state-changed' };\n}\n\n/**\n * Fall back to full reindex when git diff fails.\n */\nasync function fallbackToFullReindex(\n rootDir: string,\n savedManifest: IndexManifest,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const allFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(allFiles);\n\n const deleted: string[] = [];\n for (const filepath of Object.keys(savedManifest.files)) {\n const normalizedPath = normalizeToRelativePath(filepath, rootDir);\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n\n return { added: allFiles, modified: [], deleted, reason: 'git-state-changed' };\n}\n\n/**\n * Detects which files have changed since last indexing.\n * Uses git state detection to handle branch switches, then falls back to mtime.\n */\nexport async function detectChanges(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const manifest = new ManifestManager(vectorDB.dbPath);\n const savedManifest = await manifest.load();\n\n // No manifest = first run = full index\n if (!savedManifest) {\n const allFiles = await getAllFiles(rootDir, config);\n return { added: allFiles, modified: [], deleted: [], reason: 'full' };\n }\n\n // Check if git state has changed\n const gitCheck = await hasGitStateChanged(rootDir, vectorDB.dbPath, savedManifest.gitState);\n\n if (gitCheck.changed && gitCheck.currentState) {\n try {\n return await detectGitBasedChanges(rootDir, savedManifest, gitCheck.currentState.commit, config);\n } catch (error) {\n console.warn(`[Lien] Git diff failed, falling back to full reindex: ${error}`);\n return await fallbackToFullReindex(rootDir, savedManifest, config);\n }\n }\n\n // Use mtime-based detection for file-level changes\n return await mtimeBasedDetection(rootDir, savedManifest, config);\n}\n\n/**\n * Gets all files in the project based on configuration.\n * Always returns relative paths for consistent comparison with manifest and git diff.\n */\nasync function getAllFiles(\n rootDir: string,\n config: LienConfig | LegacyLienConfig\n): Promise<string[]> {\n let files: string[];\n \n if (isModernConfig(config) && config.frameworks.length > 0) {\n files = await scanCodebaseWithFrameworks(rootDir, config);\n } else if (isLegacyConfig(config)) {\n files = await scanCodebase({\n rootDir,\n includePatterns: config.indexing.include,\n excludePatterns: config.indexing.exclude,\n });\n } else {\n files = await scanCodebase({\n rootDir,\n includePatterns: [],\n excludePatterns: [],\n });\n }\n \n // Normalize all paths to relative for consistent comparison\n return files.map(fp => normalizeToRelativePath(fp, rootDir));\n}\n\n/**\n * Detects changes by comparing file modification times\n */\nasync function mtimeBasedDetection(\n rootDir: string,\n savedManifest: IndexManifest,\n config: LienConfig | LegacyLienConfig\n): Promise<ChangeDetectionResult> {\n const added: string[] = [];\n const modified: string[] = [];\n const deleted: string[] = [];\n \n // Get all current files (already normalized to relative paths by getAllFiles)\n const currentFiles = await getAllFiles(rootDir, config);\n const currentFileSet = new Set(currentFiles);\n \n // Build a normalized map of manifest files for comparison\n // This handles cases where manifest has absolute paths (from tests or legacy data)\n const normalizedManifestFiles = new Map<string, typeof savedManifest.files[string]>();\n for (const [filepath, entry] of Object.entries(savedManifest.files)) {\n const normalizedPath = normalizeToRelativePath(filepath, rootDir);\n normalizedManifestFiles.set(normalizedPath, entry);\n }\n \n // Get mtimes for all current files\n // Note: need to construct absolute path for fs.stat since currentFiles are relative\n const fileStats = new Map<string, number>();\n \n for (const filepath of currentFiles) {\n try {\n // Construct absolute path for filesystem access (use path.join for cross-platform)\n const absolutePath = path.isAbsolute(filepath) ? filepath : path.join(rootDir, filepath);\n const stats = await fs.stat(absolutePath);\n fileStats.set(filepath, stats.mtimeMs);\n } catch {\n // Ignore files we can't stat\n continue;\n }\n }\n \n // Check for new and modified files\n for (const [filepath, mtime] of fileStats) {\n const entry = normalizedManifestFiles.get(filepath);\n \n if (!entry) {\n // New file\n added.push(filepath);\n } else if (entry.lastModified < mtime) {\n // File modified since last index\n modified.push(filepath);\n }\n }\n \n // Check for deleted files (use normalized manifest paths)\n for (const normalizedPath of normalizedManifestFiles.keys()) {\n if (!currentFileSet.has(normalizedPath)) {\n deleted.push(normalizedPath);\n }\n }\n \n return {\n added,\n modified,\n deleted,\n reason: 'mtime',\n };\n}\n\n","/**\n * Witty loading messages to keep users entertained during long operations.\n * Inspired by tools like npm, yarn, and other personality-driven CLIs.\n */\n\nconst INDEXING_MESSAGES = [\n 'Teaching AI to read your spaghetti code...',\n 'Convincing the LLM that your variable names make sense...',\n 'Indexing your TODO comments (so many TODOs)...',\n 'Building semantic links faster than you can say \"grep\"...',\n 'Making your codebase searchable (the good, the bad, and the ugly)...',\n 'Chunking code like a boss...',\n \"Feeding your code to the neural network (it's hungry)...\",\n \"Creating embeddings (it's like compression, but fancier)...\",\n 'Teaching machines to understand your midnight commits...',\n 'Vectorizing your technical debt...',\n \"Indexing... because Ctrl+F wasn't cutting it anymore...\",\n 'Making semantic connections (unlike your last refactor)...',\n 'Processing files faster than your CI pipeline...',\n 'Embedding wisdom from your comments (all 3 of them)...',\n 'Analyzing code semantics (yes, even that one function)...',\n 'Building search index (now with 100% more AI)...',\n \"Crunching vectors like it's nobody's business...\",\n 'Linking code fragments across the spacetime continuum...',\n 'Teaching transformers about your coding style...',\n 'Preparing for semantic search domination...',\n 'Indexing your genius (and that hacky workaround from 2019)...',\n \"Making your codebase AI-readable (you're welcome, future you)...\",\n 'Converting code to math (engineers love this trick)...',\n \"Building the neural net's mental model of your app...\",\n 'Chunking files like a lumberjack, but for code...',\n];\n\nconst EMBEDDING_MESSAGES = [\n 'Generating embeddings (math is happening)...',\n 'Teaching transformers about your forEach loops...',\n 'Converting code to 384-dimensional space (wild, right?)...',\n 'Running the neural network (the Matrix, but for code)...',\n 'Creating semantic vectors (fancy word for AI magic)...',\n 'Embedding your code into hyperspace...',\n 'Teaching the model what \"clean code\" means in your codebase...',\n 'Generating vectors faster than you can say \"AI\"...',\n 'Making math from your methods...',\n 'Transforming code into numbers (the AI way)...',\n 'Processing with transformers.js (yes, it runs locally!)...',\n \"Embedding semantics (your code's hidden meaning)...\",\n 'Vectorizing variables (alliteration achieved)...',\n 'Teaching AI the difference between foo and bar...',\n 'Creating embeddings (384 dimensions of awesome)...',\n];\n\nconst MODEL_LOADING_MESSAGES = [\n 'Waking up the neural network...',\n 'Loading transformer model (patience, young padawan)...',\n 'Downloading AI brain (first run only, promise!)...',\n 'Initializing the semantic search engine...',\n 'Booting up the language model (coffee break recommended)...',\n 'Loading 100MB of pure AI goodness...',\n 'Preparing the transformer for action...',\n 'Model loading (this is why we run locally)...',\n 'Spinning up the embedding generator...',\n 'Getting the AI ready for your codebase...',\n];\n\nlet currentIndexingIndex = 0;\nlet currentEmbeddingIndex = 0;\nlet currentModelIndex = 0;\n\n/**\n * Get the next witty message for the indexing process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getIndexingMessage(): string {\n const message = INDEXING_MESSAGES[currentIndexingIndex % INDEXING_MESSAGES.length];\n currentIndexingIndex++;\n return message;\n}\n\n/**\n * Get the next witty message for the embedding generation process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getEmbeddingMessage(): string {\n const message = EMBEDDING_MESSAGES[currentEmbeddingIndex % EMBEDDING_MESSAGES.length];\n currentEmbeddingIndex++;\n return message;\n}\n\n/**\n * Get the next witty message for the model loading process.\n * Messages are returned sequentially in a round-robin fashion.\n */\nexport function getModelLoadingMessage(): string {\n const message = MODEL_LOADING_MESSAGES[currentModelIndex % MODEL_LOADING_MESSAGES.length];\n currentModelIndex++;\n return message;\n}\n\n/**\n * Reset all message counters (useful for testing)\n */\nexport function resetMessageCounters(): void {\n currentIndexingIndex = 0;\n currentEmbeddingIndex = 0;\n currentModelIndex = 0;\n}\n\n","import type { Ora } from 'ora';\nimport { getIndexingMessage } from '../utils/loading-messages.js';\n\n/**\n * Manages progress tracking and spinner updates during indexing.\n * \n * Handles:\n * - Periodic progress updates (files processed count)\n * - Message rotation (witty messages every 8 seconds)\n * - Clean separation from business logic\n * \n * @example\n * ```typescript\n * const tracker = new IndexingProgressTracker(1000, spinner);\n * tracker.start();\n * \n * // ... process files ...\n * tracker.incrementFiles();\n * \n * tracker.setMessage('Generating embeddings...');\n * tracker.stop();\n * ```\n */\nexport class IndexingProgressTracker {\n private processedFiles = 0;\n private totalFiles: number;\n private wittyMessage: string;\n private spinner: Ora;\n private updateInterval?: NodeJS.Timeout;\n \n // Configuration constants\n private static readonly SPINNER_UPDATE_INTERVAL_MS = 200; // How often to update spinner\n private static readonly MESSAGE_ROTATION_INTERVAL_MS = 8000; // How often to rotate message\n \n constructor(totalFiles: number, spinner: Ora) {\n this.totalFiles = totalFiles;\n this.spinner = spinner;\n this.wittyMessage = getIndexingMessage();\n }\n \n /**\n * Start the progress tracker.\n * Sets up periodic updates for spinner and message rotation.\n * \n * Safe to call multiple times - will not create duplicate intervals.\n */\n start(): void {\n // Prevent creating multiple intervals (resource leak)\n if (this.updateInterval) {\n return;\n }\n \n const MESSAGE_ROTATION_TICKS = Math.floor(\n IndexingProgressTracker.MESSAGE_ROTATION_INTERVAL_MS / \n IndexingProgressTracker.SPINNER_UPDATE_INTERVAL_MS\n );\n \n let spinnerTick = 0;\n this.updateInterval = setInterval(() => {\n // Rotate witty message periodically\n spinnerTick++;\n if (spinnerTick >= MESSAGE_ROTATION_TICKS) {\n this.wittyMessage = getIndexingMessage();\n spinnerTick = 0; // Reset counter to prevent unbounded growth\n }\n \n // Update spinner text with current progress\n this.spinner.text = `${this.processedFiles}/${this.totalFiles} files | ${this.wittyMessage}`;\n }, IndexingProgressTracker.SPINNER_UPDATE_INTERVAL_MS);\n }\n \n /**\n * Increment the count of processed files.\n * \n * Safe for async operations in Node.js's single-threaded event loop.\n * Note: Not thread-safe for true concurrent operations (e.g., worker threads).\n */\n incrementFiles(): void {\n this.processedFiles++;\n }\n \n /**\n * Set a custom message (e.g., for special operations like embedding generation).\n * The message will be displayed until the next automatic rotation.\n */\n setMessage(message: string): void {\n this.wittyMessage = message;\n }\n \n /**\n * Stop the progress tracker and clean up intervals.\n * Must be called when indexing completes or fails.\n */\n stop(): void {\n if (this.updateInterval) {\n clearInterval(this.updateInterval);\n this.updateInterval = undefined;\n }\n }\n \n /**\n * Get the current count of processed files.\n */\n getProcessedCount(): number {\n return this.processedFiles;\n }\n \n /**\n * Get the total number of files to process.\n */\n getTotalFiles(): number {\n return this.totalFiles;\n }\n \n /**\n * Get the current message being displayed.\n */\n getCurrentMessage(): string {\n return this.wittyMessage;\n }\n}\n\n","import fs from 'fs/promises';\nimport ora, { type Ora } from 'ora';\nimport chalk from 'chalk';\nimport pLimit from 'p-limit';\nimport { scanCodebase, scanCodebaseWithFrameworks } from './scanner.js';\nimport { chunkFile } from './chunker.js';\nimport { LocalEmbeddings } from '../embeddings/local.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { configService } from '../config/service.js';\nimport { CodeChunk } from './types.js';\nimport { writeVersionFile } from '../vectordb/version.js';\nimport { isLegacyConfig, isModernConfig, type LienConfig, type LegacyLienConfig } from '../config/schema.js';\nimport { ManifestManager } from './manifest.js';\nimport { detectChanges } from './change-detector.js';\nimport { indexMultipleFiles } from './incremental.js';\nimport { getIndexingMessage, getEmbeddingMessage, getModelLoadingMessage } from '../utils/loading-messages.js';\nimport { EMBEDDING_MICRO_BATCH_SIZE } from '../constants.js';\nimport { IndexingProgressTracker } from './progress-tracker.js';\nimport type { EmbeddingService } from '../embeddings/types.js';\n\nexport interface IndexingOptions {\n rootDir?: string;\n verbose?: boolean;\n force?: boolean; // Force full reindex, skip incremental\n}\n\ninterface ChunkWithContent {\n chunk: CodeChunk;\n content: string;\n}\n\n/** Extracted config values with defaults for indexing */\ninterface IndexingConfig {\n concurrency: number;\n embeddingBatchSize: number;\n chunkSize: number;\n chunkOverlap: number;\n useAST: boolean;\n astFallback: 'line-based' | 'error';\n}\n\n/** Extract indexing config values with defaults */\nfunction getIndexingConfig(config: LienConfig | LegacyLienConfig): IndexingConfig {\n if (isModernConfig(config)) {\n return {\n concurrency: config.core.concurrency,\n embeddingBatchSize: config.core.embeddingBatchSize,\n chunkSize: config.core.chunkSize,\n chunkOverlap: config.core.chunkOverlap,\n useAST: config.chunking.useAST,\n astFallback: config.chunking.astFallback,\n };\n }\n // Legacy defaults\n return {\n concurrency: 4,\n embeddingBatchSize: 50,\n chunkSize: 75,\n chunkOverlap: 10,\n useAST: true,\n astFallback: 'line-based',\n };\n}\n\n/** Scan files based on config type */\nasync function scanFilesToIndex(\n rootDir: string,\n config: LienConfig | LegacyLienConfig\n): Promise<string[]> {\n if (isModernConfig(config) && config.frameworks.length > 0) {\n return scanCodebaseWithFrameworks(rootDir, config);\n }\n if (isLegacyConfig(config)) {\n return scanCodebase({\n rootDir,\n includePatterns: config.indexing.include,\n excludePatterns: config.indexing.exclude,\n });\n }\n return scanCodebase({ rootDir, includePatterns: [], excludePatterns: [] });\n}\n\n/** Process embeddings in micro-batches to prevent event loop blocking */\nasync function processEmbeddingMicroBatches(\n texts: string[],\n embeddings: EmbeddingService\n): Promise<Float32Array[]> {\n const results: Float32Array[] = [];\n for (let j = 0; j < texts.length; j += EMBEDDING_MICRO_BATCH_SIZE) {\n const microBatch = texts.slice(j, Math.min(j + EMBEDDING_MICRO_BATCH_SIZE, texts.length));\n const microResults = await embeddings.embedBatch(microBatch);\n results.push(...microResults);\n await new Promise(resolve => setImmediate(resolve));\n }\n return results;\n}\n\n/**\n * Helper functions extracted from indexCodebase\n * These make the main function more readable and testable\n */\n\n/**\n * Update git state after indexing (if in a git repo).\n */\nasync function updateGitState(\n rootDir: string,\n vectorDB: VectorDB,\n manifest: ManifestManager\n): Promise<void> {\n const { isGitAvailable, isGitRepo } = await import('../git/utils.js');\n const { GitStateTracker } = await import('../git/tracker.js');\n \n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n \n if (!gitAvailable || !isRepo) {\n return;\n }\n \n const gitTracker = new GitStateTracker(rootDir, vectorDB.dbPath);\n await gitTracker.initialize();\n const gitState = gitTracker.getState();\n \n if (gitState) {\n await manifest.updateGitState(gitState);\n }\n}\n\n/**\n * Handle file deletions during incremental indexing.\n */\nasync function handleDeletions(\n deletedFiles: string[],\n vectorDB: VectorDB,\n manifest: ManifestManager,\n spinner: Ora\n): Promise<void> {\n if (deletedFiles.length === 0) {\n return;\n }\n \n spinner.start(`Removing ${deletedFiles.length} deleted files...`);\n let removedCount = 0;\n \n for (const filepath of deletedFiles) {\n try {\n await vectorDB.deleteByFile(filepath);\n await manifest.removeFile(filepath);\n removedCount++;\n } catch (err) {\n spinner.warn(\n `Failed to remove file \"${filepath}\": ${err instanceof Error ? err.message : String(err)}`\n );\n }\n }\n \n spinner.succeed(`Removed ${removedCount}/${deletedFiles.length} deleted files`);\n}\n\n/**\n * Handle file updates (additions and modifications) during incremental indexing.\n */\nasync function handleUpdates(\n addedFiles: string[],\n modifiedFiles: string[],\n vectorDB: VectorDB,\n embeddings: EmbeddingService,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<void> {\n const filesToIndex = [...addedFiles, ...modifiedFiles];\n \n if (filesToIndex.length === 0) {\n return;\n }\n \n spinner.start(`Reindexing ${filesToIndex.length} changed files...`);\n const count = await indexMultipleFiles(\n filesToIndex,\n vectorDB,\n embeddings,\n config,\n { verbose: options.verbose }\n );\n \n await writeVersionFile(vectorDB.dbPath);\n spinner.succeed(\n `Incremental reindex complete: ${count}/${filesToIndex.length} files indexed successfully`\n );\n}\n\n/**\n * Try incremental indexing if a manifest exists.\n * Returns true if incremental indexing completed, false if full index needed.\n */\nasync function tryIncrementalIndex(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<boolean> {\n spinner.text = 'Checking for changes...';\n const manifest = new ManifestManager(vectorDB.dbPath);\n const savedManifest = await manifest.load();\n \n if (!savedManifest) {\n return false; // No manifest, need full index\n }\n \n const changes = await detectChanges(rootDir, vectorDB, config);\n \n if (changes.reason === 'full') {\n spinner.text = 'Full reindex required...';\n return false;\n }\n \n const totalChanges = changes.added.length + changes.modified.length;\n const totalDeleted = changes.deleted.length;\n \n if (totalChanges === 0 && totalDeleted === 0) {\n spinner.succeed('No changes detected - index is up to date!');\n return true;\n }\n \n spinner.succeed(\n `Detected changes: ${totalChanges} files to index, ${totalDeleted} to remove (${changes.reason} detection)`\n );\n \n // Initialize embeddings for incremental update\n spinner.start(getModelLoadingMessage());\n const embeddings = new LocalEmbeddings();\n await embeddings.initialize();\n spinner.succeed('Embedding model loaded');\n \n // Process changes\n await handleDeletions(changes.deleted, vectorDB, manifest, spinner);\n await handleUpdates(changes.added, changes.modified, vectorDB, embeddings, config, options, spinner);\n \n // Update git state\n await updateGitState(rootDir, vectorDB, manifest);\n \n console.log(chalk.dim('\\nNext step: Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n return true;\n}\n\n/**\n * Perform a full index of the codebase.\n */\nasync function performFullIndex(\n rootDir: string,\n vectorDB: VectorDB,\n config: LienConfig | LegacyLienConfig,\n options: IndexingOptions,\n spinner: Ora\n): Promise<void> {\n // 0. Clear existing index (required for schema changes)\n spinner.text = 'Clearing existing index...';\n await vectorDB.clear();\n \n // 1. Scan for files\n spinner.text = 'Scanning codebase...';\n const files = await scanFilesToIndex(rootDir, config);\n \n if (files.length === 0) {\n spinner.fail('No files found to index');\n return;\n }\n \n spinner.text = `Found ${files.length} files`;\n \n // 2. Initialize embeddings model\n spinner.text = getModelLoadingMessage();\n const embeddings = new LocalEmbeddings();\n await embeddings.initialize();\n spinner.succeed('Embedding model loaded');\n \n // 3. Get config values and process files\n const indexConfig = getIndexingConfig(config);\n const vectorDBBatchSize = 100; // Smaller batch for UI responsiveness\n \n spinner.start(`Processing files with ${indexConfig.concurrency}x concurrency...`);\n \n const startTime = Date.now();\n let processedChunks = 0;\n \n // Accumulator for chunks across multiple files\n const chunkAccumulator: ChunkWithContent[] = [];\n const limit = pLimit(indexConfig.concurrency);\n \n // Track successfully indexed files for manifest\n const indexedFileEntries: Array<{ filepath: string; chunkCount: number; mtime: number }> = [];\n \n // Create progress tracker\n const progressTracker = new IndexingProgressTracker(files.length, spinner);\n progressTracker.start();\n \n try {\n // Mutex to prevent concurrent access to shared state (chunkAccumulator, indexedFileEntries)\n // This prevents race conditions when multiple concurrent tasks try to:\n // 1. Push to shared arrays\n // 2. Check accumulator length threshold\n // 3. Trigger processing\n let addChunksLock: Promise<void> | null = null;\n let processingQueue: Promise<void> | null = null;\n \n // Function to process accumulated chunks\n // Uses queue-based synchronization to prevent TOCTOU race conditions\n const processAccumulatedChunks = async (): Promise<void> => {\n // Chain onto existing processing promise to create a queue\n // This prevents the race condition where multiple tasks check processingQueue\n // simultaneously and both proceed to process\n if (processingQueue) {\n processingQueue = processingQueue.then(() => doProcessChunks());\n } else {\n processingQueue = doProcessChunks();\n }\n return processingQueue;\n };\n \n // The actual processing logic (separated for queue-based synchronization)\n const doProcessChunks = async (): Promise<void> => {\n if (chunkAccumulator.length === 0) return;\n \n const currentPromise = processingQueue;\n \n try {\n const toProcess = chunkAccumulator.splice(0, chunkAccumulator.length);\n \n // Process in batches for UI responsiveness\n for (let i = 0; i < toProcess.length; i += indexConfig.embeddingBatchSize) {\n const batch = toProcess.slice(i, Math.min(i + indexConfig.embeddingBatchSize, toProcess.length));\n const texts = batch.map(item => item.content);\n \n progressTracker.setMessage(getEmbeddingMessage());\n const embeddingVectors = await processEmbeddingMicroBatches(texts, embeddings);\n processedChunks += batch.length;\n \n progressTracker.setMessage(`Inserting ${batch.length} chunks into vector space...`);\n await vectorDB.insertBatch(embeddingVectors, batch.map(item => item.chunk.metadata), texts);\n await new Promise(resolve => setImmediate(resolve));\n }\n \n progressTracker.setMessage(getIndexingMessage());\n } finally {\n if (processingQueue === currentPromise) processingQueue = null;\n }\n };\n \n // Process files with concurrency limit\n const filePromises = files.map((file) =>\n limit(async () => {\n try {\n // Get file stats to capture actual modification time\n const stats = await fs.stat(file);\n const content = await fs.readFile(file, 'utf-8');\n \n const chunks = chunkFile(file, content, {\n chunkSize: indexConfig.chunkSize,\n chunkOverlap: indexConfig.chunkOverlap,\n useAST: indexConfig.useAST,\n astFallback: indexConfig.astFallback,\n });\n \n if (chunks.length === 0) {\n progressTracker.incrementFiles();\n return;\n }\n \n // Critical section: add chunks to shared state and check threshold\n // Must be protected with mutex to prevent race conditions\n {\n // Wait for any in-progress add operation\n if (addChunksLock) {\n await addChunksLock;\n }\n \n // Acquire lock\n let releaseAddLock!: () => void;\n addChunksLock = new Promise<void>(resolve => {\n releaseAddLock = resolve;\n });\n \n try {\n // Add chunks to accumulator\n for (const chunk of chunks) {\n chunkAccumulator.push({\n chunk,\n content: chunk.content,\n });\n }\n \n // Track this file for manifest with actual file mtime\n indexedFileEntries.push({\n filepath: file,\n chunkCount: chunks.length,\n mtime: stats.mtimeMs,\n });\n \n progressTracker.incrementFiles();\n \n // Process when batch is large enough (use smaller batch for responsiveness)\n // Check is done inside the mutex to prevent multiple tasks from triggering processing\n if (chunkAccumulator.length >= vectorDBBatchSize) {\n await processAccumulatedChunks();\n }\n } finally {\n // Release lock (always defined by Promise constructor)\n releaseAddLock();\n addChunksLock = null;\n }\n }\n } catch (error) {\n if (options.verbose) {\n console.error(chalk.yellow(`\\n⚠️ Skipping ${file}: ${error}`));\n }\n progressTracker.incrementFiles();\n }\n })\n );\n \n // Wait for all files to be processed\n await Promise.all(filePromises);\n \n // Process remaining chunks\n progressTracker.setMessage('Processing final chunks...');\n await processAccumulatedChunks();\n } finally {\n // Always stop the progress tracker to clean up the interval\n progressTracker.stop();\n }\n \n // Save manifest with all indexed files\n spinner.start('Saving index manifest...');\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.updateFiles(\n indexedFileEntries.map(entry => ({\n filepath: entry.filepath,\n // Use actual file mtime for accurate change detection\n lastModified: entry.mtime,\n chunkCount: entry.chunkCount,\n }))\n );\n \n // Save git state if in a git repo\n await updateGitState(rootDir, vectorDB, manifest);\n \n spinner.succeed('Manifest saved');\n \n // Write version file to mark successful completion\n await writeVersionFile(vectorDB.dbPath);\n \n const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);\n spinner.succeed(\n `Indexed ${progressTracker.getProcessedCount()} files (${processedChunks} chunks) in ${totalTime}s using ${indexConfig.concurrency}x concurrency`\n );\n \n console.log(chalk.dim('\\nNext step: Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n}\n\n/**\n * Index a codebase, creating vector embeddings for semantic search.\n * \n * Refactored to be more maintainable:\n * - Tries incremental indexing first (if not forced)\n * - Falls back to full indexing if needed\n * - Delegates to helper functions for specific tasks\n * \n * @param options - Indexing options\n */\nexport async function indexCodebase(options: IndexingOptions = {}): Promise<void> {\n const rootDir = options.rootDir ?? process.cwd();\n const spinner = ora('Starting indexing process...').start();\n \n try {\n // Load configuration\n spinner.text = 'Loading configuration...';\n const config = await configService.load(rootDir);\n \n // Initialize vector database\n spinner.text = 'Initializing vector database...';\n const vectorDB = new VectorDB(rootDir);\n await vectorDB.initialize();\n \n // Try incremental indexing first (unless forced)\n if (!options.force) {\n const completed = await tryIncrementalIndex(rootDir, vectorDB, config, options, spinner);\n if (completed) {\n return; // Incremental index completed\n }\n } else {\n spinner.text = 'Force flag enabled, performing full reindex...';\n }\n \n // Fall back to full index\n await performFullIndex(rootDir, vectorDB, config, options, spinner);\n \n } catch (error) {\n spinner.fail(`Indexing failed: ${error}`);\n throw error;\n }\n}\n\n","import { Command } from 'commander';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { initCommand } from './init.js';\nimport { statusCommand } from './status.js';\nimport { indexCommand } from './index-cmd.js';\nimport { serveCommand } from './serve.js';\nimport { complexityCommand } from './complexity.js';\n\n// Get version from package.json dynamically\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson;\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\nexport const program = new Command();\n\nprogram\n .name('lien')\n .description('Local semantic code search for AI assistants via MCP')\n .version(packageJson.version);\n\nprogram\n .command('init')\n .description('Initialize Lien in the current directory')\n .option('-u, --upgrade', 'Upgrade existing config with new options')\n .option('-y, --yes', 'Skip interactive prompts and use defaults')\n .option('-p, --path <path>', 'Path to initialize (defaults to current directory)')\n .action(initCommand);\n\nprogram\n .command('index')\n .description('Index the codebase for semantic search')\n .option('-f, --force', 'Force full reindex (skip incremental)')\n .option('-w, --watch', 'Watch for changes and re-index automatically')\n .option('-v, --verbose', 'Show detailed logging during indexing')\n .action(indexCommand);\n\nprogram\n .command('serve')\n .description('Start the MCP server for Cursor integration')\n .option('-p, --port <port>', 'Port number (for future use)', '7133')\n .option('--no-watch', 'Disable file watching for this session')\n .option('-w, --watch', '[DEPRECATED] File watching is now enabled by default')\n .option('-r, --root <path>', 'Root directory to serve (defaults to current directory)')\n .action(serveCommand);\n\nprogram\n .command('status')\n .description('Show indexing status and statistics')\n .action(statusCommand);\n\nprogram\n .command('complexity')\n .description('Analyze code complexity')\n .option('--files <paths...>', 'Specific files to analyze')\n .option('--format <type>', 'Output format: text, json, sarif', 'text')\n .option('--threshold <n>', 'Override both complexity thresholds (cyclomatic & cognitive)')\n .option('--cyclomatic-threshold <n>', 'Override cyclomatic complexity threshold only')\n .option('--cognitive-threshold <n>', 'Override cognitive complexity threshold only')\n .option('--fail-on <severity>', 'Exit 1 if violations: error, warning')\n .action(complexityCommand);\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport chalk from 'chalk';\nimport inquirer from 'inquirer';\nimport { defaultConfig, LienConfig, FrameworkInstance, FrameworkConfig } from '../config/schema.js';\nimport { showCompactBanner } from '../utils/banner.js';\nimport { MigrationManager } from '../config/migration-manager.js';\nimport { detectAllFrameworks } from '../frameworks/detector-service.js';\nimport { getFrameworkDetector } from '../frameworks/registry.js';\n\n// ES module equivalent of __dirname\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport interface InitOptions {\n upgrade?: boolean;\n yes?: boolean;\n path?: string;\n}\n\nexport async function initCommand(options: InitOptions = {}) {\n const rootDir = options.path || process.cwd();\n const configPath = path.join(rootDir, '.lien.config.json');\n \n try {\n // Check if config already exists\n let configExists = false;\n try {\n await fs.access(configPath);\n configExists = true;\n } catch {\n // File doesn't exist\n }\n \n // Handle upgrade scenario\n if (configExists && options.upgrade) {\n const migrationManager = new MigrationManager(rootDir);\n await migrationManager.upgradeInteractive();\n return;\n }\n \n // Warn if config exists and not upgrading\n if (configExists && !options.upgrade) {\n console.log(chalk.yellow('⚠️ .lien.config.json already exists'));\n console.log(chalk.dim('Run'), chalk.bold('lien init --upgrade'), chalk.dim('to merge new config options'));\n return;\n }\n \n // Create new config with framework detection\n if (!configExists) {\n await createNewConfig(rootDir, options);\n }\n } catch (error) {\n console.error(chalk.red('Error creating config file:'), error);\n process.exit(1);\n }\n}\n\nasync function createNewConfig(rootDir: string, options: InitOptions) {\n // Show banner for new initialization\n showCompactBanner();\n console.log(chalk.bold('Initializing Lien...\\n'));\n \n // 1. Run framework detection\n console.log(chalk.dim('🔍 Detecting frameworks in'), chalk.bold(rootDir));\n const detections = await detectAllFrameworks(rootDir);\n \n let frameworks: FrameworkInstance[] = [];\n \n if (detections.length === 0) {\n console.log(chalk.yellow('\\n⚠️ No frameworks detected'));\n \n if (!options.yes) {\n const { useGeneric } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'useGeneric',\n message: 'Create a generic config (index all supported file types)?',\n default: true,\n },\n ]);\n \n if (!useGeneric) {\n console.log(chalk.dim('Aborted.'));\n return;\n }\n }\n \n // Create generic framework\n frameworks.push({\n name: 'generic',\n path: '.',\n enabled: true,\n config: {\n include: ['**/*.{ts,tsx,js,jsx,py,php,go,rs,java,c,cpp,cs}'],\n exclude: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.git/**',\n '**/coverage/**',\n '**/.next/**',\n '**/.nuxt/**',\n '**/vendor/**',\n ],\n },\n });\n } else {\n // 2. Display detected frameworks\n console.log(chalk.green(`\\n✓ Found ${detections.length} framework(s):\\n`));\n \n for (const det of detections) {\n const pathDisplay = det.path === '.' ? 'root' : det.path;\n console.log(chalk.bold(` ${det.name}`), chalk.dim(`(${det.confidence} confidence)`));\n console.log(chalk.dim(` Location: ${pathDisplay}`));\n \n if (det.evidence.length > 0) {\n det.evidence.forEach((e) => {\n console.log(chalk.dim(` • ${e}`));\n });\n }\n console.log();\n }\n \n // 3. Interactive confirmation\n if (!options.yes) {\n const { confirm } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'confirm',\n message: 'Configure these frameworks?',\n default: true,\n },\n ]);\n \n if (!confirm) {\n console.log(chalk.dim('Aborted.'));\n return;\n }\n }\n \n // 4. Generate configs for each detected framework\n for (const det of detections) {\n const detector = getFrameworkDetector(det.name);\n if (!detector) {\n console.warn(chalk.yellow(`⚠️ No detector found for ${det.name}, skipping`));\n continue;\n }\n \n // Generate default config\n const frameworkConfig = await detector.generateConfig(rootDir, det.path);\n \n // Optional: Ask to customize (only in interactive mode)\n let shouldCustomize = false;\n if (!options.yes) {\n const { customize } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'customize',\n message: `Customize ${det.name} settings?`,\n default: false,\n },\n ]);\n shouldCustomize = customize;\n }\n \n let finalConfig = frameworkConfig;\n if (shouldCustomize) {\n const customized = await promptForCustomization(det.name, frameworkConfig);\n finalConfig = { ...frameworkConfig, ...customized };\n } else {\n const pathDisplay = det.path === '.' ? 'root' : det.path;\n console.log(chalk.dim(` → Using defaults for ${det.name} at ${pathDisplay}`));\n }\n \n frameworks.push({\n name: det.name,\n path: det.path,\n enabled: true,\n config: finalConfig,\n });\n }\n }\n \n // 5. Ask about Cursor rules installation\n if (!options.yes) {\n const { installCursorRules } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'installCursorRules',\n message: 'Install recommended Cursor rules?',\n default: true,\n },\n ]);\n \n if (installCursorRules) {\n try {\n const cursorRulesDir = path.join(rootDir, '.cursor');\n await fs.mkdir(cursorRulesDir, { recursive: true });\n \n // Find template - it's in the package root (same dir as package.json)\n // When compiled: everything bundles to dist/index.js, so __dirname is dist/\n // Go up one level from dist/ to reach package root\n const templatePath = path.join(__dirname, '../CURSOR_RULES_TEMPLATE.md');\n \n const rulesPath = path.join(cursorRulesDir, 'rules');\n let targetPath: string;\n let isDirectory = false;\n let isFile = false;\n\n try {\n const stats = await fs.stat(rulesPath);\n isDirectory = stats.isDirectory();\n isFile = stats.isFile();\n } catch {\n // Doesn't exist, that's fine\n }\n\n if (isDirectory) {\n // .cursor/rules is already a directory, create lien.mdc inside it\n targetPath = path.join(rulesPath, 'lien.mdc');\n await fs.copyFile(templatePath, targetPath);\n console.log(chalk.green('✓ Installed Cursor rules as .cursor/rules/lien.mdc'));\n } else if (isFile) {\n // .cursor/rules exists as a file - ask to convert to directory structure\n const { convertToDir } = await inquirer.prompt([\n {\n type: 'confirm',\n name: 'convertToDir',\n message: 'Existing .cursor/rules file found. Convert to directory and preserve your rules?',\n default: true,\n },\n ]);\n\n if (convertToDir) {\n // Convert file to directory structure\n // 1. Read existing rules\n const existingRules = await fs.readFile(rulesPath, 'utf-8');\n // 2. Delete the file\n await fs.unlink(rulesPath);\n // 3. Create rules as a directory\n await fs.mkdir(rulesPath);\n // 4. Save original rules as project.mdc\n await fs.writeFile(path.join(rulesPath, 'project.mdc'), existingRules);\n // 5. Add Lien rules as lien.mdc\n await fs.copyFile(templatePath, path.join(rulesPath, 'lien.mdc'));\n console.log(chalk.green('✓ Converted .cursor/rules to directory'));\n console.log(chalk.green(' - Your project rules: .cursor/rules/project.mdc'));\n console.log(chalk.green(' - Lien rules: .cursor/rules/lien.mdc'));\n } else {\n console.log(chalk.dim('Skipped Cursor rules installation (preserving existing file)'));\n }\n } else {\n // .cursor/rules doesn't exist, create it as a directory\n await fs.mkdir(rulesPath, { recursive: true });\n targetPath = path.join(rulesPath, 'lien.mdc');\n await fs.copyFile(templatePath, targetPath);\n console.log(chalk.green('✓ Installed Cursor rules as .cursor/rules/lien.mdc'));\n }\n } catch (error) {\n console.log(chalk.yellow('⚠️ Could not install Cursor rules'));\n console.log(chalk.dim(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));\n console.log(chalk.dim('You can manually copy CURSOR_RULES_TEMPLATE.md to .cursor/rules/lien.mdc'));\n }\n }\n }\n \n // 6. Build final config\n const config: LienConfig = {\n ...defaultConfig,\n frameworks,\n };\n \n // 7. Write config\n const configPath = path.join(rootDir, '.lien.config.json');\n await fs.writeFile(configPath, JSON.stringify(config, null, 2) + '\\n', 'utf-8');\n \n // 8. Show success message\n console.log(chalk.green('\\n✓ Created .lien.config.json'));\n console.log(chalk.green(`✓ Configured ${frameworks.length} framework(s)`));\n console.log(chalk.dim('\\nNext steps:'));\n console.log(chalk.dim(' 1. Run'), chalk.bold('lien index'), chalk.dim('to index your codebase'));\n console.log(chalk.dim(' 2. Run'), chalk.bold('lien serve'), chalk.dim('to start the MCP server'));\n console.log(chalk.dim(' 3. Configure Cursor to use the MCP server (see README.md)'));\n}\n\nasync function promptForCustomization(frameworkName: string, config: FrameworkConfig): Promise<Partial<FrameworkConfig>> {\n console.log(chalk.bold(`\\nCustomizing ${frameworkName} settings:`));\n \n const answers = await inquirer.prompt([\n {\n type: 'input',\n name: 'include',\n message: 'File patterns to include (comma-separated):',\n default: config.include.join(', '),\n filter: (input: string) => input.split(',').map(s => s.trim()),\n },\n {\n type: 'input',\n name: 'exclude',\n message: 'File patterns to exclude (comma-separated):',\n default: config.exclude.join(', '),\n filter: (input: string) => input.split(',').map(s => s.trim()),\n },\n ]);\n \n return {\n include: answers.include,\n exclude: answers.exclude,\n };\n}\n\n// Removed: upgradeConfig function is now handled by MigrationManager.upgradeInteractive()\n","import figlet from 'figlet';\nimport chalk from 'chalk';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\n\n// Get package.json dynamically\n// In development: src/utils/banner.ts -> ../../package.json\n// In production (bundled): dist/index.js -> ../package.json\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\n// Try production path first (dist -> package.json), then dev path\nlet packageJson;\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\n// Package info\nconst PACKAGE_NAME = packageJson.name;\nconst VERSION = packageJson.version;\n\n/**\n * Wrap text in a box with a footer line\n */\nfunction wrapInBox(text: string, footer: string, padding = 1): string {\n const lines = text.split('\\n').filter(line => line.trim().length > 0);\n \n // Use only the main content (logo) to determine box width\n const maxLength = Math.max(...lines.map(line => line.length));\n \n const horizontalBorder = '─'.repeat(maxLength + padding * 2);\n const top = `┌${horizontalBorder}┐`;\n const bottom = `└${horizontalBorder}┘`;\n const separator = `├${horizontalBorder}┤`;\n \n const paddedLines = lines.map(line => {\n const padRight = ' '.repeat(maxLength - line.length + padding);\n const padLeft = ' '.repeat(padding);\n return `│${padLeft}${line}${padRight}│`;\n });\n \n // Center the footer line\n const totalPad = maxLength - footer.length;\n const leftPad = Math.floor(totalPad / 2);\n const rightPad = totalPad - leftPad;\n const centeredFooter = ' '.repeat(leftPad) + footer + ' '.repeat(rightPad);\n \n const paddedFooter = `│${' '.repeat(padding)}${centeredFooter}${' '.repeat(padding)}│`;\n \n return [top, ...paddedLines, separator, paddedFooter, bottom].join('\\n');\n}\n\n/**\n * Display the gorgeous ANSI Shadow banner (uses stderr for MCP server)\n */\nexport function showBanner(): void {\n const banner = figlet.textSync('LIEN', {\n font: 'ANSI Shadow',\n horizontalLayout: 'fitted',\n verticalLayout: 'fitted',\n });\n\n const footer = `${PACKAGE_NAME} - v${VERSION}`;\n const boxedBanner = wrapInBox(banner.trim(), footer);\n console.error(chalk.cyan(boxedBanner));\n console.error(); // Empty line\n}\n\n/**\n * Display the gorgeous ANSI Shadow banner (uses stdout for CLI commands)\n */\nexport function showCompactBanner(): void {\n const banner = figlet.textSync('LIEN', {\n font: 'ANSI Shadow',\n horizontalLayout: 'fitted',\n verticalLayout: 'fitted',\n });\n\n const footer = `${PACKAGE_NAME} - v${VERSION}`;\n const boxedBanner = wrapInBox(banner.trim(), footer);\n console.log(chalk.cyan(boxedBanner));\n console.log(); // Empty line\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport chalk from 'chalk';\nimport { LienConfig, defaultConfig } from './schema.js';\nimport { needsMigration, migrateConfig, migrateConfigFile } from './migration.js';\nimport { deepMergeConfig, detectNewFields } from './merge.js';\nimport { CURRENT_CONFIG_VERSION } from '../constants.js';\n\n/**\n * Result of a migration operation\n */\nexport interface MigrationResult {\n migrated: boolean;\n backupPath?: string;\n config: LienConfig;\n}\n\n/**\n * Centralized migration orchestration service\n * \n * Handles all config migration scenarios:\n * - Auto-migration during config loading\n * - Interactive upgrade via CLI\n * - Migration status checking\n */\nexport class MigrationManager {\n constructor(private readonly rootDir: string = process.cwd()) {}\n \n /**\n * Get the config file path\n */\n private getConfigPath(): string {\n return path.join(this.rootDir, '.lien.config.json');\n }\n \n /**\n * Check if the current config needs migration\n */\n async needsMigration(): Promise<boolean> {\n try {\n const configPath = this.getConfigPath();\n const content = await fs.readFile(configPath, 'utf-8');\n const config = JSON.parse(content);\n return needsMigration(config);\n } catch (error) {\n // If config doesn't exist or can't be read, no migration needed\n return false;\n }\n }\n \n /**\n * Perform silent migration (for auto-migration during load)\n * Returns the migrated config without user interaction\n */\n async autoMigrate(): Promise<LienConfig> {\n const result = await migrateConfigFile(this.rootDir);\n \n if (result.migrated && result.backupPath) {\n const backupFilename = path.basename(result.backupPath);\n console.log(`✅ Migration complete! Backup saved as ${backupFilename}`);\n console.log('📝 Your config now uses the framework-based structure.');\n }\n \n return result.config;\n }\n \n /**\n * Perform interactive upgrade (for CLI upgrade command)\n * Provides detailed feedback and handles edge cases\n */\n async upgradeInteractive(): Promise<void> {\n const configPath = this.getConfigPath();\n \n try {\n // 1. Read existing config\n const existingContent = await fs.readFile(configPath, 'utf-8');\n const existingConfig = JSON.parse(existingContent);\n \n // 2. Check if any changes are needed\n const migrationNeeded = needsMigration(existingConfig);\n const newFields = migrationNeeded ? [] : detectNewFields(existingConfig, defaultConfig);\n const hasChanges = migrationNeeded || newFields.length > 0;\n \n if (!hasChanges) {\n console.log(chalk.green('✓ Config is already up to date'));\n console.log(chalk.dim('No changes needed'));\n return;\n }\n \n // 3. Backup existing config (only if changes are needed)\n const backupPath = `${configPath}.backup`;\n await fs.copyFile(configPath, backupPath);\n \n // 4. Perform upgrade\n let upgradedConfig: LienConfig;\n let migrated = false;\n \n if (migrationNeeded) {\n console.log(chalk.blue(`🔄 Migrating config from v0.2.0 to v${CURRENT_CONFIG_VERSION}...`));\n upgradedConfig = migrateConfig(existingConfig);\n migrated = true;\n } else {\n // Just merge with defaults for current version configs\n upgradedConfig = deepMergeConfig(defaultConfig, existingConfig as Partial<LienConfig>);\n \n console.log(chalk.dim('\\nNew options added:'));\n newFields.forEach(field => console.log(chalk.dim(' •'), chalk.bold(field)));\n }\n \n // 5. Write upgraded config\n await fs.writeFile(\n configPath,\n JSON.stringify(upgradedConfig, null, 2) + '\\n',\n 'utf-8'\n );\n \n // 6. Show results\n console.log(chalk.green('✓ Config upgraded successfully'));\n console.log(chalk.dim('Backup saved to:'), backupPath);\n \n if (migrated) {\n console.log(chalk.dim('\\n📝 Your config now uses the framework-based structure.'));\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.log(chalk.red('Error: No config file found'));\n console.log(chalk.dim('Run'), chalk.bold('lien init'), chalk.dim('to create a config file'));\n return;\n }\n throw error;\n }\n }\n \n /**\n * Perform migration and return result\n * Used when programmatic access to migration result is needed\n */\n async migrate(): Promise<MigrationResult> {\n return migrateConfigFile(this.rootDir);\n }\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { DetectionResult, DetectionOptions, defaultDetectionOptions } from './types.js';\nimport { frameworkDetectors } from './registry.js';\n\n/**\n * Detect all frameworks in a monorepo by recursively scanning subdirectories\n * @param rootDir - Absolute path to project root\n * @param options - Detection options (max depth, skip dirs)\n * @returns Array of detected frameworks with their paths\n */\nexport async function detectAllFrameworks(\n rootDir: string,\n options: Partial<DetectionOptions> = {}\n): Promise<DetectionResult[]> {\n const opts = { ...defaultDetectionOptions, ...options };\n const results: DetectionResult[] = [];\n const visited = new Set<string>();\n \n // Detect at root first\n await detectAtPath(rootDir, '.', results, visited);\n \n // Recursively scan subdirectories\n await scanSubdirectories(rootDir, '.', results, visited, 0, opts);\n \n return results;\n}\n\n/**\n * Detect frameworks at a specific path\n */\nasync function detectAtPath(\n rootDir: string,\n relativePath: string,\n results: DetectionResult[],\n visited: Set<string>\n): Promise<void> {\n // Mark as visited\n const fullPath = path.join(rootDir, relativePath);\n if (visited.has(fullPath)) {\n return;\n }\n visited.add(fullPath);\n \n // Run all detectors and collect results\n const detectedAtPath: Array<DetectionResult & { priority: number }> = [];\n \n for (const detector of frameworkDetectors) {\n try {\n const result = await detector.detect(rootDir, relativePath);\n if (result.detected) {\n detectedAtPath.push({\n ...result,\n priority: detector.priority ?? 0,\n });\n }\n } catch (error) {\n // Log error but continue with other detectors\n console.error(`Error running detector '${detector.name}' at ${relativePath}:`, error);\n }\n }\n \n // Conflict resolution: Allow multiple HIGH-confidence frameworks to coexist\n // This enables hybrid projects (e.g., Shopify + Node.js, Laravel + Node.js)\n if (detectedAtPath.length > 1) {\n // Separate frameworks by confidence level\n const highConfidence = detectedAtPath.filter(d => d.confidence === 'high');\n const mediumConfidence = detectedAtPath.filter(d => d.confidence === 'medium');\n const lowConfidence = detectedAtPath.filter(d => d.confidence === 'low');\n \n if (highConfidence.length > 1) {\n // Multiple HIGH-confidence frameworks -> keep all (hybrid/monorepo behavior)\n // Strip internal priority property before adding to results\n const cleanResults = highConfidence.map(({ priority, ...result }) => result);\n results.push(...cleanResults);\n const names = highConfidence.map(d => d.name).join(' + ');\n console.log(` → Detected hybrid project: ${names}`);\n \n // Log skipped medium/low confidence detections\n if (mediumConfidence.length > 0 || lowConfidence.length > 0) {\n const skippedNames = [...mediumConfidence, ...lowConfidence].map(d => d.name).join(', ');\n console.log(` → Skipping lower confidence detections: ${skippedNames}`);\n }\n } else if (highConfidence.length === 1) {\n // Only one HIGH-confidence framework\n const { priority, ...result } = highConfidence[0];\n results.push(result);\n \n // Log skipped medium/low confidence detections\n if (mediumConfidence.length > 0 || lowConfidence.length > 0) {\n const skippedNames = [...mediumConfidence, ...lowConfidence].map(d => d.name).join(', ');\n console.log(` → Skipping lower confidence detections: ${skippedNames}`);\n }\n } else if (mediumConfidence.length > 0) {\n // No HIGH confidence, but have MEDIUM -> use priority system\n mediumConfidence.sort((a, b) => b.priority - a.priority);\n const { priority, ...winner } = mediumConfidence[0];\n results.push(winner);\n \n // Skipped = remaining medium + all low confidence\n const skipped = [...mediumConfidence.slice(1), ...lowConfidence];\n if (skipped.length > 0) {\n const skippedNames = skipped.map(d => d.name).join(', ');\n console.log(` → Skipping ${skippedNames} at ${relativePath} (${winner.name} takes precedence)`);\n }\n } else if (lowConfidence.length > 0) {\n // Only LOW confidence -> use priority system\n lowConfidence.sort((a, b) => b.priority - a.priority);\n const { priority, ...winner } = lowConfidence[0];\n results.push(winner);\n \n // Skipped = remaining low confidence\n const skipped = lowConfidence.slice(1);\n if (skipped.length > 0) {\n const skippedNames = skipped.map(d => d.name).join(', ');\n console.log(` → Skipping ${skippedNames} at ${relativePath} (${winner.name} takes precedence)`);\n }\n }\n } else if (detectedAtPath.length === 1) {\n const { priority, ...result } = detectedAtPath[0];\n results.push(result);\n }\n}\n\n/**\n * Recursively scan subdirectories for frameworks\n */\nasync function scanSubdirectories(\n rootDir: string,\n relativePath: string,\n results: DetectionResult[],\n visited: Set<string>,\n depth: number,\n options: DetectionOptions\n): Promise<void> {\n // Check depth limit\n if (depth >= options.maxDepth) {\n return;\n }\n \n const fullPath = path.join(rootDir, relativePath);\n \n try {\n const entries = await fs.readdir(fullPath, { withFileTypes: true });\n \n // Process only directories\n const dirs = entries.filter(e => e.isDirectory());\n \n for (const dir of dirs) {\n // Skip directories in the skip list\n if (options.skipDirs.includes(dir.name)) {\n continue;\n }\n \n // Skip hidden directories (except .git, .github which are already in skipDirs)\n if (dir.name.startsWith('.')) {\n continue;\n }\n \n const subPath = relativePath === '.' \n ? dir.name \n : path.join(relativePath, dir.name);\n \n // Detect at this subdirectory\n await detectAtPath(rootDir, subPath, results, visited);\n \n // Recurse deeper\n await scanSubdirectories(rootDir, subPath, results, visited, depth + 1, options);\n }\n } catch (error) {\n // Silently skip directories we can't read (permission errors, etc.)\n return;\n }\n}\n\n/**\n * Get a human-readable summary of detected frameworks\n */\nexport function getDetectionSummary(results: DetectionResult[]): string {\n if (results.length === 0) {\n return 'No frameworks detected';\n }\n \n const lines: string[] = [];\n \n for (const result of results) {\n const pathDisplay = result.path === '.' ? 'root' : result.path;\n lines.push(`${result.name} at ${pathDisplay} (${result.confidence} confidence)`);\n \n if (result.evidence.length > 0) {\n result.evidence.forEach(e => {\n lines.push(` - ${e}`);\n });\n }\n }\n \n return lines.join('\\n');\n}\n\n","import { FrameworkConfig } from '../config/schema.js';\n\n/**\n * Result of framework detection\n */\nexport interface DetectionResult {\n detected: boolean;\n name: string; // 'nodejs', 'laravel'\n path: string; // Relative path from root: '.', 'packages/cli', 'cognito-backend'\n confidence: 'high' | 'medium' | 'low';\n evidence: string[]; // Human-readable evidence (e.g., \"Found package.json with jest\")\n version?: string; // Framework/language version if detectable\n}\n\n/**\n * Interface for framework detectors\n */\nexport interface FrameworkDetector {\n name: string; // Unique framework identifier\n \n /**\n * Priority for conflict resolution (higher = takes precedence)\n * - 100: Specific frameworks (Laravel, Rails, Django)\n * - 50: Generic frameworks (Node.js, Python)\n * - 0: Fallback/generic\n */\n priority?: number;\n \n /**\n * Detect if this framework exists at the given path\n * @param rootDir - Absolute path to project root\n * @param relativePath - Relative path from root to check (e.g., '.' or 'packages/cli')\n * @returns Detection result with evidence\n */\n detect(rootDir: string, relativePath: string): Promise<DetectionResult>;\n \n /**\n * Generate default configuration for this framework\n * @param rootDir - Absolute path to project root\n * @param relativePath - Relative path where framework was detected\n * @returns Framework-specific configuration\n */\n generateConfig(rootDir: string, relativePath: string): Promise<FrameworkConfig>;\n}\n\n/**\n * Options for framework detection\n */\nexport interface DetectionOptions {\n maxDepth: number; // Maximum directory depth to scan\n skipDirs: string[]; // Directories to skip (node_modules, vendor, etc.)\n}\n\n/**\n * Default detection options\n */\nexport const defaultDetectionOptions: DetectionOptions = {\n maxDepth: 3,\n skipDirs: [\n 'node_modules',\n 'vendor',\n 'dist',\n 'build',\n '.next',\n '.nuxt',\n 'coverage',\n '.git',\n '.idea',\n '.vscode',\n 'tmp',\n 'temp',\n ],\n};\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateNodeJsConfig } from './config.js';\n\n/**\n * Node.js/TypeScript/JavaScript framework detector\n */\nexport const nodejsDetector: FrameworkDetector = {\n name: 'nodejs',\n priority: 50, // Generic, yields to specific frameworks like Laravel\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'nodejs',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for package.json\n const packageJsonPath = path.join(fullPath, 'package.json');\n let packageJson: any = null;\n \n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8');\n packageJson = JSON.parse(content);\n result.evidence.push('Found package.json');\n } catch {\n // No package.json, not a Node.js project\n return result;\n }\n \n // At this point, we know it's a Node.js project\n result.detected = true;\n result.confidence = 'high';\n \n // Check for TypeScript\n if (packageJson.devDependencies?.typescript || packageJson.dependencies?.typescript) {\n result.evidence.push('TypeScript detected');\n }\n \n // Check for testing frameworks\n const testFrameworks = [\n { name: 'jest', display: 'Jest' },\n { name: 'vitest', display: 'Vitest' },\n { name: 'mocha', display: 'Mocha' },\n { name: 'ava', display: 'AVA' },\n { name: '@playwright/test', display: 'Playwright' },\n ];\n \n for (const framework of testFrameworks) {\n if (\n packageJson.devDependencies?.[framework.name] || \n packageJson.dependencies?.[framework.name]\n ) {\n result.evidence.push(`${framework.display} test framework detected`);\n break; // Only mention first test framework found\n }\n }\n \n // Check for common frameworks/libraries\n const frameworks = [\n { name: 'next', display: 'Next.js' },\n { name: 'react', display: 'React' },\n { name: 'vue', display: 'Vue' },\n { name: 'express', display: 'Express' },\n { name: '@nestjs/core', display: 'NestJS' },\n ];\n \n for (const fw of frameworks) {\n if (packageJson.dependencies?.[fw.name]) {\n result.evidence.push(`${fw.display} detected`);\n break; // Only mention first framework found\n }\n }\n \n // Try to detect version from package.json engines or node version\n if (packageJson.engines?.node) {\n result.version = packageJson.engines.node;\n }\n \n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateNodeJsConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Node.js framework configuration\n */\nexport async function generateNodeJsConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // Broader patterns to catch all common project structures\n // (frontend/, src/, lib/, app/, components/, etc.)\n '**/*.ts',\n '**/*.tsx',\n '**/*.js',\n '**/*.jsx',\n '**/*.vue',\n '**/*.mjs',\n '**/*.cjs',\n '**/*.md',\n '**/*.mdx',\n ],\n exclude: [\n // Node.js dependencies (with ** prefix for nested projects)\n '**/node_modules/**',\n 'node_modules/**',\n \n // PHP/Composer dependencies (for monorepos with PHP)\n '**/vendor/**',\n 'vendor/**',\n \n // Build outputs\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n '**/public/build/**',\n 'public/build/**',\n 'out/**',\n \n // Framework build caches\n '.next/**',\n '.nuxt/**',\n '.vite/**',\n '.lien/**',\n \n // Test artifacts\n 'coverage/**',\n 'playwright-report/**',\n 'test-results/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Common build/cache directories\n '.cache/**',\n '.turbo/**',\n '.vercel/**',\n '.netlify/**',\n \n // Minified/bundled files\n '**/*.min.js',\n '**/*.min.css',\n '**/*.bundle.js',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generatePhpConfig } from './config.js';\n\n/**\n * Generic PHP framework detector\n * Detects any PHP project with composer.json\n */\nexport const phpDetector: FrameworkDetector = {\n name: 'php',\n priority: 50, // Generic, yields to specific frameworks like Laravel\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'php',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for composer.json\n const composerJsonPath = path.join(fullPath, 'composer.json');\n let composerJson: any = null;\n \n try {\n const content = await fs.readFile(composerJsonPath, 'utf-8');\n composerJson = JSON.parse(content);\n result.evidence.push('Found composer.json');\n } catch {\n // No composer.json, not a PHP project\n return result;\n }\n \n // Check if this is a Laravel project (Laravel detector should handle it)\n const hasLaravel = \n composerJson.require?.['laravel/framework'] ||\n composerJson['require-dev']?.['laravel/framework'];\n \n if (hasLaravel) {\n // This is a Laravel project - let the Laravel detector handle it\n // Return not detected to avoid redundant \"php\" + \"laravel\" detection\n return result;\n }\n \n // At this point, we know it's a generic PHP project (not Laravel)\n result.detected = true;\n result.confidence = 'high';\n \n // Check for common PHP directories\n const phpDirs = ['src', 'lib', 'app', 'tests'];\n let foundDirs = 0;\n \n for (const dir of phpDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs > 0) {\n result.evidence.push(`Found PHP project structure (${foundDirs} directories)`);\n }\n \n // Check for PHP version\n if (composerJson.require?.php) {\n result.version = composerJson.require.php;\n result.evidence.push(`PHP ${composerJson.require.php}`);\n }\n \n // Check for testing frameworks\n const testFrameworks = [\n { name: 'phpunit/phpunit', display: 'PHPUnit' },\n { name: 'pestphp/pest', display: 'Pest' },\n { name: 'codeception/codeception', display: 'Codeception' },\n { name: 'behat/behat', display: 'Behat' },\n ];\n \n for (const framework of testFrameworks) {\n if (\n composerJson.require?.[framework.name] || \n composerJson['require-dev']?.[framework.name]\n ) {\n result.evidence.push(`${framework.display} test framework detected`);\n break; // Only mention first test framework found\n }\n }\n \n // Check for common PHP tools/frameworks\n const tools = [\n { name: 'symfony/framework-bundle', display: 'Symfony' },\n { name: 'symfony/http-kernel', display: 'Symfony' },\n { name: 'symfony/symfony', display: 'Symfony (monolithic)' },\n { name: 'doctrine/orm', display: 'Doctrine ORM' },\n { name: 'guzzlehttp/guzzle', display: 'Guzzle HTTP' },\n { name: 'monolog/monolog', display: 'Monolog' },\n ];\n \n for (const tool of tools) {\n if (composerJson.require?.[tool.name]) {\n result.evidence.push(`${tool.display} detected`);\n break; // Only mention first tool found\n }\n }\n \n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generatePhpConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate generic PHP framework configuration\n */\nexport async function generatePhpConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // PHP source code\n 'src/**/*.php',\n 'lib/**/*.php',\n 'app/**/*.php',\n 'tests/**/*.php',\n '*.php',\n \n // Common PHP project files\n 'config/**/*.php',\n 'public/**/*.php',\n \n // Documentation\n '**/*.md',\n '**/*.mdx',\n 'docs/**/*.md',\n 'README.md',\n 'CHANGELOG.md',\n ],\n exclude: [\n // Composer dependencies (CRITICAL)\n '**/vendor/**',\n 'vendor/**',\n \n // Node.js dependencies\n '**/node_modules/**',\n 'node_modules/**',\n \n // Build outputs\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n '**/public/build/**',\n 'public/build/**',\n \n // Laravel/PHP system directories\n 'storage/**',\n 'cache/**',\n 'bootstrap/cache/**',\n \n // Test artifacts\n 'coverage/**',\n 'test-results/**',\n '.phpunit.cache/**',\n \n // Build outputs\n '__generated__/**',\n \n // Minified files\n '**/*.min.js',\n '**/*.min.css',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateLaravelConfig } from './config.js';\n\n/**\n * Laravel/PHP framework detector\n */\nexport const laravelDetector: FrameworkDetector = {\n name: 'laravel',\n priority: 100, // Laravel takes precedence over Node.js\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'laravel',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // Check for composer.json with Laravel\n const composerJsonPath = path.join(fullPath, 'composer.json');\n let composerJson: any = null;\n \n try {\n const content = await fs.readFile(composerJsonPath, 'utf-8');\n composerJson = JSON.parse(content);\n result.evidence.push('Found composer.json');\n } catch {\n // No composer.json, not a Laravel project\n return result;\n }\n \n // Check if Laravel framework is in dependencies\n const hasLaravel = \n composerJson.require?.['laravel/framework'] ||\n composerJson['require-dev']?.['laravel/framework'];\n \n if (!hasLaravel) {\n // Has composer.json but not Laravel\n return result;\n }\n \n result.evidence.push('Laravel framework detected in composer.json');\n \n // Check for artisan file (strong indicator of Laravel)\n const artisanPath = path.join(fullPath, 'artisan');\n try {\n await fs.access(artisanPath);\n result.evidence.push('Found artisan file');\n result.confidence = 'high';\n } catch {\n result.confidence = 'medium';\n }\n \n // Check for typical Laravel directory structure\n const laravelDirs = ['app', 'routes', 'config', 'database'];\n let foundDirs = 0;\n \n for (const dir of laravelDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs >= 2) {\n result.evidence.push(`Laravel directory structure detected (${foundDirs}/${laravelDirs.length} dirs)`);\n result.confidence = 'high';\n }\n \n // Check for test directories\n const testDirsToCheck = [\n path.join(fullPath, 'tests', 'Feature'),\n path.join(fullPath, 'tests', 'Unit'),\n ];\n \n for (const testDir of testDirsToCheck) {\n try {\n const stats = await fs.stat(testDir);\n if (stats.isDirectory()) {\n const dirName = path.basename(path.dirname(testDir)) + '/' + path.basename(testDir);\n result.evidence.push(`Found ${dirName} test directory`);\n }\n } catch {\n // Test directory doesn't exist\n }\n }\n \n // Extract Laravel version if available\n if (composerJson.require?.['laravel/framework']) {\n result.version = composerJson.require['laravel/framework'];\n }\n \n result.detected = true;\n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateLaravelConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Laravel framework configuration\n */\nexport async function generateLaravelConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // PHP backend\n 'app/**/*.php',\n 'routes/**/*.php',\n 'config/**/*.php',\n 'database/**/*.php',\n 'resources/**/*.php',\n 'tests/**/*.php',\n '*.php',\n // Frontend assets (Vue/React/Inertia) - Scoped to resources/ to avoid build output\n 'resources/**/*.js',\n 'resources/**/*.ts',\n 'resources/**/*.jsx',\n 'resources/**/*.tsx',\n 'resources/**/*.vue',\n // Blade templates\n 'resources/views/**/*.blade.php',\n // Documentation\n 'docs/**/*.md',\n 'README.md',\n 'CHANGELOG.md',\n ],\n exclude: [\n // Composer dependencies (CRITICAL: exclude before any include patterns)\n '**/vendor/**',\n 'vendor/**',\n \n // Build outputs (Vite/Mix compiled assets)\n '**/public/build/**',\n 'public/build/**',\n 'public/hot',\n '**/dist/**',\n 'dist/**',\n '**/build/**',\n 'build/**',\n \n // Laravel system directories\n 'storage/**',\n 'bootstrap/cache/**',\n 'public/**/*.js', // Compiled JS in public\n 'public/**/*.css', // Compiled CSS in public\n \n // Database boilerplate (not useful for semantic search)\n 'database/migrations/**',\n 'database/seeders/**',\n 'database/factories/**',\n \n // Node.js dependencies\n '**/node_modules/**',\n 'node_modules/**',\n \n // Test artifacts\n 'playwright-report/**',\n 'test-results/**',\n 'coverage/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Frontend build outputs\n '.vite/**',\n '.nuxt/**',\n '.next/**',\n \n // Minified files\n '**/*.min.js',\n '**/*.min.css',\n ],\n };\n}\n\n","import fs from 'fs/promises';\nimport path from 'path';\nimport { FrameworkDetector, DetectionResult } from '../types.js';\nimport { generateShopifyConfig } from './config.js';\n\n/**\n * Shopify Liquid theme framework detector\n */\nexport const shopifyDetector: FrameworkDetector = {\n name: 'shopify',\n priority: 100, // High priority (same as Laravel)\n \n async detect(rootDir: string, relativePath: string): Promise<DetectionResult> {\n const fullPath = path.join(rootDir, relativePath);\n const result: DetectionResult = {\n detected: false,\n name: 'shopify',\n path: relativePath,\n confidence: 'low',\n evidence: [],\n };\n \n // 1. Check for config/settings_schema.json (STRONGEST signal)\n const settingsSchemaPath = path.join(fullPath, 'config', 'settings_schema.json');\n let hasSettingsSchema = false;\n \n try {\n await fs.access(settingsSchemaPath);\n hasSettingsSchema = true;\n result.evidence.push('Found config/settings_schema.json');\n } catch {\n // Not present, continue checking other markers\n }\n \n // 2. Check for layout/theme.liquid\n const themeLayoutPath = path.join(fullPath, 'layout', 'theme.liquid');\n let hasThemeLayout = false;\n \n try {\n await fs.access(themeLayoutPath);\n hasThemeLayout = true;\n result.evidence.push('Found layout/theme.liquid');\n } catch {\n // Not present\n }\n \n // 3. Check for typical Shopify directories\n const shopifyDirs = ['sections', 'snippets', 'templates', 'locales'];\n let foundDirs = 0;\n \n for (const dir of shopifyDirs) {\n try {\n const dirPath = path.join(fullPath, dir);\n const stats = await fs.stat(dirPath);\n if (stats.isDirectory()) {\n foundDirs++;\n }\n } catch {\n // Directory doesn't exist\n }\n }\n \n if (foundDirs >= 2) {\n result.evidence.push(`Shopify directory structure detected (${foundDirs}/${shopifyDirs.length} dirs)`);\n }\n \n // 4. Check for shopify.theme.toml (Shopify CLI)\n try {\n const tomlPath = path.join(fullPath, 'shopify.theme.toml');\n await fs.access(tomlPath);\n result.evidence.push('Found shopify.theme.toml');\n } catch {\n // Optional file\n }\n \n // 5. Check for .shopifyignore\n try {\n const ignorePath = path.join(fullPath, '.shopifyignore');\n await fs.access(ignorePath);\n result.evidence.push('Found .shopifyignore');\n } catch {\n // Optional file\n }\n \n // Determine detection confidence with early returns\n // High: Has settings_schema.json + 2+ directories\n if (hasSettingsSchema && foundDirs >= 2) {\n result.detected = true;\n result.confidence = 'high';\n return result;\n }\n \n // Medium: Has settings_schema alone, OR has theme.liquid + 1+ directory\n if (hasSettingsSchema || (hasThemeLayout && foundDirs >= 1)) {\n result.detected = true;\n result.confidence = 'medium';\n return result;\n }\n \n // Medium: Has 3+ typical directories but no strong markers\n if (foundDirs >= 3) {\n result.detected = true;\n result.confidence = 'medium';\n return result;\n }\n \n // Not detected\n return result;\n },\n \n async generateConfig(rootDir: string, relativePath: string) {\n return generateShopifyConfig(rootDir, relativePath);\n },\n};\n\n","import { FrameworkConfig } from '../../config/schema.js';\n\n/**\n * Generate Shopify theme framework configuration\n */\nexport async function generateShopifyConfig(\n _rootDir: string,\n _relativePath: string\n): Promise<FrameworkConfig> {\n return {\n include: [\n // Core Liquid templates\n 'layout/**/*.liquid',\n 'sections/**/*.liquid',\n 'snippets/**/*.liquid',\n 'templates/**/*.liquid', // Matches any nesting level (e.g., templates/customers/account.liquid)\n 'templates/**/*.json', // JSON template definitions (Shopify 2.0+)\n \n // Theme editor blocks (Online Store 2.0)\n 'blocks/**/*.liquid',\n \n // Assets (CSS, JS with optional Liquid templating)\n 'assets/**/*.js',\n 'assets/**/*.js.liquid',\n 'assets/**/*.css',\n 'assets/**/*.css.liquid',\n 'assets/**/*.scss',\n 'assets/**/*.scss.liquid',\n \n // Configuration files\n 'config/*.json',\n \n // Locales (i18n)\n 'locales/*.json',\n \n // Documentation\n '*.md',\n 'docs/**/*.md',\n \n // Shopify-specific config files\n 'shopify.theme.toml',\n '.shopifyignore',\n ],\n exclude: [\n 'node_modules/**',\n 'dist/**',\n 'build/**',\n '.git/**',\n \n // Playwright/testing artifacts\n 'playwright-report/**',\n 'test-results/**',\n \n // Build/generated artifacts\n '__generated__/**',\n \n // Common frontend build outputs\n '.vite/**',\n '.nuxt/**',\n '.next/**',\n ],\n };\n}\n\n","import { FrameworkDetector } from './types.js';\nimport { nodejsDetector } from './nodejs/detector.js';\nimport { phpDetector } from './php/detector.js';\nimport { laravelDetector } from './laravel/detector.js';\nimport { shopifyDetector } from './shopify/detector.js';\n\n/**\n * Registry of all available framework detectors\n * Frameworks will be added as they are implemented\n * \n * Order doesn't matter for detection as priority system handles conflicts,\n * but listed here in order from generic to specific for clarity:\n * - Generic language detectors (Node.js, PHP)\n * - Specific framework detectors (Laravel, Shopify)\n */\nexport const frameworkDetectors: FrameworkDetector[] = [\n nodejsDetector,\n phpDetector,\n laravelDetector,\n shopifyDetector,\n];\n\n/**\n * Register a framework detector\n */\nexport function registerFramework(detector: FrameworkDetector): void {\n // Check if already registered\n const existing = frameworkDetectors.find(d => d.name === detector.name);\n if (existing) {\n console.warn(`Framework detector '${detector.name}' is already registered, skipping`);\n return;\n }\n \n frameworkDetectors.push(detector);\n}\n\n/**\n * Get a framework detector by name\n */\nexport function getFrameworkDetector(name: string): FrameworkDetector | undefined {\n return frameworkDetectors.find(d => d.name === name);\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport os from 'os';\nimport crypto from 'crypto';\nimport { configService } from '../config/service.js';\nimport { isGitRepo, getCurrentBranch, getCurrentCommit } from '../git/utils.js';\nimport { readVersionFile } from '../vectordb/version.js';\nimport { showCompactBanner } from '../utils/banner.js';\nimport { isModernConfig } from '../config/schema.js';\n\nexport async function statusCommand() {\n const rootDir = process.cwd();\n const projectName = path.basename(rootDir);\n \n // Use same hashing logic as VectorDB to show correct path\n const pathHash = crypto\n .createHash('md5')\n .update(rootDir)\n .digest('hex')\n .substring(0, 8);\n \n const indexPath = path.join(os.homedir(), '.lien', 'indices', `${projectName}-${pathHash}`);\n \n showCompactBanner();\n console.log(chalk.bold('Status\\n'));\n \n // Check if config exists\n const hasConfig = await configService.exists(rootDir);\n console.log(chalk.dim('Configuration:'), hasConfig ? chalk.green('✓ Found') : chalk.red('✗ Not initialized'));\n \n if (!hasConfig) {\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien init'), chalk.yellow('to initialize'));\n return;\n }\n \n // Check if index exists\n try {\n const stats = await fs.stat(indexPath);\n console.log(chalk.dim('Index location:'), indexPath);\n console.log(chalk.dim('Index status:'), chalk.green('✓ Exists'));\n \n // Try to get directory size\n try {\n const files = await fs.readdir(indexPath, { recursive: true });\n console.log(chalk.dim('Index files:'), files.length);\n } catch (e) {\n // Ignore\n }\n \n console.log(chalk.dim('Last modified:'), stats.mtime.toLocaleString());\n \n // Show version file info\n try {\n const version = await readVersionFile(indexPath);\n if (version > 0) {\n const versionDate = new Date(version);\n console.log(chalk.dim('Last reindex:'), versionDate.toLocaleString());\n }\n } catch {\n // Ignore\n }\n } catch (error) {\n console.log(chalk.dim('Index status:'), chalk.yellow('✗ Not indexed'));\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien index'), chalk.yellow('to index your codebase'));\n }\n \n // Load and show configuration settings\n try {\n const config = await configService.load(rootDir);\n \n console.log(chalk.bold('\\nFeatures:'));\n \n // Git detection status\n const isRepo = await isGitRepo(rootDir);\n if (config.gitDetection.enabled && isRepo) {\n console.log(chalk.dim('Git detection:'), chalk.green('✓ Enabled'));\n console.log(chalk.dim(' Poll interval:'), `${config.gitDetection.pollIntervalMs / 1000}s`);\n \n // Show current git state\n try {\n const branch = await getCurrentBranch(rootDir);\n const commit = await getCurrentCommit(rootDir);\n console.log(chalk.dim(' Current branch:'), branch);\n console.log(chalk.dim(' Current commit:'), commit.substring(0, 8));\n \n // Check if git state file exists\n const gitStateFile = path.join(indexPath, '.git-state.json');\n try {\n const gitStateContent = await fs.readFile(gitStateFile, 'utf-8');\n const gitState = JSON.parse(gitStateContent);\n if (gitState.branch !== branch || gitState.commit !== commit) {\n console.log(chalk.yellow(' ⚠️ Git state changed - will reindex on next serve'));\n }\n } catch {\n // Git state file doesn't exist yet\n }\n } catch {\n // Ignore git command errors\n }\n } else if (config.gitDetection.enabled && !isRepo) {\n console.log(chalk.dim('Git detection:'), chalk.yellow('Enabled (not a git repo)'));\n } else {\n console.log(chalk.dim('Git detection:'), chalk.gray('Disabled'));\n }\n \n // File watching status\n if (config.fileWatching.enabled) {\n console.log(chalk.dim('File watching:'), chalk.green('✓ Enabled'));\n console.log(chalk.dim(' Debounce:'), `${config.fileWatching.debounceMs}ms`);\n } else {\n console.log(chalk.dim('File watching:'), chalk.gray('Disabled'));\n console.log(chalk.dim(' Enable with:'), chalk.bold('lien serve --watch'));\n }\n \n // Indexing settings\n console.log(chalk.bold('\\nIndexing Settings:'));\n if (isModernConfig(config)) {\n console.log(chalk.dim('Concurrency:'), config.core.concurrency);\n console.log(chalk.dim('Batch size:'), config.core.embeddingBatchSize);\n console.log(chalk.dim('Chunk size:'), config.core.chunkSize);\n console.log(chalk.dim('Chunk overlap:'), config.core.chunkOverlap);\n }\n \n } catch (error) {\n console.log(chalk.yellow('\\nWarning: Could not load configuration'));\n }\n}\n\n","import chalk from 'chalk';\nimport { indexCodebase } from '../indexer/index.js';\nimport { showCompactBanner } from '../utils/banner.js';\n\nexport async function indexCommand(options: { watch?: boolean; verbose?: boolean; force?: boolean }) {\n showCompactBanner();\n \n try {\n // If force flag is set, clear the index and manifest first (clean slate)\n if (options.force) {\n const { VectorDB } = await import('../vectordb/lancedb.js');\n const { ManifestManager } = await import('../indexer/manifest.js');\n \n console.log(chalk.yellow('Clearing existing index and manifest...'));\n const vectorDB = new VectorDB(process.cwd());\n await vectorDB.initialize();\n await vectorDB.clear();\n \n // Also clear manifest\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.clear();\n \n console.log(chalk.green('✓ Index and manifest cleared\\n'));\n }\n \n await indexCodebase({\n rootDir: process.cwd(),\n verbose: options.verbose || false,\n force: options.force || false,\n });\n \n if (options.watch) {\n console.log(chalk.yellow('\\n⚠️ Watch mode not yet implemented'));\n // TODO: Implement file watching with chokidar\n }\n } catch (error) {\n console.error(chalk.red('Error during indexing:'), error);\n process.exit(1);\n }\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { startMCPServer } from '../mcp/server.js';\nimport { showBanner } from '../utils/banner.js';\n\nexport async function serveCommand(options: { port?: string; watch?: boolean; noWatch?: boolean; root?: string }) {\n const rootDir = options.root ? path.resolve(options.root) : process.cwd();\n \n try {\n // Validate root directory if --root was specified\n if (options.root) {\n try {\n const stats = await fs.stat(rootDir);\n if (!stats.isDirectory()) {\n console.error(chalk.red(`Error: --root path is not a directory: ${rootDir}`));\n process.exit(1);\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.error(chalk.red(`Error: --root directory does not exist: ${rootDir}`));\n } else if ((error as NodeJS.ErrnoException).code === 'EACCES') {\n console.error(chalk.red(`Error: --root directory is not accessible: ${rootDir}`));\n } else {\n console.error(chalk.red(`Error: Failed to access --root directory: ${rootDir}`));\n console.error(chalk.dim((error as Error).message));\n }\n process.exit(1);\n }\n }\n \n // Log to stderr since stdout is for MCP protocol\n showBanner();\n console.error(chalk.bold('Starting MCP server...\\n'));\n \n if (options.root) {\n console.error(chalk.dim(`Serving from: ${rootDir}\\n`));\n }\n \n // Handle deprecated --watch flag\n if (options.watch) {\n console.error(chalk.yellow('⚠️ --watch flag is deprecated (file watching is now default)'));\n console.error(chalk.dim(' Use --no-watch to disable file watching\\n'));\n }\n \n // Determine file watching state\n // Priority: --no-watch > --watch (deprecated) > config default\n const watch = options.noWatch ? false : options.watch ? true : undefined;\n \n await startMCPServer({\n rootDir,\n verbose: true,\n watch,\n });\n } catch (error) {\n console.error(chalk.red('Failed to start MCP server:'), error);\n process.exit(1);\n }\n}\n\n","import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { createRequire } from 'module';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { tools } from './tools.js';\nimport { toolHandlers } from './handlers/index.js';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { LocalEmbeddings } from '../embeddings/local.js';\nimport { GitStateTracker } from '../git/tracker.js';\nimport { indexMultipleFiles, indexSingleFile } from '../indexer/incremental.js';\nimport { configService } from '../config/service.js';\nimport { ManifestManager } from '../indexer/manifest.js';\nimport { isGitAvailable, isGitRepo } from '../git/utils.js';\nimport { FileWatcher } from '../watcher/index.js';\nimport { VERSION_CHECK_INTERVAL_MS } from '../constants.js';\nimport { LienError, LienErrorCode } from '../errors/index.js';\nimport type { ToolContext, LogFn, LogLevel } from './types.js';\n\n// Get version from package.json dynamically\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst require = createRequire(import.meta.url);\n\nlet packageJson: { name: string; version: string };\ntry {\n packageJson = require(join(__dirname, '../package.json'));\n} catch {\n packageJson = require(join(__dirname, '../../package.json'));\n}\n\nexport interface MCPServerOptions {\n rootDir: string;\n verbose?: boolean;\n watch?: boolean;\n}\n\n/**\n * Initialize embeddings and vector database.\n */\nasync function initializeDatabase(\n rootDir: string,\n log: LogFn\n): Promise<{ embeddings: LocalEmbeddings; vectorDB: VectorDB }> {\n const embeddings = new LocalEmbeddings();\n const vectorDB = new VectorDB(rootDir);\n\n log('Loading embedding model...');\n await embeddings.initialize();\n\n log('Loading vector database...');\n await vectorDB.initialize();\n\n log('Embeddings and vector DB ready');\n return { embeddings, vectorDB };\n}\n\n/**\n * Run auto-indexing if needed (first run with no index).\n */\nasync function handleAutoIndexing(\n vectorDB: VectorDB,\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n log: LogFn\n): Promise<void> {\n const hasIndex = await vectorDB.hasData();\n\n if (!hasIndex && config.mcp.autoIndexOnFirstRun) {\n log('📦 No index found - running initial indexing...');\n log('⏱️ This may take 5-20 minutes depending on project size');\n\n try {\n const { indexCodebase } = await import('../indexer/index.js');\n await indexCodebase({ rootDir, verbose: true });\n log('✅ Initial indexing complete!');\n } catch (error) {\n log(`⚠️ Initial indexing failed: ${error}`, 'warning');\n log('You can manually run: lien index', 'warning');\n }\n } else if (!hasIndex) {\n log('⚠️ No index found. Auto-indexing is disabled in config.', 'warning');\n log('Run \"lien index\" to index your codebase.', 'warning');\n }\n}\n\n/**\n * Setup git detection and background polling.\n */\nasync function setupGitDetection(\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n vectorDB: VectorDB,\n embeddings: LocalEmbeddings,\n verbose: boolean | undefined,\n log: LogFn\n): Promise<{ gitTracker: GitStateTracker | null; gitPollInterval: NodeJS.Timeout | null }> {\n if (!config.gitDetection.enabled) {\n log('Git detection disabled by configuration');\n return { gitTracker: null, gitPollInterval: null };\n }\n\n const gitAvailable = await isGitAvailable();\n const isRepo = await isGitRepo(rootDir);\n\n if (!gitAvailable) {\n log('Git not available - git detection disabled');\n return { gitTracker: null, gitPollInterval: null };\n }\n if (!isRepo) {\n log('Not a git repository - git detection disabled');\n return { gitTracker: null, gitPollInterval: null };\n }\n\n log('✓ Detected git repository');\n const gitTracker = new GitStateTracker(rootDir, vectorDB.dbPath);\n\n // Check for git changes on startup\n try {\n log('Checking for git changes...');\n const changedFiles = await gitTracker.initialize();\n\n if (changedFiles && changedFiles.length > 0) {\n log(`🌿 Git changes detected: ${changedFiles.length} files changed`);\n const count = await indexMultipleFiles(changedFiles, vectorDB, embeddings, config, { verbose });\n log(`✓ Reindexed ${count} files`);\n } else {\n log('✓ Index is up to date with git state');\n }\n } catch (error) {\n log(`Failed to check git state on startup: ${error}`, 'warning');\n }\n\n // Start background polling\n log(`✓ Git detection enabled (checking every ${config.gitDetection.pollIntervalMs / 1000}s)`);\n\n const gitPollInterval = setInterval(async () => {\n try {\n const changedFiles = await gitTracker.detectChanges();\n if (changedFiles && changedFiles.length > 0) {\n log(`🌿 Git change detected: ${changedFiles.length} files changed`);\n indexMultipleFiles(changedFiles, vectorDB, embeddings, config, { verbose })\n .then(count => log(`✓ Background reindex complete: ${count} files`))\n .catch(error => log(`Background reindex failed: ${error}`, 'warning'));\n }\n } catch (error) {\n log(`Git detection check failed: ${error}`, 'warning');\n }\n }, config.gitDetection.pollIntervalMs);\n\n return { gitTracker, gitPollInterval };\n}\n\n/**\n * Setup file watching for real-time updates.\n */\nasync function setupFileWatching(\n watch: boolean | undefined,\n config: Awaited<ReturnType<typeof configService.load>>,\n rootDir: string,\n vectorDB: VectorDB,\n embeddings: LocalEmbeddings,\n verbose: boolean | undefined,\n log: LogFn\n): Promise<FileWatcher | null> {\n const fileWatchingEnabled = watch !== undefined ? watch : config.fileWatching.enabled;\n if (!fileWatchingEnabled) return null;\n\n log('👀 Starting file watcher...');\n const fileWatcher = new FileWatcher(rootDir, config);\n\n try {\n await fileWatcher.start(async (event) => {\n const { type, filepath } = event;\n\n if (type === 'unlink') {\n log(`🗑️ File deleted: ${filepath}`);\n try {\n await vectorDB.deleteByFile(filepath);\n const manifest = new ManifestManager(vectorDB.dbPath);\n await manifest.removeFile(filepath);\n log(`✓ Removed ${filepath} from index`);\n } catch (error) {\n log(`Failed to remove ${filepath}: ${error}`, 'warning');\n }\n } else {\n const action = type === 'add' ? 'added' : 'changed';\n log(`📝 File ${action}: ${filepath}`);\n indexSingleFile(filepath, vectorDB, embeddings, config, { verbose })\n .catch((error) => log(`Failed to reindex ${filepath}: ${error}`, 'warning'));\n }\n });\n\n log(`✓ File watching enabled (watching ${fileWatcher.getWatchedFiles().length} files)`);\n return fileWatcher;\n } catch (error) {\n log(`Failed to start file watcher: ${error}`, 'warning');\n return null;\n }\n}\n\n/**\n * Register tool call handler on the MCP server.\n */\nfunction registerToolCallHandler(\n server: Server,\n toolContext: ToolContext,\n log: LogFn\n): void {\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args } = request.params;\n log(`Handling tool call: ${name}`);\n\n const handler = toolHandlers[name];\n if (!handler) {\n const error = new LienError(\n `Unknown tool: ${name}`,\n LienErrorCode.INVALID_INPUT,\n { requestedTool: name, availableTools: tools.map(t => t.name) },\n 'medium', false, false\n );\n return { isError: true, content: [{ type: 'text' as const, text: JSON.stringify(error.toJSON(), null, 2) }] };\n }\n\n try {\n return await handler(args, toolContext);\n } catch (error) {\n if (error instanceof LienError) {\n return { isError: true, content: [{ type: 'text' as const, text: JSON.stringify(error.toJSON(), null, 2) }] };\n }\n console.error(`Unexpected error handling tool call ${name}:`, error);\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({ error: error instanceof Error ? error.message : 'Unknown error', code: LienErrorCode.INTERNAL_ERROR, tool: name }, null, 2),\n }],\n };\n }\n });\n}\n\nexport async function startMCPServer(options: MCPServerOptions): Promise<void> {\n const { rootDir, verbose, watch } = options;\n \n // Early log function before server is ready (falls back to stderr)\n const earlyLog: LogFn = (message, level = 'info') => { \n if (verbose || level === 'warning' || level === 'error') {\n console.error(`[Lien MCP] [${level}] ${message}`); \n }\n };\n\n earlyLog('Initializing MCP server...');\n\n // Initialize core components\n const { embeddings, vectorDB } = await initializeDatabase(rootDir, earlyLog).catch(error => {\n console.error(`Failed to initialize: ${error}`);\n process.exit(1);\n });\n\n // Create MCP server with logging capability\n const server = new Server(\n { name: 'lien', version: packageJson.version },\n { capabilities: { tools: {}, logging: {} } }\n );\n\n // Create proper log function that uses MCP logging notifications\n // - In verbose mode: all levels (debug, info, notice, warning, error)\n // - In non-verbose mode: only warnings and errors\n const log: LogFn = (message, level: LogLevel = 'info') => {\n if (verbose || level === 'warning' || level === 'error') {\n server.sendLoggingMessage({\n level,\n logger: 'lien',\n data: message,\n }).catch(() => {\n // Fallback to stderr if MCP notification fails (e.g., not connected yet)\n console.error(`[Lien MCP] [${level}] ${message}`);\n });\n }\n };\n\n server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));\n\n // Version check helpers\n const checkAndReconnect = async () => {\n try {\n if (await vectorDB.checkVersion()) {\n log('Index version changed, reconnecting...');\n await vectorDB.reconnect();\n }\n } catch (error) {\n log(`Version check failed: ${error}`, 'warning');\n }\n };\n\n const getIndexMetadata = () => ({\n indexVersion: vectorDB.getCurrentVersion(),\n indexDate: vectorDB.getVersionDate(),\n });\n\n const versionCheckInterval = setInterval(checkAndReconnect, VERSION_CHECK_INTERVAL_MS);\n\n // Load config and create tool context\n const config = await configService.load(rootDir);\n const toolContext: ToolContext = { vectorDB, embeddings, config, rootDir, log, checkAndReconnect, getIndexMetadata };\n\n // Register handlers and setup features\n registerToolCallHandler(server, toolContext, log);\n await handleAutoIndexing(vectorDB, config, rootDir, log);\n const { gitPollInterval } = await setupGitDetection(config, rootDir, vectorDB, embeddings, verbose, log);\n const fileWatcher = await setupFileWatching(watch, config, rootDir, vectorDB, embeddings, verbose, log);\n\n // Cleanup handler\n const cleanup = async () => {\n log('Shutting down MCP server...');\n clearInterval(versionCheckInterval);\n if (gitPollInterval) clearInterval(gitPollInterval);\n if (fileWatcher) await fileWatcher.stop();\n process.exit(0);\n };\n\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n\n // Connect transport\n const transport = new StdioServerTransport();\n transport.onclose = () => { log('Transport closed'); cleanup().catch(() => process.exit(0)); };\n transport.onerror = (error) => log(`Transport error: ${error}`);\n\n await server.connect(transport);\n log('MCP server started and listening on stdio');\n}\n","import { z } from 'zod';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n/**\n * Convert a Zod schema to an MCP tool schema.\n * \n * This utility generates JSON Schema from Zod schemas for use in MCP tool definitions.\n * The resulting schema includes all validation rules and descriptions from the Zod schema.\n * \n * @param zodSchema - The Zod schema to convert\n * @param name - The tool name\n * @param description - The tool description\n * @returns MCP-compatible tool schema object\n * \n * @example\n * ```typescript\n * const SearchSchema = z.object({\n * query: z.string().min(3).describe(\"Search query\"),\n * limit: z.number().default(5)\n * });\n * \n * const tool = toMCPToolSchema(\n * SearchSchema,\n * 'semantic_search',\n * 'Search the codebase semantically'\n * );\n * ```\n */\nexport function toMCPToolSchema(\n zodSchema: z.ZodSchema,\n name: string,\n description: string\n) {\n return {\n name,\n description,\n inputSchema: zodToJsonSchema(zodSchema, {\n target: 'jsonSchema7',\n $refStrategy: 'none',\n }),\n };\n}\n\n","import { z } from 'zod';\n\n/**\n * Schema for semantic search tool input.\n * \n * Validates query strings and result limits for semantic code search.\n * Includes rich descriptions to guide AI assistants on proper usage.\n */\nexport const SemanticSearchSchema = z.object({\n query: z.string()\n .min(3, \"Query must be at least 3 characters\")\n .max(500, \"Query too long (max 500 characters)\")\n .describe(\n \"Natural language description of what you're looking for.\\n\\n\" +\n \"Use full sentences describing functionality, not exact names.\\n\\n\" +\n \"Good examples:\\n\" +\n \" - 'handles user authentication'\\n\" +\n \" - 'validates email format'\\n\" +\n \" - 'processes payment transactions'\\n\\n\" +\n \"Bad examples:\\n\" +\n \" - 'auth' (too vague)\\n\" +\n \" - 'validateEmail' (use grep for exact names)\"\n ),\n \n limit: z.number()\n .int()\n .min(1, \"Limit must be at least 1\")\n .max(50, \"Limit cannot exceed 50\")\n .default(5)\n .describe(\n \"Number of results to return.\\n\\n\" +\n \"Default: 5\\n\" +\n \"Increase to 10-15 for broad exploration.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for semantic search input\n */\nexport type SemanticSearchInput = z.infer<typeof SemanticSearchSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for find_similar tool input.\n * \n * Validates code snippets and result limits for similarity search.\n */\nexport const FindSimilarSchema = z.object({\n code: z.string()\n .min(10, \"Code snippet must be at least 10 characters\")\n .describe(\n \"Code snippet to find similar implementations for.\\n\\n\" +\n \"Provide a representative code sample that demonstrates the pattern \" +\n \"you want to find similar examples of in the codebase.\"\n ),\n \n limit: z.number()\n .int()\n .min(1, \"Limit must be at least 1\")\n .max(20, \"Limit cannot exceed 20\")\n .default(5)\n .describe(\n \"Number of similar code blocks to return.\\n\\n\" +\n \"Default: 5\"\n ),\n});\n\n/**\n * Inferred TypeScript type for find similar input\n */\nexport type FindSimilarInput = z.infer<typeof FindSimilarSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_files_context tool input.\n * \n * Validates file paths and context options for retrieving file-specific code chunks.\n * Supports both single file and batch operations.\n */\nexport const GetFilesContextSchema = z.object({\n filepaths: z.union([\n z.string().min(1, \"Filepath cannot be empty\"),\n z.array(z.string().min(1, \"Filepath cannot be empty\")).min(1, \"Array must contain at least one filepath\").max(50, \"Maximum 50 files per request\")\n ]).describe(\n \"Single filepath or array of filepaths (relative to workspace root).\\n\\n\" +\n \"Single file: 'src/components/Button.tsx'\\n\" +\n \"Multiple files: ['src/auth.ts', 'src/user.ts']\\n\\n\" +\n \"Maximum 50 files per request for batch operations.\"\n ),\n \n includeRelated: z.boolean()\n .default(true)\n .describe(\n \"Include semantically related chunks from nearby code.\\n\\n\" +\n \"Default: true\\n\\n\" +\n \"When enabled, also returns related code from other files that are \" +\n \"semantically similar to the target file's contents.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for file context input\n */\nexport type GetFilesContextInput = z.infer<typeof GetFilesContextSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for list_functions tool input.\n * \n * Validates pattern and language filters for symbol listing.\n */\nexport const ListFunctionsSchema = z.object({\n pattern: z.string()\n .optional()\n .describe(\n \"Regex pattern to match symbol names.\\n\\n\" +\n \"Examples:\\n\" +\n \" - '.*Controller.*' to find all Controllers\\n\" +\n \" - 'handle.*' to find handlers\\n\" +\n \" - '.*Service$' to find Services\\n\\n\" +\n \"If omitted, returns all symbols.\"\n ),\n \n language: z.string()\n .optional()\n .describe(\n \"Filter by programming language.\\n\\n\" +\n \"Examples: 'typescript', 'python', 'javascript', 'php'\\n\\n\" +\n \"If omitted, searches all languages.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for list functions input\n */\nexport type ListFunctionsInput = z.infer<typeof ListFunctionsSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_dependents tool input.\n * \n * Validates file paths and options for finding reverse dependencies\n * (which files import/depend on a given file).\n * \n * Limitations:\n * - Scans up to 10,000 code chunks. For very large codebases (>1M lines),\n * results may be incomplete. A warning is returned if the limit is reached.\n */\nexport const GetDependentsSchema = z.object({\n filepath: z.string()\n .min(1, \"Filepath cannot be empty\")\n .describe(\n \"Path to file to find dependents for (relative to workspace root).\\n\\n\" +\n \"Example: 'src/utils/validate.ts'\\n\\n\" +\n \"Returns all files that import or depend on this file.\\n\\n\" +\n \"Note: Scans up to 10,000 code chunks. For very large codebases,\\n\" +\n \"results may be incomplete (a warning will be included if truncated).\"\n ),\n \n depth: z.number()\n .int()\n .min(1)\n .max(1)\n .default(1)\n .describe(\n \"Depth of transitive dependencies. Only depth=1 (direct dependents) is currently supported.\\n\\n\" +\n \"1 = Direct dependents only\"\n ),\n});\n\n/**\n * Inferred TypeScript type for get_dependents input\n */\nexport type GetDependentsInput = z.infer<typeof GetDependentsSchema>;\n\n","import { z } from 'zod';\n\n/**\n * Schema for get_complexity tool input.\n * \n * Validates parameters for complexity analysis queries,\n * enabling tech debt analysis and refactoring prioritization.\n */\nexport const GetComplexitySchema = z.object({\n files: z.array(z.string().min(1, \"Filepath cannot be empty\"))\n .optional()\n .describe(\n \"Specific files to analyze. If omitted, analyzes entire codebase.\\n\\n\" +\n \"Example: ['src/auth.ts', 'src/api/user.ts']\"\n ),\n \n top: z.number()\n .int()\n .min(1, \"Top must be at least 1\")\n .max(50, \"Top cannot exceed 50\")\n .default(10)\n .describe(\n \"Return top N most complex functions. Default: 10\\n\\n\" +\n \"Use higher values to see more violations.\"\n ),\n \n threshold: z.number()\n .int()\n .min(1, \"Threshold must be at least 1\")\n .optional()\n .describe(\n \"Only return functions above this complexity threshold.\\n\\n\" +\n \"Note: Violations are first identified using the threshold from lien.config.json (default: 15). \" +\n \"This parameter filters those violations to show only items above the specified value. \" +\n \"Setting threshold below the config threshold will not show additional functions.\"\n ),\n});\n\n/**\n * Inferred TypeScript type for get_complexity input\n */\nexport type GetComplexityInput = z.infer<typeof GetComplexitySchema>;\n\n","import { toMCPToolSchema } from './utils/zod-to-json-schema.js';\nimport {\n SemanticSearchSchema,\n FindSimilarSchema,\n GetFilesContextSchema,\n ListFunctionsSchema,\n GetDependentsSchema,\n GetComplexitySchema,\n} from './schemas/index.js';\n\n/**\n * MCP tool definitions with Zod-generated schemas.\n * \n * All schemas are automatically generated from Zod definitions,\n * providing type safety and rich validation at runtime.\n */\nexport const tools = [\n toMCPToolSchema(\n SemanticSearchSchema,\n 'semantic_search',\n `Search codebase by MEANING, not text. USE THIS INSTEAD OF grep/ripgrep for finding implementations, features, or understanding how code works.\n\nExamples:\n- \"Where is authentication handled?\" → semantic_search({ query: \"handles user authentication\" })\n- \"How does payment work?\" → semantic_search({ query: \"processes payment transactions\" })\n\nUse natural language describing what the code DOES, not function names. For exact string matching, use grep instead.\n\nResults include a relevance category (highly_relevant, relevant, loosely_related, not_relevant) for each match.`\n ),\n toMCPToolSchema(\n FindSimilarSchema,\n 'find_similar',\n `Find code structurally similar to a given snippet. Use for:\n- Ensuring consistency when adding new code\n- Finding duplicate implementations\n- Refactoring similar patterns together\n\nProvide at least 10 characters of code to match against. Results include a relevance category for each match.`\n ),\n toMCPToolSchema(\n GetFilesContextSchema,\n 'get_files_context',\n `Get context for one or more files including dependencies and test coverage.\n\nMANDATORY: Call this BEFORE editing any file. Accepts single path or array of paths.\n\nSingle file:\n get_files_context({ filepaths: \"src/auth.ts\" })\n \n Returns:\n {\n file: \"src/auth.ts\",\n chunks: [...],\n testAssociations: [\"src/__tests__/auth.test.ts\"]\n }\n\nMultiple files (batch):\n get_files_context({ filepaths: [\"src/auth.ts\", \"src/user.ts\"] })\n \n Returns:\n {\n files: {\n \"src/auth.ts\": {\n chunks: [...],\n testAssociations: [\"src/__tests__/auth.test.ts\"]\n },\n \"src/user.ts\": {\n chunks: [...],\n testAssociations: [\"src/__tests__/user.test.ts\"]\n }\n }\n }\n\nReturns for each file:\n- All chunks and related code\n- testAssociations: Array of test files that import this file (reverse dependency lookup)\n- Relevance scoring\n\nALWAYS check testAssociations before modifying source code.\nAfter changes, remind the user to run the associated tests.\n\nBatch calls are more efficient than multiple single-file calls.`\n ),\n toMCPToolSchema(\n ListFunctionsSchema,\n 'list_functions',\n `Fast symbol lookup by naming pattern. Use when searching by NAME, not behavior.\n\nExamples:\n- \"Show all controllers\" → list_functions({ pattern: \".*Controller.*\" })\n- \"Find service classes\" → list_functions({ pattern: \".*Service$\" })\n\n10x faster than semantic_search for structural/architectural queries. Use semantic_search instead when searching by what code DOES.`\n ),\n toMCPToolSchema(\n GetDependentsSchema,\n 'get_dependents',\n `Find all code that depends on a file (reverse dependency lookup). Use for impact analysis:\n- \"What breaks if I change this?\"\n- \"Is this safe to delete?\"\n- \"What imports this module?\"\n\nReturns:\n- List of files that import the target\n- Risk level (low/medium/high/critical) based on dependent count and complexity\n\nExample: get_dependents({ filepath: \"src/utils/validate.ts\" })`\n ),\n toMCPToolSchema(\n GetComplexitySchema,\n 'get_complexity',\n `Get complexity analysis for files or the entire codebase.\n\nAnalyzes multiple complexity metrics:\n- **Test paths**: Number of test cases needed for full coverage (cyclomatic)\n- **Mental load**: How hard to follow - penalizes nesting (cognitive)\n- **Time to understand**: Estimated reading time based on Halstead effort\n- **Estimated bugs**: Predicted bug count based on Halstead volume\n\nUse for tech debt analysis and refactoring prioritization:\n- \"What are the most complex functions?\"\n- \"Show me tech debt hotspots\"\n- \"What should I refactor?\"\n\nExamples:\n get_complexity({ top: 10 })\n get_complexity({ files: [\"src/auth.ts\", \"src/api/user.ts\"] })\n get_complexity({ threshold: 15 })\n\nReturns violations with metricType ('cyclomatic', 'cognitive', 'halstead_effort',\nor 'halstead_bugs'), risk levels, and dependent counts.\nHuman-readable output: \"23 (needs ~23 tests)\", \"🧠 45\", \"~2h 30m\", \"2.27 bugs\".`\n ),\n];","import { ZodSchema, ZodError } from 'zod';\nimport { LienError, LienErrorCode } from '../../errors/index.js';\n\n/**\n * Wrap a tool handler with Zod validation and error handling.\n * \n * This utility provides automatic:\n * - Input validation using Zod schemas\n * - Type-safe handler execution with inferred types\n * - Consistent error formatting for validation, Lien, and unexpected errors\n * - MCP-compatible response structure\n * \n * @param schema - Zod schema to validate tool inputs against\n * @param handler - Tool handler function that receives validated inputs\n * @returns Wrapped handler that validates inputs and handles errors\n * \n * @example\n * ```typescript\n * const SearchSchema = z.object({\n * query: z.string().min(3),\n * limit: z.number().default(5)\n * });\n * \n * const searchHandler = wrapToolHandler(\n * SearchSchema,\n * async (args) => {\n * // args is fully typed: { query: string; limit: number }\n * const results = await search(args.query, args.limit);\n * return { results };\n * }\n * );\n * \n * // Use in MCP server\n * return await searchHandler(request.params.arguments);\n * ```\n */\nexport function wrapToolHandler<T>(\n schema: ZodSchema<T>,\n handler: (validated: T) => Promise<any>\n) {\n return async (args: unknown) => {\n try {\n // Validate input with Zod\n const validated = schema.parse(args);\n \n // Execute handler with validated, typed input\n const result = await handler(validated);\n \n // Return MCP-compatible success response\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify(result, null, 2),\n }],\n };\n \n } catch (error) {\n // Handle Zod validation errors\n if (error instanceof ZodError) {\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: 'Invalid parameters',\n code: LienErrorCode.INVALID_INPUT,\n details: error.errors.map(e => ({\n field: e.path.join('.'),\n message: e.message,\n })),\n }, null, 2),\n }],\n };\n }\n \n // Handle known Lien errors\n if (error instanceof LienError) {\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify(error.toJSON(), null, 2),\n }],\n };\n }\n \n // Handle unexpected errors\n console.error('Unexpected error in tool handler:', error);\n return {\n isError: true,\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n error: error instanceof Error ? error.message : 'Unknown error',\n code: LienErrorCode.INTERNAL_ERROR,\n }, null, 2),\n }],\n };\n }\n };\n}\n\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { SemanticSearchSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle semantic_search tool calls.\n * Searches the codebase by meaning using embeddings.\n */\nexport async function handleSemanticSearch(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n SemanticSearchSchema,\n async (validatedArgs) => {\n log(`Searching for: \"${validatedArgs.query}\"`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n const queryEmbedding = await embeddings.embed(validatedArgs.query);\n const results = await vectorDB.search(queryEmbedding, validatedArgs.limit, validatedArgs.query);\n\n log(`Found ${results.length} results`);\n\n return {\n indexInfo: getIndexMetadata(),\n results,\n };\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { FindSimilarSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle find_similar tool calls.\n * Finds code structurally similar to a given snippet.\n */\nexport async function handleFindSimilar(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n FindSimilarSchema,\n async (validatedArgs) => {\n log(`Finding similar code...`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n const codeEmbedding = await embeddings.embed(validatedArgs.code);\n // Pass code as query for relevance boosting\n const results = await vectorDB.search(codeEmbedding, validatedArgs.limit, validatedArgs.code);\n\n log(`Found ${results.length} similar chunks`);\n\n return {\n indexInfo: getIndexMetadata(),\n results,\n };\n }\n )(args);\n}\n","/**\n * Shared path matching utilities for dependency analysis.\n * \n * These functions handle path normalization and matching logic used by\n * the get_dependents tool to find reverse dependencies.\n */\n\n/**\n * Normalizes a file path for comparison.\n * \n * - Removes quotes and trims whitespace\n * - Converts backslashes to forward slashes\n * - Strips file extensions (.ts, .tsx, .js, .jsx)\n * - Converts absolute paths to relative (if within workspace root)\n * \n * @param path - The path to normalize\n * @param workspaceRoot - The workspace root directory (normalized with forward slashes)\n * @returns Normalized path\n */\nexport function normalizePath(path: string, workspaceRoot: string): string {\n let normalized = path.replace(/['\"]/g, '').trim().replace(/\\\\/g, '/');\n \n // Normalize extensions: .ts/.tsx/.js/.jsx → all treated as equivalent\n // This handles TypeScript's ESM requirement of .js imports for .ts files\n normalized = normalized.replace(/\\.(ts|tsx|js|jsx)$/, '');\n \n // Normalize to relative path if it starts with workspace root\n if (normalized.startsWith(workspaceRoot + '/')) {\n normalized = normalized.substring(workspaceRoot.length + 1);\n }\n \n return normalized;\n}\n\n/**\n * Checks if a pattern matches at path component boundaries.\n * \n * Ensures matches occur at proper boundaries (/, .) to avoid false positives like:\n * - \"logger\" matching \"logger-utils\" ❌\n * - \"src/logger\" matching \"src/logger-service\" ❌\n * \n * @param str - The string to search in\n * @param pattern - The pattern to search for\n * @returns True if pattern matches at a boundary\n */\nexport function matchesAtBoundary(str: string, pattern: string): boolean {\n const index = str.indexOf(pattern);\n if (index === -1) return false;\n \n // Check character before match (must be start or path separator)\n const charBefore = index > 0 ? str[index - 1] : '/';\n if (charBefore !== '/' && index !== 0) return false;\n \n // Check character after match (must be end or path separator)\n // Extensions are already stripped during normalization, so we only need to check for '/' as a valid path separator\n const endIndex = index + pattern.length;\n if (endIndex === str.length) return true;\n const charAfter = str[endIndex];\n return charAfter === '/';\n}\n\n/**\n * Determines if an import path matches a target file path.\n * \n * Handles various matching strategies:\n * 1. Exact match\n * 2. Target path appears in import (at boundaries)\n * 3. Import path appears in target (at boundaries)\n * 4. Relative imports (./logger vs src/utils/logger)\n * \n * @param normalizedImport - Normalized import path\n * @param normalizedTarget - Normalized target file path\n * @returns True if the import matches the target file\n */\nexport function matchesFile(normalizedImport: string, normalizedTarget: string): boolean {\n // Exact match\n if (normalizedImport === normalizedTarget) return true;\n \n // Strategy 1: Check if target path appears in import at path boundaries\n if (matchesAtBoundary(normalizedImport, normalizedTarget)) {\n return true;\n }\n \n // Strategy 2: Check if import path appears in target (for longer target paths)\n if (matchesAtBoundary(normalizedTarget, normalizedImport)) {\n return true;\n }\n \n // Strategy 3: Handle relative imports (./logger vs src/utils/logger)\n // Remove leading ./ and ../ from import\n const cleanedImport = normalizedImport.replace(/^(\\.\\.?\\/)+/, '');\n if (matchesAtBoundary(cleanedImport, normalizedTarget) || \n matchesAtBoundary(normalizedTarget, cleanedImport)) {\n return true;\n }\n \n return false;\n}\n\n/**\n * Gets a canonical path representation (relative to workspace, with extension).\n * \n * @param filepath - The file path to canonicalize\n * @param workspaceRoot - The workspace root directory (normalized with forward slashes)\n * @returns Canonical path\n */\nexport function getCanonicalPath(filepath: string, workspaceRoot: string): string {\n let canonical = filepath.replace(/\\\\/g, '/');\n if (canonical.startsWith(workspaceRoot + '/')) {\n canonical = canonical.substring(workspaceRoot.length + 1);\n }\n return canonical;\n}\n\n/**\n * Determines if a file is a test file based on naming conventions.\n * \n * Uses precise regex patterns to avoid false positives:\n * - Files with .test. or .spec. extensions (e.g., foo.test.ts, bar.spec.js)\n * - Files in test/, tests/, or __tests__/ directories\n * \n * Avoids false positives like:\n * - contest.ts (contains \".test.\" but isn't a test)\n * - latest/config.ts (contains \"/test/\" but isn't a test)\n * \n * @param filepath - The file path to check\n * @returns True if the file is a test file\n */\nexport function isTestFile(filepath: string): boolean {\n return /\\.(test|spec)\\.[^/]+$/.test(filepath) ||\n /(^|[/\\\\])(test|tests|__tests__)[/\\\\]/.test(filepath);\n}\n\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetFilesContextSchema } from '../schemas/index.js';\nimport { normalizePath, matchesFile, getCanonicalPath, isTestFile } from '../utils/path-matching.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Maximum number of chunks to scan for test association analysis.\n * Larger codebases may have incomplete results if they exceed this limit.\n */\nconst SCAN_LIMIT = 10000;\n\n/**\n * Handle get_files_context tool calls.\n * Gets context for one or more files including dependencies and test coverage.\n */\nexport async function handleGetFilesContext(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, embeddings, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetFilesContextSchema,\n async (validatedArgs) => {\n // Normalize input: convert single string to array\n const filepaths = Array.isArray(validatedArgs.filepaths)\n ? validatedArgs.filepaths\n : [validatedArgs.filepaths];\n\n const isSingleFile = !Array.isArray(validatedArgs.filepaths);\n\n log(`Getting context for: ${filepaths.join(', ')}`);\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n // Compute workspace root for path matching\n const workspaceRoot = process.cwd().replace(/\\\\/g, '/');\n\n // Batch embedding calls for all filepaths at once to reduce latency\n const fileEmbeddings = await Promise.all(filepaths.map(fp => embeddings.embed(fp)));\n\n // Batch all initial file searches in parallel\n const allFileSearches = await Promise.all(\n fileEmbeddings.map((embedding, i) =>\n vectorDB.search(embedding, 50, filepaths[i])\n )\n );\n\n // Filter results to only include chunks from each target file\n // Use exact matching with getCanonicalPath to avoid false positives\n const fileChunksMap = filepaths.map((filepath, i) => {\n const allResults = allFileSearches[i];\n const targetCanonical = getCanonicalPath(filepath, workspaceRoot);\n\n return allResults.filter(r => {\n const chunkCanonical = getCanonicalPath(r.metadata.file, workspaceRoot);\n return chunkCanonical === targetCanonical;\n });\n });\n\n // Batch related chunk operations if includeRelated is true\n let relatedChunksMap: any[][] = [];\n if (validatedArgs.includeRelated) {\n // Get files that have chunks (need first chunk for related search)\n const filesWithChunks = fileChunksMap\n .map((chunks, i) => ({ chunks, filepath: filepaths[i], index: i }))\n .filter(({ chunks }) => chunks.length > 0);\n\n if (filesWithChunks.length > 0) {\n // Batch embedding calls for all first chunks\n const relatedEmbeddings = await Promise.all(\n filesWithChunks.map(({ chunks }) => embeddings.embed(chunks[0].content))\n );\n\n // Batch all related chunk searches\n const relatedSearches = await Promise.all(\n relatedEmbeddings.map((embedding, i) =>\n vectorDB.search(embedding, 5, filesWithChunks[i].chunks[0].content)\n )\n );\n\n // Map back to original indices\n relatedChunksMap = Array.from({ length: filepaths.length }, () => []);\n filesWithChunks.forEach(({ filepath, index }, i) => {\n const related = relatedSearches[i];\n const targetCanonical = getCanonicalPath(filepath, workspaceRoot);\n // Filter out chunks from the same file using exact matching\n relatedChunksMap[index] = related.filter(r => {\n const chunkCanonical = getCanonicalPath(r.metadata.file, workspaceRoot);\n return chunkCanonical !== targetCanonical;\n });\n });\n }\n }\n\n // Compute test associations for each file\n // Scan once for all files to avoid repeated database queries (performance optimization)\n const allChunks = await vectorDB.scanWithFilter({ limit: SCAN_LIMIT });\n\n // Warn if we hit the limit (similar to get_dependents tool)\n if (allChunks.length === SCAN_LIMIT) {\n log(`Scanned ${SCAN_LIMIT} chunks (limit reached). Test associations may be incomplete for large codebases.`, 'warning');\n }\n\n // Path normalization cache to avoid repeated string operations\n const pathCache = new Map<string, string>();\n const normalizePathCached = (path: string): string => {\n if (pathCache.has(path)) return pathCache.get(path)!;\n const normalized = normalizePath(path, workspaceRoot);\n pathCache.set(path, normalized);\n return normalized;\n };\n\n // Compute test associations for each file using the same scan result\n const testAssociationsMap = filepaths.map((filepath) => {\n const normalizedTarget = normalizePathCached(filepath);\n\n // Find chunks that:\n // 1. Are from test files\n // 2. Import the target file\n const testFiles = new Set<string>();\n for (const chunk of allChunks) {\n const chunkFile = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n\n // Skip if not a test file\n if (!isTestFile(chunkFile)) continue;\n\n // Check if this test file imports the target\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n if (matchesFile(normalizedImport, normalizedTarget)) {\n testFiles.add(chunkFile);\n break;\n }\n }\n }\n\n return Array.from(testFiles);\n });\n\n // Combine file chunks with related chunks and test associations\n const filesData: Record<string, { chunks: any[]; testAssociations: string[] }> = {};\n filepaths.forEach((filepath, i) => {\n const fileChunks = fileChunksMap[i];\n const relatedChunks = relatedChunksMap[i] || [];\n\n // Deduplicate chunks (by canonical file path + line range)\n // Use canonical paths to avoid duplicates from absolute vs relative paths\n const seenChunks = new Set<string>();\n const dedupedChunks = [...fileChunks, ...relatedChunks].filter(chunk => {\n const canonicalFile = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n const chunkId = `${canonicalFile}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (seenChunks.has(chunkId)) return false;\n seenChunks.add(chunkId);\n return true;\n });\n\n filesData[filepath] = {\n chunks: dedupedChunks,\n testAssociations: testAssociationsMap[i],\n };\n });\n\n log(`Found ${Object.values(filesData).reduce((sum, f) => sum + f.chunks.length, 0)} total chunks`);\n\n // Return format depends on single vs multi file\n if (isSingleFile) {\n // Single file: return old format for backward compatibility\n const filepath = filepaths[0];\n return {\n indexInfo: getIndexMetadata(),\n file: filepath,\n chunks: filesData[filepath].chunks,\n testAssociations: filesData[filepath].testAssociations,\n };\n } else {\n // Multiple files: return new format\n return {\n indexInfo: getIndexMetadata(),\n files: filesData,\n };\n }\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { ListFunctionsSchema } from '../schemas/index.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\n\n/**\n * Handle list_functions tool calls.\n * Fast symbol lookup by naming pattern.\n */\nexport async function handleListFunctions(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n ListFunctionsSchema,\n async (validatedArgs) => {\n log('Listing functions with symbol metadata...');\n\n // Check if index has been updated and reconnect if needed\n await checkAndReconnect();\n\n let results;\n let usedMethod = 'symbols';\n\n try {\n // Try using symbol-based query first (v0.5.0+)\n results = await vectorDB.querySymbols({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n\n // If no results and pattern was provided, it might be an old index\n // Fall back to content scanning\n if (results.length === 0 && (validatedArgs.language || validatedArgs.pattern)) {\n log('No symbol results, falling back to content scan...');\n results = await vectorDB.scanWithFilter({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n usedMethod = 'content';\n }\n } catch (error) {\n // If querySymbols fails (e.g., old index without symbol fields), fall back\n log(`Symbol query failed, falling back to content scan: ${error}`);\n results = await vectorDB.scanWithFilter({\n language: validatedArgs.language,\n pattern: validatedArgs.pattern,\n limit: 50,\n });\n usedMethod = 'content';\n }\n\n log(`Found ${results.length} matches using ${usedMethod} method`);\n\n return {\n indexInfo: getIndexMetadata(),\n method: usedMethod,\n results,\n note: usedMethod === 'content'\n ? 'Using content search. Run \"lien reindex\" to enable faster symbol-based queries.'\n : undefined,\n };\n }\n )(args);\n}\n","import { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetDependentsSchema } from '../schemas/index.js';\nimport { normalizePath, matchesFile, getCanonicalPath, isTestFile } from '../utils/path-matching.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\nimport type { SearchResult } from '../../vectordb/types.js';\n\n/**\n * Complexity metrics for a single dependent file.\n */\ninterface FileComplexity {\n filepath: string;\n avgComplexity: number;\n maxComplexity: number;\n complexityScore: number; // Sum of all complexities\n chunksWithComplexity: number;\n}\n\n/**\n * Aggregate complexity metrics for all dependents.\n */\ninterface ComplexityMetrics {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n highComplexityDependents: Array<{\n filepath: string;\n maxComplexity: number;\n avgComplexity: number;\n }>;\n complexityRiskBoost: 'low' | 'medium' | 'high' | 'critical';\n}\n\n/**\n * Risk level thresholds for dependent count.\n * Based on impact analysis: more dependents = higher risk of breaking changes.\n */\nconst DEPENDENT_COUNT_THRESHOLDS = {\n LOW: 5, // Few dependents, safe to change\n MEDIUM: 15, // Moderate impact, review dependents\n HIGH: 30, // High impact, careful planning needed\n} as const;\n\n/**\n * Complexity thresholds for risk assessment.\n * Based on cyclomatic complexity: higher complexity = harder to change safely.\n */\nconst COMPLEXITY_THRESHOLDS = {\n HIGH_COMPLEXITY_DEPENDENT: 10, // Individual file is complex\n CRITICAL_AVG: 15, // Average complexity indicates systemic complexity\n CRITICAL_MAX: 25, // Peak complexity indicates hotspot\n HIGH_AVG: 10, // Moderately complex on average\n HIGH_MAX: 20, // Some complex functions exist\n MEDIUM_AVG: 6, // Slightly above simple code\n MEDIUM_MAX: 15, // Occasional branching\n} as const;\n\n/**\n * Maximum number of chunks to scan for dependency analysis.\n * Larger codebases may have incomplete results if they exceed this limit.\n */\nconst SCAN_LIMIT = 10000;\n\n/** Risk level ordering for comparison */\nconst RISK_ORDER = { low: 0, medium: 1, high: 2, critical: 3 } as const;\ntype RiskLevel = keyof typeof RISK_ORDER;\n\n/**\n * Build import-to-chunk index for O(n) instead of O(n*m) lookup.\n */\nfunction buildImportIndex(\n allChunks: SearchResult[],\n normalizePathCached: (path: string) => string\n): Map<string, SearchResult[]> {\n const importIndex = new Map<string, SearchResult[]>();\n \n for (const chunk of allChunks) {\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n if (!importIndex.has(normalizedImport)) {\n importIndex.set(normalizedImport, []);\n }\n importIndex.get(normalizedImport)!.push(chunk);\n }\n }\n \n return importIndex;\n}\n\n/**\n * Find dependent chunks using direct lookup and fuzzy matching.\n */\nfunction findDependentChunks(\n importIndex: Map<string, SearchResult[]>,\n normalizedTarget: string\n): SearchResult[] {\n const dependentChunks: SearchResult[] = [];\n const seenChunkIds = new Set<string>();\n\n const addChunk = (chunk: SearchResult) => {\n const chunkId = `${chunk.metadata.file}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (!seenChunkIds.has(chunkId)) {\n dependentChunks.push(chunk);\n seenChunkIds.add(chunkId);\n }\n };\n\n // Direct index lookup (fastest path)\n if (importIndex.has(normalizedTarget)) {\n for (const chunk of importIndex.get(normalizedTarget)!) {\n addChunk(chunk);\n }\n }\n\n // Fuzzy match for relative imports and path variations\n for (const [normalizedImport, chunks] of importIndex.entries()) {\n if (normalizedImport !== normalizedTarget && matchesFile(normalizedImport, normalizedTarget)) {\n for (const chunk of chunks) {\n addChunk(chunk);\n }\n }\n }\n\n return dependentChunks;\n}\n\n/**\n * Calculate complexity metrics for each file from its chunks.\n */\nfunction calculateFileComplexities(\n chunksByFile: Map<string, SearchResult[]>\n): FileComplexity[] {\n const fileComplexities: FileComplexity[] = [];\n\n for (const [filepath, chunks] of chunksByFile.entries()) {\n const complexities = chunks\n .map(c => c.metadata.complexity)\n .filter((c): c is number => typeof c === 'number' && c > 0);\n\n if (complexities.length > 0) {\n const sum = complexities.reduce((a, b) => a + b, 0);\n fileComplexities.push({\n filepath,\n avgComplexity: Math.round((sum / complexities.length) * 10) / 10,\n maxComplexity: Math.max(...complexities),\n complexityScore: sum,\n chunksWithComplexity: complexities.length,\n });\n }\n }\n\n return fileComplexities;\n}\n\n/**\n * Calculate overall complexity metrics from per-file complexities.\n */\nfunction calculateOverallComplexityMetrics(\n fileComplexities: FileComplexity[]\n): ComplexityMetrics {\n if (fileComplexities.length === 0) {\n return {\n averageComplexity: 0,\n maxComplexity: 0,\n filesWithComplexityData: 0,\n highComplexityDependents: [],\n complexityRiskBoost: 'low',\n };\n }\n\n const allAvgs = fileComplexities.map(f => f.avgComplexity);\n const allMaxes = fileComplexities.map(f => f.maxComplexity);\n const totalAvg = allAvgs.reduce((a, b) => a + b, 0) / allAvgs.length;\n const globalMax = Math.max(...allMaxes);\n\n const highComplexityDependents = fileComplexities\n .filter(f => f.maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_COMPLEXITY_DEPENDENT)\n .sort((a, b) => b.maxComplexity - a.maxComplexity)\n .slice(0, 5)\n .map(f => ({ filepath: f.filepath, maxComplexity: f.maxComplexity, avgComplexity: f.avgComplexity }));\n\n const complexityRiskBoost = calculateComplexityRiskBoost(totalAvg, globalMax);\n\n return {\n averageComplexity: Math.round(totalAvg * 10) / 10,\n maxComplexity: globalMax,\n filesWithComplexityData: fileComplexities.length,\n highComplexityDependents,\n complexityRiskBoost,\n };\n}\n\n/**\n * Calculate complexity-based risk boost level.\n */\nfunction calculateComplexityRiskBoost(avgComplexity: number, maxComplexity: number): RiskLevel {\n if (avgComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_MAX) {\n return 'critical';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.HIGH_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_MAX) {\n return 'high';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_MAX) {\n return 'medium';\n }\n return 'low';\n}\n\n/**\n * Calculate risk level based on dependent count and complexity.\n */\nfunction calculateRiskLevel(dependentCount: number, complexityRiskBoost: RiskLevel): RiskLevel {\n let riskLevel: RiskLevel =\n dependentCount === 0 ? 'low' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.LOW ? 'low' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.MEDIUM ? 'medium' :\n dependentCount <= DEPENDENT_COUNT_THRESHOLDS.HIGH ? 'high' : 'critical';\n\n // Boost if complexity risk is higher\n if (RISK_ORDER[complexityRiskBoost] > RISK_ORDER[riskLevel]) {\n riskLevel = complexityRiskBoost;\n }\n\n return riskLevel;\n}\n\n/**\n * Handle get_dependents tool calls.\n * Finds all code that depends on a file (reverse dependency lookup).\n */\nexport async function handleGetDependents(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetDependentsSchema,\n async (validatedArgs) => {\n log(`Finding dependents of: ${validatedArgs.filepath}`);\n await checkAndReconnect();\n\n const allChunks = await vectorDB.scanWithFilter({ limit: SCAN_LIMIT });\n const hitLimit = allChunks.length === SCAN_LIMIT;\n if (hitLimit) {\n log(`Scanned ${SCAN_LIMIT} chunks (limit reached). Results may be incomplete.`, 'warning');\n }\n log(`Scanning ${allChunks.length} chunks for imports...`);\n\n const workspaceRoot = process.cwd().replace(/\\\\/g, '/');\n const pathCache = new Map<string, string>();\n const normalizePathCached = (path: string): string => {\n if (!pathCache.has(path)) pathCache.set(path, normalizePath(path, workspaceRoot));\n return pathCache.get(path)!;\n };\n\n // Build index and find dependents\n const importIndex = buildImportIndex(allChunks, normalizePathCached);\n const normalizedTarget = normalizePathCached(validatedArgs.filepath);\n const dependentChunks = findDependentChunks(importIndex, normalizedTarget);\n\n // Group by canonical file path\n const chunksByFile = new Map<string, typeof dependentChunks>();\n for (const chunk of dependentChunks) {\n const canonical = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n const existing = chunksByFile.get(canonical) || [];\n existing.push(chunk);\n chunksByFile.set(canonical, existing);\n }\n\n // Calculate metrics\n const fileComplexities = calculateFileComplexities(chunksByFile);\n const complexityMetrics = calculateOverallComplexityMetrics(fileComplexities);\n\n const uniqueFiles = Array.from(chunksByFile.keys()).map(filepath => ({\n filepath,\n isTestFile: isTestFile(filepath),\n }));\n\n const riskLevel = calculateRiskLevel(uniqueFiles.length, complexityMetrics.complexityRiskBoost);\n log(`Found ${uniqueFiles.length} dependent files (risk: ${riskLevel}${complexityMetrics.filesWithComplexityData > 0 ? ', complexity-boosted' : ''})`);\n\n return {\n indexInfo: getIndexMetadata(),\n filepath: validatedArgs.filepath,\n dependentCount: uniqueFiles.length,\n riskLevel,\n dependents: uniqueFiles,\n complexityMetrics,\n note: hitLimit ? `Warning: Scanned ${SCAN_LIMIT} chunks (limit reached). Results may be incomplete.` : undefined,\n };\n }\n )(args);\n}\n","import collect from 'collect.js';\nimport { wrapToolHandler } from '../utils/tool-wrapper.js';\nimport { GetComplexitySchema } from '../schemas/index.js';\nimport { ComplexityAnalyzer } from '../../insights/complexity-analyzer.js';\nimport type { ToolContext, MCPToolResult } from '../types.js';\nimport type { ComplexityViolation, FileComplexityData } from '../../insights/types.js';\n\n/**\n * Transform a violation with file-level metadata for API response\n */\nfunction transformViolation(v: ComplexityViolation, fileData: FileComplexityData) {\n return {\n filepath: v.filepath,\n symbolName: v.symbolName,\n symbolType: v.symbolType,\n startLine: v.startLine,\n endLine: v.endLine,\n complexity: v.complexity,\n metricType: v.metricType,\n threshold: v.threshold,\n severity: v.severity,\n language: v.language,\n message: v.message,\n dependentCount: fileData.dependentCount || 0,\n riskLevel: fileData.riskLevel,\n ...(v.halsteadDetails && { halsteadDetails: v.halsteadDetails }),\n };\n}\n\n/**\n * Handle get_complexity tool calls.\n * Analyzes complexity for files or the entire codebase.\n */\nexport async function handleGetComplexity(\n args: unknown,\n ctx: ToolContext\n): Promise<MCPToolResult> {\n const { vectorDB, config, log, checkAndReconnect, getIndexMetadata } = ctx;\n\n return await wrapToolHandler(\n GetComplexitySchema,\n async (validatedArgs) => {\n log('Analyzing complexity...');\n await checkAndReconnect();\n\n const analyzer = new ComplexityAnalyzer(vectorDB, config);\n const report = await analyzer.analyze(validatedArgs.files);\n log(`Analyzed ${report.summary.filesAnalyzed} files`);\n\n // Transform violations using collect.js\n type TransformedViolation = ReturnType<typeof transformViolation>;\n const allViolations: TransformedViolation[] = collect(Object.entries(report.files))\n .flatMap(([/* filepath unused */, fileData]) => \n fileData.violations.map(v => transformViolation(v, fileData))\n )\n .sortByDesc('complexity')\n .all() as unknown as TransformedViolation[];\n\n // Apply custom threshold filter if provided\n const violations = validatedArgs.threshold !== undefined\n ? allViolations.filter(v => v.complexity >= validatedArgs.threshold!)\n : allViolations;\n\n const topViolations = violations.slice(0, validatedArgs.top);\n\n // Calculate severity counts - countBy returns { error?: number, warning?: number }\n const bySeverity = collect(violations).countBy('severity').all() as { error?: number; warning?: number };\n\n return {\n indexInfo: getIndexMetadata(),\n summary: {\n filesAnalyzed: report.summary.filesAnalyzed,\n avgComplexity: report.summary.avgComplexity,\n maxComplexity: report.summary.maxComplexity,\n violationCount: violations.length,\n bySeverity: {\n error: bySeverity['error'] || 0,\n warning: bySeverity['warning'] || 0,\n },\n },\n violations: topViolations,\n };\n }\n )(args);\n}\n","/**\n * Complexity analysis types for code quality insights\n */\n\n/**\n * Risk level ordering for comparison operations.\n * Higher value = higher risk.\n */\nexport const RISK_ORDER = { low: 0, medium: 1, high: 2, critical: 3 } as const;\n\n/**\n * Risk level type derived from RISK_ORDER keys\n */\nexport type RiskLevel = keyof typeof RISK_ORDER;\n\n/**\n * Type of complexity metric being measured\n */\nexport type ComplexityMetricType = 'cyclomatic' | 'cognitive' | 'halstead_effort' | 'halstead_bugs';\n\n/**\n * Halstead metric details for Halstead-type violations\n */\nexport interface HalsteadDetails {\n volume: number;\n difficulty: number;\n effort: number;\n bugs: number;\n}\n\nexport interface ComplexityViolation {\n filepath: string;\n startLine: number;\n endLine: number;\n symbolName: string;\n symbolType: 'function' | 'method' | 'class' | 'file';\n language: string;\n complexity: number;\n threshold: number;\n severity: 'warning' | 'error';\n message: string;\n /** Type of complexity metric (cyclomatic vs cognitive vs halstead) */\n metricType: ComplexityMetricType;\n /** Halstead-specific details when metricType is halstead_* */\n halsteadDetails?: HalsteadDetails;\n}\n\nexport interface FileComplexityData {\n violations: ComplexityViolation[];\n dependents: string[];\n dependentCount?: number;\n /** Test files associated with this source file. TODO: Populate when test-to-code mapping is implemented */\n testAssociations: string[];\n riskLevel: RiskLevel;\n dependentComplexityMetrics?: {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n };\n}\n\nexport interface ComplexityReport {\n summary: {\n filesAnalyzed: number;\n totalViolations: number;\n bySeverity: { error: number; warning: number };\n avgComplexity: number;\n maxComplexity: number;\n };\n files: Record<string, FileComplexityData>;\n}\n\n","import { SearchResult } from '../vectordb/types.js';\nimport { normalizePath, getCanonicalPath, matchesFile, isTestFile } from '../mcp/utils/path-matching.js';\nimport { RISK_ORDER, RiskLevel } from '../insights/types.js';\n\n/**\n * Risk level thresholds for dependent count.\n * Based on impact analysis: more dependents = higher risk of breaking changes.\n */\nexport const DEPENDENT_COUNT_THRESHOLDS = {\n LOW: 5, // Few dependents, safe to change\n MEDIUM: 15, // Moderate impact, review dependents\n HIGH: 30, // High impact, careful planning needed\n} as const;\n\n/**\n * Complexity thresholds for risk assessment.\n * Based on cyclomatic complexity: higher complexity = harder to change safely.\n */\nexport const COMPLEXITY_THRESHOLDS = {\n HIGH_COMPLEXITY_DEPENDENT: 10, // Individual file is complex\n CRITICAL_AVG: 15, // Average complexity indicates systemic complexity\n CRITICAL_MAX: 25, // Peak complexity indicates hotspot\n HIGH_AVG: 10, // Moderately complex on average\n HIGH_MAX: 20, // Some complex functions exist\n MEDIUM_AVG: 6, // Slightly above simple code\n MEDIUM_MAX: 15, // Occasional branching\n} as const;\n\nexport interface FileComplexityInfo {\n filepath: string;\n avgComplexity: number;\n maxComplexity: number;\n complexityScore: number;\n chunksWithComplexity: number;\n}\n\nexport interface DependencyAnalysisResult {\n dependents: Array<{\n filepath: string;\n isTestFile: boolean;\n }>;\n dependentCount: number;\n riskLevel: RiskLevel;\n complexityMetrics?: {\n averageComplexity: number;\n maxComplexity: number;\n filesWithComplexityData: number;\n highComplexityDependents: Array<{\n filepath: string;\n maxComplexity: number;\n avgComplexity: number;\n }>;\n complexityRiskBoost: RiskLevel;\n };\n}\n\n/**\n * Creates a cached path normalizer to avoid repeated string operations.\n * \n * @param workspaceRoot - The workspace root directory for path normalization\n * @returns A function that normalizes and caches file paths\n */\nfunction createPathNormalizer(workspaceRoot: string): (path: string) => string {\n const cache = new Map<string, string>();\n return (path: string): string => {\n const cached = cache.get(path);\n if (cached !== undefined) return cached;\n const normalized = normalizePath(path, workspaceRoot);\n cache.set(path, normalized);\n return normalized;\n };\n}\n\n/**\n * Builds an index mapping normalized import paths to chunks that import them.\n * Enables O(1) lookup instead of O(n*m) iteration.\n * \n * @param chunks - All chunks from the vector database\n * @param normalizePathCached - Cached path normalization function\n * @returns Map of normalized import paths to chunks that import them\n */\nfunction buildImportIndex(\n chunks: SearchResult[],\n normalizePathCached: (path: string) => string\n): Map<string, SearchResult[]> {\n const importIndex = new Map<string, SearchResult[]>();\n \n for (const chunk of chunks) {\n const imports = chunk.metadata.imports || [];\n for (const imp of imports) {\n const normalizedImport = normalizePathCached(imp);\n let chunkList = importIndex.get(normalizedImport);\n if (!chunkList) {\n chunkList = [];\n importIndex.set(normalizedImport, chunkList);\n }\n chunkList.push(chunk);\n }\n }\n \n return importIndex;\n}\n\n/**\n * Finds all chunks that import the target file using index + fuzzy matching.\n * \n * @param normalizedTarget - The normalized path of the target file\n * @param importIndex - Index mapping import paths to chunks\n * @returns Array of chunks that import the target file (deduplicated)\n */\nfunction findDependentChunks(\n normalizedTarget: string,\n importIndex: Map<string, SearchResult[]>\n): SearchResult[] {\n const dependentChunks: SearchResult[] = [];\n const seenChunkIds = new Set<string>();\n \n const addChunk = (chunk: SearchResult): void => {\n const chunkId = `${chunk.metadata.file}:${chunk.metadata.startLine}-${chunk.metadata.endLine}`;\n if (!seenChunkIds.has(chunkId)) {\n dependentChunks.push(chunk);\n seenChunkIds.add(chunkId);\n }\n };\n \n // Direct index lookup (fastest path)\n const directMatches = importIndex.get(normalizedTarget);\n if (directMatches) {\n for (const chunk of directMatches) {\n addChunk(chunk);\n }\n }\n \n // Fuzzy match for relative imports and path variations\n // Note: This is O(M) where M = unique import paths. For large codebases with many\n // violations, consider caching fuzzy match results at a higher level.\n for (const [normalizedImport, chunks] of importIndex.entries()) {\n if (normalizedImport !== normalizedTarget && matchesFile(normalizedImport, normalizedTarget)) {\n for (const chunk of chunks) {\n addChunk(chunk);\n }\n }\n }\n \n return dependentChunks;\n}\n\n/**\n * Groups chunks by their canonical file path.\n * \n * @param chunks - Array of chunks to group\n * @param workspaceRoot - The workspace root directory\n * @returns Map of canonical file paths to their chunks\n */\nfunction groupChunksByFile(\n chunks: SearchResult[],\n workspaceRoot: string\n): Map<string, SearchResult[]> {\n const chunksByFile = new Map<string, SearchResult[]>();\n \n for (const chunk of chunks) {\n const canonical = getCanonicalPath(chunk.metadata.file, workspaceRoot);\n let existing = chunksByFile.get(canonical);\n if (!existing) {\n existing = [];\n chunksByFile.set(canonical, existing);\n }\n existing.push(chunk);\n }\n \n return chunksByFile;\n}\n\n/**\n * Calculates complexity metrics for each file based on its chunks.\n * \n * @param chunksByFile - Map of file paths to their chunks\n * @returns Array of complexity info for files with complexity data\n */\nfunction calculateFileComplexities(\n chunksByFile: Map<string, SearchResult[]>\n): FileComplexityInfo[] {\n const fileComplexities: FileComplexityInfo[] = [];\n \n for (const [filepath, chunks] of chunksByFile.entries()) {\n const complexities = chunks\n .map(c => c.metadata.complexity)\n .filter((c): c is number => typeof c === 'number' && c > 0);\n \n if (complexities.length > 0) {\n const sum = complexities.reduce((a, b) => a + b, 0);\n const avg = sum / complexities.length;\n const max = Math.max(...complexities);\n \n fileComplexities.push({\n filepath,\n avgComplexity: Math.round(avg * 10) / 10,\n maxComplexity: max,\n complexityScore: sum,\n chunksWithComplexity: complexities.length,\n });\n }\n }\n \n return fileComplexities;\n}\n\n/**\n * Calculates overall complexity metrics from per-file data.\n * \n * @param fileComplexities - Array of per-file complexity info\n * @returns Aggregated complexity metrics, or undefined if no data\n */\nfunction calculateOverallComplexityMetrics(\n fileComplexities: FileComplexityInfo[]\n): DependencyAnalysisResult['complexityMetrics'] | undefined {\n if (fileComplexities.length === 0) {\n return undefined;\n }\n \n const allAvgs = fileComplexities.map(f => f.avgComplexity);\n const allMaxes = fileComplexities.map(f => f.maxComplexity);\n const totalAvg = allAvgs.reduce((a, b) => a + b, 0) / allAvgs.length;\n const globalMax = Math.max(...allMaxes);\n \n // Identify high-complexity dependents (top 5)\n const highComplexityDependents = fileComplexities\n .filter(f => f.maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_COMPLEXITY_DEPENDENT)\n .sort((a, b) => b.maxComplexity - a.maxComplexity)\n .slice(0, 5)\n .map(f => ({\n filepath: f.filepath,\n maxComplexity: f.maxComplexity,\n avgComplexity: f.avgComplexity,\n }));\n \n // Calculate complexity-based risk boost\n const complexityRiskBoost = calculateComplexityRiskBoost(totalAvg, globalMax);\n \n return {\n averageComplexity: Math.round(totalAvg * 10) / 10,\n maxComplexity: globalMax,\n filesWithComplexityData: fileComplexities.length,\n highComplexityDependents,\n complexityRiskBoost,\n };\n}\n\n/**\n * Determines risk level based on complexity thresholds.\n * \n * @param avgComplexity - Average complexity across all files\n * @param maxComplexity - Maximum complexity found in any file\n * @returns Risk level based on complexity thresholds\n */\nfunction calculateComplexityRiskBoost(avgComplexity: number, maxComplexity: number): RiskLevel {\n if (avgComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.CRITICAL_MAX) {\n return 'critical';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.HIGH_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.HIGH_MAX) {\n return 'high';\n }\n if (avgComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_AVG || maxComplexity > COMPLEXITY_THRESHOLDS.MEDIUM_MAX) {\n return 'medium';\n }\n return 'low';\n}\n\n/**\n * Calculates risk level based on dependent count.\n * \n * @param count - Number of dependent files\n * @returns Risk level based on dependent count thresholds\n */\nfunction calculateRiskLevelFromCount(count: number): RiskLevel {\n if (count <= DEPENDENT_COUNT_THRESHOLDS.LOW) {\n return 'low';\n }\n if (count <= DEPENDENT_COUNT_THRESHOLDS.MEDIUM) {\n return 'medium';\n }\n if (count <= DEPENDENT_COUNT_THRESHOLDS.HIGH) {\n return 'high';\n }\n return 'critical';\n}\n\n/**\n * Analyzes dependencies for a given file by finding all chunks that import it.\n * \n * @param targetFilepath - The file to analyze dependencies for\n * @param allChunks - All chunks from the vector database\n * @param workspaceRoot - The workspace root directory\n * @returns Dependency analysis including dependents, count, and risk level\n */\nexport function analyzeDependencies(\n targetFilepath: string,\n allChunks: SearchResult[],\n workspaceRoot: string\n): DependencyAnalysisResult {\n // Create cached path normalizer\n const normalizePathCached = createPathNormalizer(workspaceRoot);\n \n // Build import index for efficient lookup\n const importIndex = buildImportIndex(allChunks, normalizePathCached);\n \n // Find all dependent chunks\n const normalizedTarget = normalizePathCached(targetFilepath);\n const dependentChunks = findDependentChunks(normalizedTarget, importIndex);\n \n // Group by file for analysis\n const chunksByFile = groupChunksByFile(dependentChunks, workspaceRoot);\n \n // Calculate complexity metrics\n const fileComplexities = calculateFileComplexities(chunksByFile);\n const complexityMetrics = calculateOverallComplexityMetrics(fileComplexities);\n \n // Build dependents list\n const dependents = Array.from(chunksByFile.keys()).map(filepath => ({\n filepath,\n isTestFile: isTestFile(filepath),\n }));\n \n // Calculate risk level\n let riskLevel = calculateRiskLevelFromCount(dependents.length);\n \n // Boost risk level if complexity warrants it\n if (complexityMetrics?.complexityRiskBoost) {\n if (RISK_ORDER[complexityMetrics.complexityRiskBoost] > RISK_ORDER[riskLevel]) {\n riskLevel = complexityMetrics.complexityRiskBoost;\n }\n }\n \n return {\n dependents,\n dependentCount: dependents.length,\n riskLevel,\n complexityMetrics,\n };\n}\n","import { VectorDB } from '../vectordb/lancedb.js';\nimport { LienConfig } from '../config/schema.js';\nimport { ComplexityViolation, ComplexityReport, FileComplexityData, RISK_ORDER, RiskLevel, HalsteadDetails } from './types.js';\nimport { ChunkMetadata } from '../indexer/types.js';\nimport { analyzeDependencies } from '../indexer/dependency-analyzer.js';\nimport { SearchResult } from '../vectordb/types.js';\n\n/**\n * Hardcoded severity multipliers:\n * - Warning: triggers at 1x threshold (e.g., testPaths >= 15)\n * - Error: triggers at 2x threshold (e.g., testPaths >= 30)\n */\nconst SEVERITY = { warning: 1.0, error: 2.0 } as const;\n\n/**\n * Analyzer for code complexity based on indexed codebase\n */\nexport class ComplexityAnalyzer {\n constructor(\n private vectorDB: VectorDB,\n private config: LienConfig\n ) {}\n\n /**\n * Analyze complexity of codebase or specific files\n * @param files - Optional list of specific files to analyze\n * @returns Complexity report with violations and summary\n */\n async analyze(files?: string[]): Promise<ComplexityReport> {\n // 1. Get all chunks from index (uses full scan internally for LanceDB)\n // Note: We fetch all chunks even with --files filter because dependency analysis\n // needs the complete dataset to find dependents accurately\n const allChunks = await this.vectorDB.scanAll();\n \n // 2. Filter to specified files if provided\n const chunks = files \n ? allChunks.filter(c => this.matchesAnyFile(c.metadata.file, files))\n : allChunks;\n \n // 3. Find violations from filtered chunks\n const violations = this.findViolations(chunks);\n \n // 4. Build report - pass filtered chunks for file list, but keep violations from those files\n const report = this.buildReport(violations, chunks);\n \n // 5. Enrich files with violations with dependency data\n this.enrichWithDependencies(report, allChunks as SearchResult[]);\n \n return report;\n }\n\n /**\n * Normalize a file path to a consistent relative format\n * Converts absolute paths to relative paths from workspace root\n */\n private normalizeFilePath(filepath: string): string {\n const workspaceRoot = process.cwd();\n // Convert to forward slashes first\n const normalized = filepath.replace(/\\\\/g, '/');\n const normalizedRoot = workspaceRoot.replace(/\\\\/g, '/');\n \n // Convert absolute paths to relative\n if (normalized.startsWith(normalizedRoot + '/')) {\n return normalized.slice(normalizedRoot.length + 1);\n }\n if (normalized.startsWith(normalizedRoot)) {\n return normalized.slice(normalizedRoot.length);\n }\n return normalized;\n }\n\n /**\n * Check if a chunk's file matches any of the target files\n * Uses exact match or suffix matching to avoid unintended matches\n */\n private matchesAnyFile(chunkFile: string, targetFiles: string[]): boolean {\n // Normalize to forward slashes for cross-platform consistency\n // Don't use path.normalize() as its behavior is platform-dependent\n const normalizedChunkFile = chunkFile.replace(/\\\\/g, '/');\n return targetFiles.some(target => {\n const normalizedTarget = target.replace(/\\\\/g, '/');\n // Exact match or target is a suffix of the chunk file\n return normalizedChunkFile === normalizedTarget || \n normalizedChunkFile.endsWith('/' + normalizedTarget);\n });\n }\n\n /**\n * Create a violation if complexity exceeds threshold\n */\n private createViolation(\n metadata: ChunkMetadata,\n complexity: number,\n baseThreshold: number,\n metricType: ComplexityViolation['metricType']\n ): ComplexityViolation | null {\n const warningThreshold = baseThreshold * SEVERITY.warning;\n const errorThreshold = baseThreshold * SEVERITY.error;\n\n if (complexity < warningThreshold) return null;\n\n const violationSeverity = complexity >= errorThreshold ? 'error' : 'warning';\n const effectiveThreshold = violationSeverity === 'error' ? errorThreshold : warningThreshold;\n \n // Human-friendly messages\n const message = metricType === 'cyclomatic'\n ? `Needs ~${complexity} test cases for full coverage (threshold: ${Math.round(effectiveThreshold)})`\n : `Mental load ${complexity} exceeds threshold ${Math.round(effectiveThreshold)} (hard to follow)`;\n\n return {\n filepath: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n symbolName: metadata.symbolName || 'unknown',\n symbolType: metadata.symbolType as 'function' | 'method',\n language: metadata.language,\n complexity,\n threshold: Math.round(effectiveThreshold),\n severity: violationSeverity,\n message,\n metricType,\n };\n }\n\n /**\n * Deduplicate and filter chunks to only function/method types.\n * Handles potential index duplicates by tracking file+line ranges.\n */\n private getUniqueFunctionChunks(\n chunks: Array<{ content: string; metadata: ChunkMetadata }>\n ): ChunkMetadata[] {\n const seen = new Set<string>();\n const result: ChunkMetadata[] = [];\n \n for (const { metadata } of chunks) {\n if (metadata.symbolType !== 'function' && metadata.symbolType !== 'method') continue;\n \n const key = `${metadata.file}:${metadata.startLine}-${metadata.endLine}`;\n if (seen.has(key)) continue;\n \n seen.add(key);\n result.push(metadata);\n }\n \n return result;\n }\n\n /**\n * Convert Halstead effort to time in minutes.\n * Formula: Time (seconds) = Effort / 18 (Stroud number for mental discrimination)\n * Time (minutes) = Effort / (18 * 60) = Effort / 1080\n */\n private effortToMinutes(effort: number): number {\n return effort / 1080;\n }\n\n /**\n * Format minutes as human-readable time (e.g., \"2h 30m\" or \"45m\")\n */\n private formatTime(minutes: number): string {\n if (minutes >= 60) {\n const hours = Math.floor(minutes / 60);\n const mins = Math.round(minutes % 60);\n return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;\n }\n return `${Math.round(minutes)}m`;\n }\n\n /**\n * Create a Halstead violation if metrics exceed thresholds\n */\n private createHalsteadViolation(\n metadata: ChunkMetadata,\n metricValue: number,\n threshold: number,\n metricType: 'halstead_effort' | 'halstead_bugs'\n ): ComplexityViolation | null {\n const warningThreshold = threshold * SEVERITY.warning;\n const errorThreshold = threshold * SEVERITY.error;\n\n if (metricValue < warningThreshold) return null;\n\n const violationSeverity = metricValue >= errorThreshold ? 'error' : 'warning';\n const effectiveThreshold = violationSeverity === 'error' ? errorThreshold : warningThreshold;\n \n // For effort, show time in minutes; for bugs, show decimal with 2 places\n let message: string;\n if (metricType === 'halstead_effort') {\n const timeMinutes = this.effortToMinutes(metricValue);\n const thresholdMinutes = this.effortToMinutes(effectiveThreshold);\n message = `Time to understand ~${this.formatTime(timeMinutes)} exceeds threshold ${this.formatTime(thresholdMinutes)}`;\n } else {\n message = `Estimated bugs ${metricValue.toFixed(2)} exceeds threshold ${effectiveThreshold.toFixed(1)}`;\n }\n\n const halsteadDetails: HalsteadDetails = {\n volume: metadata.halsteadVolume || 0,\n difficulty: metadata.halsteadDifficulty || 0,\n effort: metadata.halsteadEffort || 0,\n bugs: metadata.halsteadBugs || 0,\n };\n\n // Store human-scale values for complexity/threshold:\n // - halstead_effort: rounded to integer minutes for readability (typical values 60-300)\n // - halstead_bugs: kept as decimal for precision (typical values < 5, e.g. 1.5, 2.27)\n let complexity: number;\n let displayThreshold: number;\n if (metricType === 'halstead_effort') {\n // Convert raw effort to minutes and round for comparable deltas\n complexity = Math.round(this.effortToMinutes(metricValue));\n displayThreshold = Math.round(this.effortToMinutes(effectiveThreshold));\n } else {\n // halstead_bugs: store as decimal for precision in small values\n complexity = metricValue;\n displayThreshold = effectiveThreshold;\n }\n\n return {\n filepath: metadata.file,\n startLine: metadata.startLine,\n endLine: metadata.endLine,\n symbolName: metadata.symbolName || 'unknown',\n symbolType: metadata.symbolType as 'function' | 'method',\n language: metadata.language,\n complexity,\n threshold: displayThreshold,\n severity: violationSeverity,\n message,\n metricType,\n halsteadDetails,\n };\n }\n\n /**\n * Check complexity metrics and create violations for a single chunk.\n */\n private checkChunkComplexity(\n metadata: ChunkMetadata,\n thresholds: { testPaths: number; mentalLoad: number; halsteadEffort?: number; estimatedBugs?: number }\n ): ComplexityViolation[] {\n const violations: ComplexityViolation[] = [];\n \n // Check test paths (cyclomatic complexity)\n if (metadata.complexity) {\n const v = this.createViolation(metadata, metadata.complexity, thresholds.testPaths, 'cyclomatic');\n if (v) violations.push(v);\n }\n \n // Check mental load (cognitive complexity)\n if (metadata.cognitiveComplexity) {\n const v = this.createViolation(metadata, metadata.cognitiveComplexity, thresholds.mentalLoad, 'cognitive');\n if (v) violations.push(v);\n }\n \n // Check time to understand (Halstead effort)\n if (thresholds.halsteadEffort && metadata.halsteadEffort) {\n const v = this.createHalsteadViolation(metadata, metadata.halsteadEffort, thresholds.halsteadEffort, 'halstead_effort');\n if (v) violations.push(v);\n }\n \n // Check estimated bugs\n if (thresholds.estimatedBugs && metadata.halsteadBugs) {\n const v = this.createHalsteadViolation(metadata, metadata.halsteadBugs, thresholds.estimatedBugs, 'halstead_bugs');\n if (v) violations.push(v);\n }\n \n return violations;\n }\n\n /**\n * Convert time in minutes to Halstead effort.\n * This is the inverse of effortToMinutes().\n * Formula: Time (seconds) = Effort / 18 (Stroud number)\n * So: Effort = Time (minutes) * 60 * 18 = Time * 1080\n */\n private minutesToEffort(minutes: number): number {\n return minutes * 1080;\n }\n\n /**\n * Find all complexity violations based on thresholds.\n * Checks cyclomatic, cognitive, and Halstead complexity.\n */\n private findViolations(chunks: Array<{ content: string; metadata: ChunkMetadata }>): ComplexityViolation[] {\n const configThresholds = this.config.complexity?.thresholds;\n \n // Convert timeToUnderstandMinutes to effort internally\n const halsteadEffort = configThresholds?.timeToUnderstandMinutes \n ? this.minutesToEffort(configThresholds.timeToUnderstandMinutes)\n : this.minutesToEffort(60); // Default: 60 minutes = 64,800 effort\n \n const thresholds = { \n testPaths: configThresholds?.testPaths ?? 15, \n mentalLoad: configThresholds?.mentalLoad ?? 15, \n halsteadEffort, // Converted from minutes to effort internally (see above)\n estimatedBugs: configThresholds?.estimatedBugs ?? 1.5, // Direct decimal value (no conversion needed)\n };\n const functionChunks = this.getUniqueFunctionChunks(chunks);\n \n return functionChunks.flatMap(metadata => \n this.checkChunkComplexity(metadata, thresholds)\n );\n }\n\n /**\n * Build the final report with summary and per-file data\n */\n private buildReport(\n violations: ComplexityViolation[],\n allChunks: Array<{ content: string; metadata: ChunkMetadata }>\n ): ComplexityReport {\n // Normalize violation filepaths and group by normalized path\n const fileViolationsMap = new Map<string, ComplexityViolation[]>();\n for (const violation of violations) {\n const normalizedPath = this.normalizeFilePath(violation.filepath);\n // Update violation's filepath to normalized form\n violation.filepath = normalizedPath;\n const existing = fileViolationsMap.get(normalizedPath) || [];\n existing.push(violation);\n fileViolationsMap.set(normalizedPath, existing);\n }\n\n // Get unique files from all analyzed chunks, normalized to relative paths\n const analyzedFiles = new Set(allChunks.map(c => this.normalizeFilePath(c.metadata.file)));\n\n // Build file data\n const files: Record<string, FileComplexityData> = {};\n for (const filepath of analyzedFiles) {\n const fileViolations = fileViolationsMap.get(filepath) || [];\n files[filepath] = {\n violations: fileViolations,\n dependents: [], // Will be enriched later if needed\n testAssociations: [], // Will be enriched later if needed\n riskLevel: this.calculateRiskLevel(fileViolations),\n };\n }\n\n // Calculate summary statistics\n const errorCount = violations.filter(v => v.severity === 'error').length;\n const warningCount = violations.filter(v => v.severity === 'warning').length;\n\n // Calculate average and max complexity from all chunks with complexity data\n const complexityValues = allChunks\n .filter(c => c.metadata.complexity !== undefined && c.metadata.complexity > 0)\n .map(c => c.metadata.complexity!);\n\n const avgComplexity = complexityValues.length > 0\n ? complexityValues.reduce((sum, val) => sum + val, 0) / complexityValues.length\n : 0;\n\n const maxComplexity = complexityValues.length > 0\n ? Math.max(...complexityValues)\n : 0;\n\n return {\n summary: {\n filesAnalyzed: analyzedFiles.size,\n totalViolations: violations.length,\n bySeverity: { error: errorCount, warning: warningCount },\n avgComplexity: Math.round(avgComplexity * 10) / 10, // Round to 1 decimal\n maxComplexity,\n },\n files,\n };\n }\n\n /**\n * Calculate risk level based on violations\n */\n private calculateRiskLevel(violations: ComplexityViolation[]): RiskLevel {\n if (violations.length === 0) return 'low';\n\n const hasErrors = violations.some(v => v.severity === 'error');\n const errorCount = violations.filter(v => v.severity === 'error').length;\n\n if (errorCount >= 3) return 'critical';\n if (hasErrors) return 'high';\n if (violations.length >= 3) return 'medium';\n return 'low';\n }\n\n /**\n * Enrich files with violations with dependency data\n * This adds:\n * - List of dependent files (who imports this?)\n * - Boosted risk level based on dependents + complexity\n */\n private enrichWithDependencies(\n report: ComplexityReport,\n allChunks: SearchResult[]\n ): void {\n const workspaceRoot = process.cwd();\n\n // Only enrich files that have violations (to save computation)\n const filesWithViolations = Object.entries(report.files)\n .filter(([_, data]) => data.violations.length > 0)\n .map(([filepath, _]) => filepath);\n\n for (const filepath of filesWithViolations) {\n const fileData = report.files[filepath];\n \n // Analyze dependencies for this file\n const depAnalysis = analyzeDependencies(filepath, allChunks, workspaceRoot);\n \n // Update file data with dependency information\n fileData.dependents = depAnalysis.dependents.map(d => d.filepath);\n fileData.dependentCount = depAnalysis.dependentCount;\n \n // Boost risk level based on dependency analysis\n // Take the higher of the two risk levels\n if (RISK_ORDER[depAnalysis.riskLevel] > RISK_ORDER[fileData.riskLevel]) {\n fileData.riskLevel = depAnalysis.riskLevel;\n }\n \n // Add complexity metrics if available\n if (depAnalysis.complexityMetrics) {\n fileData.dependentComplexityMetrics = {\n averageComplexity: depAnalysis.complexityMetrics.averageComplexity,\n maxComplexity: depAnalysis.complexityMetrics.maxComplexity,\n filesWithComplexityData: depAnalysis.complexityMetrics.filesWithComplexityData,\n };\n }\n }\n }\n}\n\n","/**\n * MCP Tool Handler Registry\n *\n * This module exports all tool handlers and a registry mapping tool names to handlers.\n * The registry is used by the MCP server to dispatch tool calls.\n */\n\nimport { handleSemanticSearch } from './semantic-search.js';\nimport { handleFindSimilar } from './find-similar.js';\nimport { handleGetFilesContext } from './get-files-context.js';\nimport { handleListFunctions } from './list-functions.js';\nimport { handleGetDependents } from './get-dependents.js';\nimport { handleGetComplexity } from './get-complexity.js';\nimport type { ToolHandler } from '../types.js';\n\n// Re-export individual handlers for direct use if needed\nexport {\n handleSemanticSearch,\n handleFindSimilar,\n handleGetFilesContext,\n handleListFunctions,\n handleGetDependents,\n handleGetComplexity,\n};\n\n/**\n * Registry mapping MCP tool names to their handler functions.\n * Used by the MCP server to dispatch tool calls.\n */\nexport const toolHandlers: Record<string, ToolHandler> = {\n 'semantic_search': handleSemanticSearch,\n 'find_similar': handleFindSimilar,\n 'get_files_context': handleGetFilesContext,\n 'list_functions': handleListFunctions,\n 'get_dependents': handleGetDependents,\n 'get_complexity': handleGetComplexity,\n};\n","import chokidar from 'chokidar';\nimport path from 'path';\nimport { LienConfig, LegacyLienConfig, isLegacyConfig, isModernConfig } from '../config/schema.js';\n\nexport interface FileChangeEvent {\n type: 'add' | 'change' | 'unlink';\n filepath: string;\n}\n\nexport type FileChangeHandler = (event: FileChangeEvent) => void | Promise<void>;\n\n/**\n * File watcher service that monitors code files for changes.\n * Uses chokidar for robust file watching with debouncing support.\n */\nexport class FileWatcher {\n private watcher: chokidar.FSWatcher | null = null;\n private debounceTimers: Map<string, NodeJS.Timeout> = new Map();\n private config: LienConfig | LegacyLienConfig;\n private rootDir: string;\n private onChangeHandler: FileChangeHandler | null = null;\n \n constructor(rootDir: string, config: LienConfig | LegacyLienConfig) {\n this.rootDir = rootDir;\n this.config = config;\n }\n \n /**\n * Starts watching files for changes.\n * \n * @param handler - Callback function called when files change\n */\n async start(handler: FileChangeHandler): Promise<void> {\n if (this.watcher) {\n throw new Error('File watcher is already running');\n }\n \n this.onChangeHandler = handler;\n \n // Get watch patterns based on config type\n let includePatterns: string[];\n let excludePatterns: string[];\n \n if (isLegacyConfig(this.config)) {\n includePatterns = this.config.indexing.include;\n excludePatterns = this.config.indexing.exclude;\n } else if (isModernConfig(this.config)) {\n // For modern configs, aggregate patterns from all frameworks\n includePatterns = this.config.frameworks.flatMap(f => f.config.include);\n excludePatterns = this.config.frameworks.flatMap(f => f.config.exclude);\n } else {\n includePatterns = ['**/*'];\n excludePatterns = [];\n }\n \n // Configure chokidar\n this.watcher = chokidar.watch(includePatterns, {\n cwd: this.rootDir,\n ignored: excludePatterns,\n persistent: true,\n ignoreInitial: true, // Don't trigger for existing files\n \n // Handle atomic saves from modern editors (VS Code, Sublime, etc.)\n // Editors write to temp file then rename - without this, we get unlink+add instead of change\n atomic: true,\n \n awaitWriteFinish: {\n stabilityThreshold: 300, // Reduced from 500ms for faster detection\n pollInterval: 100,\n },\n \n // Performance optimizations\n usePolling: false,\n interval: 100,\n binaryInterval: 300,\n });\n \n // Register event handlers with debouncing\n this.watcher\n .on('add', (filepath) => this.handleChange('add', filepath))\n .on('change', (filepath) => this.handleChange('change', filepath))\n .on('unlink', (filepath) => this.handleChange('unlink', filepath))\n .on('error', (error) => {\n console.error(`[Lien] File watcher error: ${error}`);\n });\n \n // Wait for watcher to be ready\n await new Promise<void>((resolve) => {\n this.watcher!.on('ready', () => {\n resolve();\n });\n });\n }\n \n /**\n * Handles a file change event with debouncing.\n * Debouncing prevents rapid reindexing when files are saved multiple times quickly.\n */\n private handleChange(type: 'add' | 'change' | 'unlink', filepath: string): void {\n // Clear existing debounce timer for this file\n const existingTimer = this.debounceTimers.get(filepath);\n if (existingTimer) {\n clearTimeout(existingTimer);\n }\n \n // Set new debounce timer\n const timer = setTimeout(() => {\n this.debounceTimers.delete(filepath);\n \n // Call handler\n if (this.onChangeHandler) {\n // Use path.join for proper cross-platform path handling\n const absolutePath = path.isAbsolute(filepath)\n ? filepath\n : path.join(this.rootDir, filepath);\n \n try {\n const result = this.onChangeHandler({\n type,\n filepath: absolutePath,\n });\n \n // Handle async handlers\n if (result instanceof Promise) {\n result.catch((error) => {\n console.error(`[Lien] Error handling file change: ${error}`);\n });\n }\n } catch (error) {\n console.error(`[Lien] Error handling file change: ${error}`);\n }\n }\n }, this.config.fileWatching.debounceMs);\n \n this.debounceTimers.set(filepath, timer);\n }\n \n /**\n * Stops the file watcher and cleans up resources.\n */\n async stop(): Promise<void> {\n if (!this.watcher) {\n return;\n }\n \n // Clear all pending debounce timers\n for (const timer of this.debounceTimers.values()) {\n clearTimeout(timer);\n }\n this.debounceTimers.clear();\n \n // Close watcher\n await this.watcher.close();\n this.watcher = null;\n this.onChangeHandler = null;\n }\n \n /**\n * Gets the list of files currently being watched.\n */\n getWatchedFiles(): string[] {\n if (!this.watcher) {\n return [];\n }\n \n const watched = this.watcher.getWatched();\n const files: string[] = [];\n \n for (const [dir, filenames] of Object.entries(watched)) {\n for (const filename of filenames) {\n files.push(`${dir}/${filename}`);\n }\n }\n \n return files;\n }\n \n /**\n * Checks if the watcher is currently running.\n */\n isRunning(): boolean {\n return this.watcher !== null;\n }\n}\n\n","import chalk from 'chalk';\nimport fs from 'fs';\nimport path from 'path';\nimport { VectorDB } from '../vectordb/lancedb.js';\nimport { configService } from '../config/service.js';\nimport { ComplexityAnalyzer } from '../insights/complexity-analyzer.js';\nimport { formatReport, OutputFormat } from '../insights/formatters/index.js';\nimport type { LienConfig, LegacyLienConfig } from '../config/schema.js';\n\ninterface ComplexityOptions {\n files?: string[];\n format: OutputFormat;\n threshold?: string;\n cyclomaticThreshold?: string;\n cognitiveThreshold?: string;\n failOn?: 'error' | 'warning';\n}\n\n/** Parsed threshold overrides */\ninterface ThresholdOverrides {\n cyclomatic: number | null;\n cognitive: number | null;\n}\n\nconst VALID_FAIL_ON = ['error', 'warning'];\nconst VALID_FORMATS = ['text', 'json', 'sarif'];\n\n/** Validate --fail-on option */\nfunction validateFailOn(failOn: string | undefined): void {\n if (failOn && !VALID_FAIL_ON.includes(failOn)) {\n console.error(chalk.red(`Error: Invalid --fail-on value \"${failOn}\". Must be either 'error' or 'warning'`));\n process.exit(1);\n }\n}\n\n/** Validate --format option */\nfunction validateFormat(format: string): void {\n if (!VALID_FORMATS.includes(format)) {\n console.error(chalk.red(`Error: Invalid --format value \"${format}\". Must be one of: text, json, sarif`));\n process.exit(1);\n }\n}\n\n/** Validate that specified files exist */\nfunction validateFilesExist(files: string[] | undefined, rootDir: string): void {\n if (!files || files.length === 0) return;\n \n const missingFiles = files.filter(file => {\n const fullPath = path.isAbsolute(file) ? file : path.join(rootDir, file);\n return !fs.existsSync(fullPath);\n });\n \n if (missingFiles.length > 0) {\n console.error(chalk.red(`Error: File${missingFiles.length > 1 ? 's' : ''} not found:`));\n missingFiles.forEach(file => console.error(chalk.red(` - ${file}`)));\n process.exit(1);\n }\n}\n\n/** Parse and validate a threshold value */\nfunction parseThresholdValue(value: string | undefined, flagName: string): number | null {\n if (!value) return null;\n \n const parsed = parseInt(value, 10);\n if (isNaN(parsed)) {\n console.error(chalk.red(`Error: Invalid ${flagName} value \"${value}\". Must be a number`));\n process.exit(1);\n }\n if (parsed <= 0) {\n console.error(chalk.red(`Error: Invalid ${flagName} value \"${value}\". Must be a positive number`));\n process.exit(1);\n }\n return parsed;\n}\n\n/** Parse all threshold options into overrides */\nfunction parseThresholdOverrides(options: ComplexityOptions): ThresholdOverrides {\n const baseThreshold = parseThresholdValue(options.threshold, '--threshold');\n const cyclomaticOverride = parseThresholdValue(options.cyclomaticThreshold, '--cyclomatic-threshold');\n const cognitiveOverride = parseThresholdValue(options.cognitiveThreshold, '--cognitive-threshold');\n \n return {\n // Specific flags take precedence over --threshold\n cyclomatic: cyclomaticOverride ?? baseThreshold,\n cognitive: cognitiveOverride ?? baseThreshold,\n };\n}\n\n/** Apply threshold overrides to config (mutates config) */\nfunction applyThresholdOverrides(config: LienConfig | LegacyLienConfig, overrides: ThresholdOverrides): void {\n if (overrides.cyclomatic === null && overrides.cognitive === null) return;\n \n // Cast to allow mutation - both config types support complexity at runtime\n const cfg = config as { complexity?: LienConfig['complexity'] };\n \n // Ensure complexity config structure exists\n if (!cfg.complexity) {\n cfg.complexity = {\n enabled: true,\n thresholds: { testPaths: 15, mentalLoad: 15 },\n };\n } else if (!cfg.complexity.thresholds) {\n cfg.complexity.thresholds = { testPaths: 15, mentalLoad: 15 };\n }\n \n // Apply overrides (CLI flags use --cyclomatic/--cognitive for familiarity)\n if (overrides.cyclomatic !== null) {\n cfg.complexity.thresholds.testPaths = overrides.cyclomatic;\n }\n if (overrides.cognitive !== null) {\n cfg.complexity.thresholds.mentalLoad = overrides.cognitive;\n }\n}\n\n/** Check if index exists */\nasync function ensureIndexExists(vectorDB: VectorDB): Promise<void> {\n try {\n await vectorDB.scanWithFilter({ limit: 1 });\n } catch {\n console.error(chalk.red('Error: Index not found'));\n console.log(chalk.yellow('\\nRun'), chalk.bold('lien index'), chalk.yellow('to index your codebase first'));\n process.exit(1);\n }\n}\n\n/**\n * Analyze code complexity from indexed codebase\n */\nexport async function complexityCommand(options: ComplexityOptions) {\n const rootDir = process.cwd();\n \n try {\n // Validate options\n validateFailOn(options.failOn);\n validateFormat(options.format);\n validateFilesExist(options.files, rootDir);\n const thresholdOverrides = parseThresholdOverrides(options);\n \n // Load config and database\n const config = await configService.load(rootDir);\n const vectorDB = new VectorDB(rootDir);\n await vectorDB.initialize();\n await ensureIndexExists(vectorDB);\n \n // Apply threshold overrides if provided\n applyThresholdOverrides(config, thresholdOverrides);\n \n // Run analysis and output\n const analyzer = new ComplexityAnalyzer(vectorDB, config);\n const report = await analyzer.analyze(options.files);\n console.log(formatReport(report, options.format));\n \n // Exit code for CI integration\n if (options.failOn) {\n const hasViolations = options.failOn === 'error' \n ? report.summary.bySeverity.error > 0\n : report.summary.totalViolations > 0;\n if (hasViolations) process.exit(1);\n }\n } catch (error) {\n console.error(chalk.red('Error analyzing complexity:'), error);\n process.exit(1);\n }\n}\n\n","import chalk from 'chalk';\nimport { ComplexityReport, ComplexityViolation, FileComplexityData } from '../types.js';\n\n/**\n * Violation with associated file path for rendering\n */\ntype ViolationWithFile = ComplexityViolation & { file: string };\n\n/**\n * Get the display label for a metric type\n */\nfunction getMetricLabel(metricType: ComplexityViolation['metricType']): string {\n switch (metricType) {\n case 'cognitive': return '🧠 Mental load';\n case 'cyclomatic': return '🔀 Test paths';\n case 'halstead_effort': return '⏱️ Time to understand';\n case 'halstead_bugs': return '🐛 Estimated bugs';\n default: return 'Complexity';\n }\n}\n\n/**\n * Convert Halstead effort to time in minutes\n */\nfunction effortToMinutes(effort: number): number {\n return effort / 1080;\n}\n\n/**\n * Format minutes as human-readable time\n */\nfunction formatTime(minutes: number): string {\n if (minutes >= 60) {\n const hours = Math.floor(minutes / 60);\n const mins = Math.round(minutes % 60);\n return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`;\n }\n return `${Math.round(minutes)}m`;\n}\n\n/**\n * Format Halstead details as additional lines\n */\nfunction formatHalsteadDetails(violation: ViolationWithFile): string[] {\n if (!violation.halsteadDetails) return [];\n \n const { volume, difficulty, effort, bugs } = violation.halsteadDetails;\n const timeStr = formatTime(effortToMinutes(effort));\n return [\n chalk.dim(` 📊 Volume: ${Math.round(volume).toLocaleString()}, Difficulty: ${difficulty.toFixed(1)}`),\n chalk.dim(` ⏱️ Time: ~${timeStr}, Est. bugs: ${bugs.toFixed(2)}`),\n ];\n}\n\n/**\n * Metric-specific formatters for complexity/threshold display.\n * Each formatter returns { complexity, threshold } as display strings.\n */\ntype MetricFormatter = (val: number, thresh: number) => { complexity: string; threshold: string };\n\nconst metricFormatters: Record<string, MetricFormatter> = {\n halstead_effort: (val, thresh) => ({\n // val/thresh are already in minutes (human-scale)\n complexity: '~' + formatTime(val),\n threshold: formatTime(thresh),\n }),\n halstead_bugs: (val, thresh) => ({\n complexity: val.toFixed(2),\n threshold: thresh.toFixed(1),\n }),\n cyclomatic: (val, thresh) => ({\n complexity: `${val} (needs ~${val} tests)`,\n threshold: thresh.toString(),\n }),\n};\n\nconst defaultFormatter: MetricFormatter = (val, thresh) => ({\n complexity: val.toString(),\n threshold: thresh.toString(),\n});\n\n/**\n * Format symbol name with appropriate suffix\n */\nfunction formatSymbolDisplay(violation: ViolationWithFile, isBold: boolean): string {\n const display = ['function', 'method'].includes(violation.symbolType)\n ? `${violation.symbolName}()`\n : violation.symbolName;\n return isBold ? chalk.bold(display) : display;\n}\n\n/**\n * Format dependency impact information\n */\nfunction formatDependencyInfo(fileData: FileComplexityData): string[] {\n const depCount = fileData.dependentCount ?? fileData.dependents.length;\n if (depCount === 0) return [];\n\n const lines = [chalk.dim(` 📦 Imported by ${depCount} file${depCount !== 1 ? 's' : ''}`)];\n \n if (fileData.dependentComplexityMetrics) {\n const { averageComplexity, maxComplexity } = fileData.dependentComplexityMetrics;\n lines.push(chalk.dim(` - Dependent avg complexity: ${averageComplexity}, max: ${maxComplexity}`));\n }\n \n return lines;\n}\n\n/**\n * Format percentage over threshold\n */\nfunction formatPercentageOver(complexity: number, threshold: number): string {\n if (threshold <= 0) return 'N/A (invalid threshold)';\n return `${Math.round(((complexity - threshold) / threshold) * 100)}% over threshold`;\n}\n\n/**\n * Format a single violation entry with its metadata\n */\nfunction formatViolation(\n violation: ViolationWithFile,\n fileData: FileComplexityData,\n colorFn: typeof chalk.red | typeof chalk.yellow,\n isBold: boolean\n): string[] {\n const symbolText = formatSymbolDisplay(violation, isBold);\n const metricLabel = getMetricLabel(violation.metricType);\n const formatter = metricFormatters[violation.metricType] || defaultFormatter;\n const { complexity: complexityDisplay, threshold: thresholdDisplay } = formatter(violation.complexity, violation.threshold);\n\n return [\n colorFn(` ${violation.file}:${violation.startLine}`) + chalk.dim(' - ') + symbolText,\n chalk.dim(` ${metricLabel}: ${complexityDisplay} (threshold: ${thresholdDisplay})`),\n chalk.dim(` ⬆️ ${formatPercentageOver(violation.complexity, violation.threshold)}`),\n ...formatHalsteadDetails(violation),\n ...formatDependencyInfo(fileData),\n chalk.dim(` ⚠️ Risk: ${fileData.riskLevel.toUpperCase()}`),\n '',\n ];\n}\n\n/**\n * Format complexity report as human-readable text with colors\n */\nexport function formatTextReport(report: ComplexityReport): string {\n const lines: string[] = [];\n\n // Header\n lines.push(chalk.bold('🔍 Complexity Analysis\\n'));\n\n // Summary\n lines.push(chalk.bold('Summary:'));\n lines.push(chalk.dim(' Files analyzed: ') + report.summary.filesAnalyzed.toString());\n const errorText = `${report.summary.bySeverity.error} error${report.summary.bySeverity.error !== 1 ? 's' : ''}`;\n const warningText = `${report.summary.bySeverity.warning} warning${report.summary.bySeverity.warning !== 1 ? 's' : ''}`;\n lines.push(chalk.dim(' Violations: ') + `${report.summary.totalViolations} (${errorText}, ${warningText})`);\n lines.push(chalk.dim(' Average complexity: ') + report.summary.avgComplexity.toString());\n lines.push(chalk.dim(' Max complexity: ') + report.summary.maxComplexity.toString());\n lines.push('');\n\n // Group violations by file\n const filesWithViolations = Object.entries(report.files)\n .filter(([_, data]) => data.violations.length > 0)\n .sort((a, b) => b[1].violations.length - a[1].violations.length);\n\n if (filesWithViolations.length === 0) {\n lines.push(chalk.green('✓ No violations found!'));\n return lines.join('\\n');\n }\n\n // Errors section\n const errors = filesWithViolations.flatMap(([file, data]) =>\n data.violations.filter(v => v.severity === 'error').map(v => ({ file, ...v }))\n );\n\n if (errors.length > 0) {\n lines.push(chalk.red.bold('❌ Errors:\\n'));\n for (const error of errors) {\n lines.push(...formatViolation(error, report.files[error.file], chalk.red, true));\n }\n }\n\n // Warnings section\n const warnings = filesWithViolations.flatMap(([file, data]) =>\n data.violations.filter(v => v.severity === 'warning').map(v => ({ file, ...v }))\n );\n\n if (warnings.length > 0) {\n lines.push(chalk.yellow.bold('⚠️ Warnings:\\n'));\n for (const warning of warnings) {\n lines.push(...formatViolation(warning, report.files[warning.file], chalk.yellow, false));\n }\n }\n\n return lines.join('\\n');\n}\n\n","import { ComplexityReport } from '../types.js';\n\n/**\n * Format complexity report as JSON for consumption by GitHub Action\n */\nexport function formatJsonReport(report: ComplexityReport): string {\n return JSON.stringify(report, null, 2);\n}\n\n","import { ComplexityReport } from '../types.js';\n\n/**\n * SARIF (Static Analysis Results Interchange Format) 2.1.0\n * Used by GitHub Code Scanning to show results in Security tab\n * https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning\n */\ninterface SarifReport {\n $schema: string;\n version: string;\n runs: SarifRun[];\n}\n\ninterface SarifRun {\n tool: {\n driver: {\n name: string;\n version: string;\n informationUri?: string;\n rules?: SarifRule[];\n };\n };\n results: SarifResult[];\n}\n\ninterface SarifRule {\n id: string;\n shortDescription: {\n text: string;\n };\n fullDescription?: {\n text: string;\n };\n help?: {\n text: string;\n };\n defaultConfiguration?: {\n level: 'warning' | 'error' | 'note';\n };\n}\n\ninterface SarifResult {\n ruleId: string;\n level: 'warning' | 'error' | 'note';\n message: {\n text: string;\n };\n locations: Array<{\n physicalLocation: {\n artifactLocation: {\n uri: string;\n };\n region: {\n startLine: number;\n endLine: number;\n };\n };\n }>;\n}\n\n/**\n * Get the SARIF rule ID for a metric type\n */\nfunction getRuleId(metricType: string): string {\n switch (metricType) {\n case 'cognitive': return 'lien/high-cognitive-complexity';\n case 'cyclomatic': return 'lien/high-cyclomatic-complexity';\n case 'halstead_effort': return 'lien/high-halstead-effort';\n case 'halstead_bugs': return 'lien/high-estimated-bugs';\n default: return 'lien/high-complexity';\n }\n}\n\n/**\n * Format complexity report as SARIF for GitHub Code Scanning\n */\nexport function formatSarifReport(report: ComplexityReport): string {\n const rules: SarifRule[] = [\n {\n id: 'lien/high-cyclomatic-complexity',\n shortDescription: {\n text: 'Too many test paths',\n },\n fullDescription: {\n text: 'Function or method requires too many test cases to achieve full branch coverage. Each decision point (if, switch, loop) adds a path that needs testing.',\n },\n help: {\n text: 'Consider refactoring by extracting methods, using early returns, or simplifying conditional logic to reduce the number of test paths.',\n },\n },\n {\n id: 'lien/high-cognitive-complexity',\n shortDescription: {\n text: 'High mental load',\n },\n fullDescription: {\n text: 'Function or method has high mental load (deeply nested or hard to follow), requiring too much mental effort to understand and maintain.',\n },\n help: {\n text: 'Consider flattening nested conditionals, extracting helper functions, or using guard clauses to reduce mental load.',\n },\n },\n {\n id: 'lien/high-halstead-effort',\n shortDescription: {\n text: 'Long time to understand',\n },\n fullDescription: {\n text: 'Function or method takes too long to understand, based on Halstead metrics (operators and operands count).',\n },\n help: {\n text: 'Consider simplifying expressions, reducing variable count, or breaking into smaller functions.',\n },\n },\n {\n id: 'lien/high-estimated-bugs',\n shortDescription: {\n text: 'High estimated bug count',\n },\n fullDescription: {\n text: 'Function or method is likely to contain bugs based on Halstead metrics (Volume / 3000), which estimates bug count from code complexity.',\n },\n help: {\n text: 'Consider simplifying the function, breaking into smaller units, or adding thorough test coverage.',\n },\n },\n ];\n\n const results: SarifResult[] = [];\n\n // Convert violations to SARIF results\n for (const [filepath, fileData] of Object.entries(report.files)) {\n for (const violation of fileData.violations) {\n const ruleId = getRuleId(violation.metricType);\n \n results.push({\n ruleId,\n level: violation.severity,\n message: {\n text: `${violation.symbolName}: ${violation.message}`,\n },\n locations: [\n {\n physicalLocation: {\n artifactLocation: {\n uri: filepath,\n },\n region: {\n startLine: violation.startLine,\n endLine: violation.endLine,\n },\n },\n },\n ],\n });\n }\n }\n\n const sarifReport: SarifReport = {\n $schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',\n version: '2.1.0',\n runs: [\n {\n tool: {\n driver: {\n name: 'Lien Complexity Analyzer',\n version: '1.0.0',\n informationUri: 'https://github.com/liendev/lien',\n rules,\n },\n },\n results,\n },\n ],\n };\n\n return JSON.stringify(sarifReport, null, 2);\n}\n\n","import { ComplexityReport } from '../types.js';\nimport { formatTextReport } from './text.js';\nimport { formatJsonReport } from './json.js';\nimport { formatSarifReport } from './sarif.js';\n\nexport type OutputFormat = 'text' | 'json' | 'sarif';\n\n/**\n * Format complexity report in the specified format\n */\nexport function formatReport(\n report: ComplexityReport,\n format: OutputFormat\n): string {\n switch (format) {\n case 'json':\n return formatJsonReport(report);\n case 'sarif':\n return formatSarifReport(report);\n case 'text':\n default:\n return formatTextReport(report);\n }\n}\n\n// Export individual formatters\nexport { formatTextReport, formatJsonReport, formatSarifReport };\n\n","import { program } from './cli/index.js';\n\nprogram.parse();\n\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAoCvB,SAAS,oBAA4B;AAC1C,SAAO,YAAY;AACrB;AAxCA,IAeM,YACA,WACAA,UAEF;AAnBJ;AAAA;AAAA;AAeA,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,YAAY,QAAQ,UAAU;AACpC,IAAMA,WAAU,cAAc,YAAY,GAAG;AAI7C,QAAI;AAEF,oBAAcA,SAAQ,KAAK,WAAW,iBAAiB,CAAC;AAAA,IAC1D,QAAQ;AACN,UAAI;AAEF,sBAAcA,SAAQ,KA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Language","search","detectLanguage","init_chunker","init_types","path","init_types","buildLegacySymbols","fs","path","init_version","path","os","crypto","init_version","fs","path","fs","path","fs","path","manifest","init_chunker","fs","path","fs","chalk","isGitAvailable","isGitRepo","GitStateTracker","init_chunker","init_version","createRequire","fileURLToPath","dirname","join","fs","path","fileURLToPath","chalk","createRequire","fileURLToPath","dirname","join","__filename","__dirname","require","packageJson","fs","path","chalk","fs","path","fs","path","path","packageJson","fs","fs","path","path","fs","tools","fs","path","path","fs","fs","path","path","fs","path","fs","__filename","fileURLToPath","__dirname","path","fs","chalk","init_version","chalk","fs","path","path","chalk","fs","chalk","VectorDB","ManifestManager","chalk","chalk","fs","path","createRequire","fileURLToPath","dirname","join","z","z","z","z","z","path","isTestFile","path","chunkFile","isTestFile","SCAN_LIMIT","path","isTestFile","RISK_ORDER","DEPENDENT_COUNT_THRESHOLDS","COMPLEXITY_THRESHOLDS","path","buildImportIndex","findDependentChunks","calculateFileComplexities","calculateOverallComplexityMetrics","calculateComplexityRiskBoost","isTestFile","RISK_ORDER","chunkFile","RISK_ORDER","path","__filename","fileURLToPath","__dirname","dirname","require","createRequire","packageJson","join","indexCodebase","path","fs","chalk","chalk","fs","path","chalk","chalk","path","fs","__filename","fileURLToPath","__dirname","dirname","require","createRequire","packageJson","join"]}
|