import { type LinkSuggestion } from "../core/link-suggester.js"; import type { LinkType } from "../types/links.js"; import type { BrokenLink } from "../types/config.js"; import type { OperationOptions } from "../types/operations.js"; /** * Configuration options for link validation operations. * * Controls how broken link detection is performed across markdown files. * * @category Commands */ export interface ValidateOperationOptions extends OperationOptions { /** Types of links to validate (default: all types) */ linkTypes?: LinkType[]; /** Enable external HTTP/HTTPS link validation */ checkExternal: boolean; /** Timeout for external link validation in milliseconds */ externalTimeout: number; /** Treat missing internal files as errors */ strictInternal: boolean; /** Validate Claude import paths */ checkClaudeImports: boolean; /** Check for circular references in file dependencies */ checkCircular: boolean; /** Maximum depth to traverse subdirectories when using glob patterns */ maxDepth?: number | undefined; /** Show only broken links, not all validation results */ onlyBroken: boolean; /** Group results by file or by link type */ groupBy: "file" | "type"; /** Include line numbers and context in output */ includeContext: boolean; /** Git diff range for incremental validation */ gitDiff?: string; /** Only validate staged files */ gitStaged?: boolean; /** Enable validation result caching */ cache?: boolean; /** Cache directory path */ cacheDir?: string; /** Exit on first broken link found */ failFast?: boolean; /** Include dependency tracking for changed files */ includeDependencies?: boolean; /** Enable content freshness detection for external links */ checkContentFreshness?: boolean; /** Default staleness threshold in days */ freshnessThreshold?: number; /** Enable authentication-aware link validation */ enableAuthDetection?: boolean; /** Treat auth-required links as valid (not broken) */ allowAuthRequired?: boolean; /** API keys/credentials for authenticated requests */ authCredentials?: Record; /** Custom headers for specific domains */ authHeaders?: Record>; /** Validate Obsidian wikilinks by resolving them against the whole vault */ obsidian?: boolean; /** External-link hostnames excluded from checking entirely (comma-separated on the CLI) */ skipDomains?: string[]; /** Extra attempts for transient external failures (network errors, 5xx, 429) */ externalRetries?: number; /** Frontmatter fields every validated file must define */ requireFrontmatter?: string[]; /** Internal-link href form to enforce: relative (no leading /), absolute (leading /), or none */ enforceLinkFormat?: "relative" | "absolute" | "none"; } /** * CLI-specific options for the validate command. * * @category Commands */ export interface ValidateCliOptions extends Omit { /** Comma-separated list of link types to validate */ linkTypes?: string; /** Output results in JSON format */ json?: boolean; /** Print the recorded parse-failure stack for the named file */ explain?: string; /** Suggest and apply fixes for broken internal links */ fix?: boolean; } /** * Extended broken link interface with additional validation context. * * @category Commands */ interface ExtendedBrokenLink extends BrokenLink { /** Link type for grouping */ type: LinkType; /** Link URL for display */ url: string; /** Line number where the link was found */ line?: number; /** File path (for context when grouping by type) */ filePath?: string | undefined; } /** * Result of a validation operation containing all broken links found. * * @category Commands */ export interface ValidateResult { /** Total number of files processed */ filesProcessed: number; /** Total number of links found */ totalLinks: number; /** Total number of broken links found */ brokenLinks: number; /** Broken links grouped by file */ brokenLinksByFile: Record; /** Broken links grouped by type */ brokenLinksByType: Partial>; /** Files that had processing errors */ fileErrors: { file: string; error: string; stack?: string | undefined; }[]; /** Whether circular references were detected */ hasCircularReferences: boolean; /** Circular reference details if found */ circularReferences?: string[]; /** Processing time in milliseconds */ processingTime: number; /** Git integration information */ gitInfo?: { /** Whether git integration was used */ enabled: boolean; /** Files changed according to git */ changedFiles: number; /** Files cached from previous validation */ cachedFiles: number; /** Cache hit rate percentage */ cacheHitRate: number; /** Base reference used for git diff */ baseRef?: string; /** Current git commit */ currentCommit?: string; }; /** Number of stale links found */ staleLinks?: number; /** Number of fresh links found */ freshLinks?: number; /** Number of auth-required links found */ authRequiredLinks?: number; /** Number of successfully authenticated links */ authenticatedLinks?: number; /** Files missing required frontmatter fields */ frontmatterViolations: { file: string; missingFields: string[]; }[]; /** Internal links whose href form violates the enforced link format */ formatViolations: { file: string; href: string; line: number; expected: string; }[]; } /** * A broken internal link with ranked replacement candidates, ready to prompt about. * * @category Commands */ export interface PlannedLinkFix { /** File containing the broken link */ sourceFile: string; /** One-based line number of the link */ line: number; /** The broken link target as written */ brokenHref: string; /** Replacement candidates, best first */ suggestions: LinkSuggestion[]; } /** * Asks the user which suggestion to apply for one broken link. * * Returns the chosen zero-based suggestion index, or undefined to skip. Injectable so tests and * non-interactive callers can drive fix mode without a terminal. * * @category Commands */ export type FixPrompter = (fix: PlannedLinkFix) => Promise; /** * Plan fixes for the broken internal links in a validation result. * * Only internal file-not-found links are fixable this way -- an external or anchor failure has no * file to suggest. Broken links whose target resembles nothing known are left out rather than given * a wild guess. * * @param result - A completed validation result * @param knownFiles - Absolute paths of every candidate file in the project * * @returns One planned fix per broken internal link that has suggestions */ export declare function planLinkFixes(result: ValidateResult, knownFiles: string[]): PlannedLinkFix[]; /** * Apply one chosen suggestion to the linking file. * * Rewrites the markdown link form ](broken-href to ](replacement on the recorded line. A missing * line or a link text that no longer matches throws -- applying a fix to a file that changed under * the validator would silently corrupt the wrong span. * * @param fix - The planned fix being accepted * @param choiceIndex - Zero-based index into fix.suggestions */ export declare function applyLinkFix(fix: PlannedLinkFix, choiceIndex: number): Promise; /** * Validates markdown files for broken links of all types. * * Searches through markdown files to find broken internal links, external HTTP/HTTPS links, missing * images, invalid anchors, and other link integrity issues. * * @example * Basic validation * ```typescript * const result = await validateLinks(['**\/*.md'], { * checkExternal: true, * onlyBroken: true * }); * * console.log('Found ' + result.brokenLinks + ' broken links in ' + result.filesProcessed + ' files'); * ``` * * @example * Validate specific link types only * ```typescript * const result = await validateLinks(['docs\/*.md'], { * linkTypes: ['internal', 'image'], * strictInternal: true, * includeContext: true * }); * ``` * * @param patterns - File patterns to validate (supports globs) * @param options - Validation configuration options * * @returns Promise resolving to validation results */ export declare function validateLinks(patterns: string[], options?: Partial): Promise; /** * CLI command handler for validate operations. * * Processes markdown files to find broken links of all types. Supports various output formats and * filtering options. * * @example * ```bash * # Validate all markdown files including external links * markmv validate "**\/*.md" --check-external --verbose * * # Check only internal links and images * markmv validate docs/ --link-types internal,image --strict-internal * * # Find broken links with context information * markmv validate README.md --include-context --group-by type * ```; * * @param patterns - File patterns to validate * @param cliOptions - CLI-specific options */ export declare function validateCommand(patterns: string[], cliOptions: ValidateCliOptions, prompter?: FixPrompter): Promise; export {}; //# sourceMappingURL=validate.d.ts.map