import type { ComplexityViolation, ComplexityReport, RiskLevel } from './types.js'; import type { ChunkMetadata, CodeChunk } from '../types.js'; /** * Complexity thresholds shape shared by chunk-based analysis (`findViolations` * below), `lien delta`'s complexity gate (`complexity-delta.ts`), and the * user-facing config default (`@liendev/core`'s `LienConfig.complexity.thresholds`). * * #988: these four sites used to each hardcode their own copy of the same * `{ testPaths: 15, mentalLoad: 15, timeToUnderstandMinutes: 60, estimatedBugs: 1.5 }` * object with nothing enforcing agreement. This file is the single source of * truth now (this is the reference `analyzeComplexityFromChunks` already read, * and the one `complexity-delta.ts`'s own comment already pointed to) — export * via `index.ts`, import everywhere else, same pattern as `COMPLEXITY_THRESHOLDS` * in `../dependency-analyzer.ts`. */ export interface ComplexityThresholds { testPaths: number; mentalLoad: number; timeToUnderstandMinutes: number; estimatedBugs: number; } /** Default complexity thresholds — the single source of truth (#988). */ export declare const DEFAULT_COMPLEXITY_THRESHOLDS: ComplexityThresholds; /** * Normalize a file path to a consistent relative format. * Converts absolute paths to relative paths from workspace root. * * Delegates to `getCanonicalPath` (`../utils/path-matching.ts`) — the module * that already owns this exact decision for dependency analysis. #988: this * function used to have its own second, unguarded `startsWith(normalizedRoot)` * fallback (no separator check), which silently mangled any sibling directory * sharing the workspace root's name prefix (e.g. root `/x/lien` mangling * `/x/lien-other/y.ts` into `-other/y.ts`, a leading-`-` path that matches * nothing downstream, so the chunk was silently dropped from complexity * reporting). `getCanonicalPath` has only the boundary-safe branch, fixing the * bug and removing the duplicate implementation in the same move. * * The one behavioral difference: the old unguarded branch also mapped a path * EXACTLY equal to the workspace root (no trailing separator) to `''`. * `getCanonicalPath` does not special-case that (it requires the `/` * separator), so such a path now passes through unchanged. No real caller * hits this: `metadata.file`/`violation.filepath` always name an actual file * under the root, never the bare root directory itself. */ export declare function normalizeFilePath(filepath: string): string; /** * Check if a chunk's file matches any of the target files. * Uses exact match or suffix matching to avoid unintended matches. */ export declare function matchesAnyFile(chunkFile: string, targetFiles: string[]): boolean; /** * Create a violation if complexity exceeds threshold. */ export declare function createViolation(metadata: ChunkMetadata, complexity: number, baseThreshold: number, metricType: ComplexityViolation['metricType']): ComplexityViolation | null; /** * Convert Halstead effort to time in minutes. * Formula: Time (seconds) = Effort / 18 (Stroud number for mental discrimination) * Time (minutes) = Effort / (18 * 60) = Effort / 1080 */ export declare function effortToMinutes(effort: number): number; /** * Convert time in minutes to Halstead effort. * Inverse of effortToMinutes(). */ export declare function minutesToEffort(minutes: number): number; /** * Format minutes as human-readable time (e.g., "2h 30m" or "45m") */ export declare function formatTime(minutes: number): string; /** * Create a Halstead violation if metrics exceed thresholds. */ export declare function createHalsteadViolation(metadata: ChunkMetadata, metricValue: number, threshold: number, metricType: 'halstead_effort' | 'halstead_bugs'): ComplexityViolation | null; /** * Check complexity metrics and create violations for a single chunk. */ export declare function checkChunkComplexity(metadata: ChunkMetadata, thresholds: { testPaths: number; mentalLoad: number; halsteadEffort?: number; estimatedBugs?: number; }): ComplexityViolation[]; /** * Deduplicate and filter chunks to only function/method types. */ export declare function getUniqueFunctionChunks(chunks: Array<{ content: string; metadata: ChunkMetadata; }>): ChunkMetadata[]; /** * Find all complexity violations based on thresholds. */ export declare function findViolations(chunks: Array<{ content: string; metadata: ChunkMetadata; }>, thresholds: ComplexityThresholds): ComplexityViolation[]; /** * Calculate risk level based on violations. */ export declare function calculateRiskLevel(violations: ComplexityViolation[]): RiskLevel; /** * Build the final report with summary and per-file data. */ export declare function buildReport(violations: ComplexityViolation[], allChunks: Array<{ content: string; metadata: ChunkMetadata; }>): ComplexityReport; /** * Enrich files with violations with dependency data. */ export declare function enrichWithDependencies(report: ComplexityReport, allChunks: CodeChunk[]): void; /** * Analyze complexity from in-memory chunks (no VectorDB needed). * Standalone replacement for ComplexityAnalyzer.analyzeFromChunks(). */ export declare function analyzeComplexityFromChunks(chunks: CodeChunk[], files?: string[], thresholdOverrides?: { testPaths?: number; mentalLoad?: number; }): ComplexityReport; //# sourceMappingURL=chunk-complexity.d.ts.map