@omfalos/mokosh 0.3.0 → 0.3.1

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.d.mts CHANGED
@@ -442,6 +442,56 @@ declare function saveChangeImpactCache(cache: ChangeImpactCache, cachePath: stri
442
442
  */
443
443
  declare function loadChangeImpactCache(cachePath: string): ChangeImpactCache | null;
444
444
 
445
+ /**
446
+ * Sliding-window (shingle) hashing over a normalized token stream, plus chain-merging of
447
+ * consecutive matching windows into contiguous duplicate blocks. Shared by every language
448
+ * `tokenize()` supports — the shingling step itself has no language awareness at all.
449
+ */
450
+
451
+ interface DuplicateOccurrence {
452
+ file: string;
453
+ startLine: number;
454
+ endLine: number;
455
+ }
456
+ interface DuplicateGroup {
457
+ /** Two locations sharing this duplicated block. */
458
+ occurrences: [DuplicateOccurrence, DuplicateOccurrence];
459
+ /** Line span covered by the block (measured on the first occurrence). */
460
+ lines: number;
461
+ /** Token-window length backing this block, after chain-merging adjacent windows. */
462
+ tokens: number;
463
+ }
464
+
465
+ interface FindDuplicatesOptions {
466
+ /** Minimum duplicated block size, in source lines, to report (default 6). */
467
+ minLines?: number | undefined;
468
+ /** Shingle window size, in tokens — the smallest duplicate the scan can detect (default 15). */
469
+ windowSize?: number | undefined;
470
+ /** When true (default), string/number literals are normalized too, so only structural shape
471
+ * — not the specific values used — drives a match. Set false for stricter, Type-1-only matching. */
472
+ ignoreLiterals?: boolean | undefined;
473
+ /** Caps the number of duplicate blocks returned, largest-first (default 50). */
474
+ limit?: number | undefined;
475
+ /** Directory names to exclude, matched against any path segment (default `DEFAULT_IGNORE_DIRS`
476
+ * — `node_modules`, `dist`, `.git`, `mokosh-cache`, `coverage`, etc.). Pass `[]` to disable. */
477
+ ignoreDirs?: readonly string[] | undefined;
478
+ }
479
+ /**
480
+ * @description Scans every file already present in `graph` for cross-file (and within-file)
481
+ * duplicated code, using a language-agnostic token-shingling pipeline: comments are stripped
482
+ * per `FileType`, identifiers (and, by default, literals) are normalized to placeholders so
483
+ * renamed-variable copies still match, then a sliding token window is hashed and chain-merged
484
+ * into contiguous blocks. Works uniformly across every language in `DEFAULT_EXTENSIONS`.
485
+ * @param graph - The graph to scan; its node paths (already ignore-rule-filtered) are the file
486
+ * list, re-read from disk since duplication data isn't cached on `FileNode`.
487
+ * @param rootDir - Absolute project root that graph paths are relative to.
488
+ * @param options - `minLines`/`windowSize` tune sensitivity; `ignoreLiterals` toggles Type-2 vs
489
+ * Type-1 matching; `ignoreDirs` excludes files under matching directory names; `limit` caps
490
+ * results. Lock files are always excluded, independent of `ignoreDirs`.
491
+ * @returns Duplicate blocks, each a pair of occurrences, sorted largest-first.
492
+ */
493
+ declare function findDuplicates(graph: Graph, rootDir: string, options?: FindDuplicatesOptions): Promise<DuplicateGroup[]>;
494
+
445
495
  /** Controls how aggressively `detectFeatures` promotes files to features. */
446
496
  interface FeatureDetectionOptions {
447
497
  /**
@@ -1303,4 +1353,4 @@ declare function createWorkspaceGraph(rootDir: string, options?: {
1303
1353
  */
1304
1354
  declare function getAllProjectFiles(rootDir: string, options?: ScanOptions): string[];
1305
1355
 
1306
- export { type ApiSurface, type ApplyTagsFileResult, type ApplyTagsResult, CALL_EDGE_TYPES, CallEdge, type CalleeEntry, type CallerEntry$1 as CallerEntry, type ChangeImpactCache, type ComplexFunctionEntry, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type DependencyGraph, EXPORT_TRACKING_TYPES, type ExportKind, type FeatureDetectionOptions, type FeatureDomain, type FeatureGraph, type FeatureGraphOptions, type FeatureInfo, FileNode, FileType, type FindComplexFunctionsOptions, type FunctionCallInfo, type GetAffectedOptions, type GetCallersOptions, Graph, type CallerEntry as GraphCallerEntry, type GraphExporter, IMPORT_SYMBOL_TYPES, ImportEdge, type LanguageCoverage, MermaidExporter, type ModuleResponsibility, type ModuleRole, type MokoshConfig, type MonorepoDetector, type MonorepoLayout, NodeCategory, type NodeMeta, type NodeQuery, type ParallelParsingOption, type PathWithSymbols, type ProposeTagsOptions, type PublicExport, type ResponsibilityGraph, type ScanOptions, type SerializedGraph, type SerializedWorkspaceGraph, type SlimNode, type SlimSerializedGraph, StructuredTag, type SymbolCaller, type SymbolImporter, type SymbolMatch, type SymbolPrecision, SymbolTraversalContext, type TestNodeIdentifier, type TraversalOptions, type TraversalVisitor, type TypeEdge, type TypeGraph, type TypeKind, type TypeNode, type TypeQueryResult, WorkspaceGraph, type WorkspacePackage, type WorkspacePackageSummary, type WorkspacePackagesSummary, applyConfig, applyTags, buildApiSurface, buildChangeImpactCache, buildFeatureGraph, buildResponsibilityGraph, buildTypeGraph, computeGraphHash, configToGraphOptions, createImportMap, createWorkspaceGraph, detectAllEntryPoints, detectEntryPoint, detectFeatures, detectMonorepo, filterGraph, findComplexFunctions, findSymbol, getAffected, getAllProjectFiles, getCallers, getDependencies, getDependents, getLanguageCoverage, getNodeMeta, hasCoverageData, isChangeImpactCacheValid, loadChangeImpactCache, loadCoverageMap, loadMokoshConfig, parseQuery, proposeAffectedTests, proposeTags, queryCallGraph, queryChangeImpact, queryTypeGraph, registerConfigMatcher, registerMonorepoDetector, registerParser, registerTestLibrary, registerTestPattern, saveChangeImpactCache, slimSerialize, summarizeWorkspacePackages, toMermaid };
1356
+ export { type ApiSurface, type ApplyTagsFileResult, type ApplyTagsResult, CALL_EDGE_TYPES, CallEdge, type CalleeEntry, type CallerEntry$1 as CallerEntry, type ChangeImpactCache, type ComplexFunctionEntry, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type DependencyGraph, type DuplicateGroup, type DuplicateOccurrence, EXPORT_TRACKING_TYPES, type ExportKind, type FeatureDetectionOptions, type FeatureDomain, type FeatureGraph, type FeatureGraphOptions, type FeatureInfo, FileNode, FileType, type FindComplexFunctionsOptions, type FindDuplicatesOptions, type FunctionCallInfo, type GetAffectedOptions, type GetCallersOptions, Graph, type CallerEntry as GraphCallerEntry, type GraphExporter, IMPORT_SYMBOL_TYPES, ImportEdge, type LanguageCoverage, MermaidExporter, type ModuleResponsibility, type ModuleRole, type MokoshConfig, type MonorepoDetector, type MonorepoLayout, NodeCategory, type NodeMeta, type NodeQuery, type ParallelParsingOption, type PathWithSymbols, type ProposeTagsOptions, type PublicExport, type ResponsibilityGraph, type ScanOptions, type SerializedGraph, type SerializedWorkspaceGraph, type SlimNode, type SlimSerializedGraph, StructuredTag, type SymbolCaller, type SymbolImporter, type SymbolMatch, type SymbolPrecision, SymbolTraversalContext, type TestNodeIdentifier, type TraversalOptions, type TraversalVisitor, type TypeEdge, type TypeGraph, type TypeKind, type TypeNode, type TypeQueryResult, WorkspaceGraph, type WorkspacePackage, type WorkspacePackageSummary, type WorkspacePackagesSummary, applyConfig, applyTags, buildApiSurface, buildChangeImpactCache, buildFeatureGraph, buildResponsibilityGraph, buildTypeGraph, computeGraphHash, configToGraphOptions, createImportMap, createWorkspaceGraph, detectAllEntryPoints, detectEntryPoint, detectFeatures, detectMonorepo, filterGraph, findComplexFunctions, findDuplicates, findSymbol, getAffected, getAllProjectFiles, getCallers, getDependencies, getDependents, getLanguageCoverage, getNodeMeta, hasCoverageData, isChangeImpactCacheValid, loadChangeImpactCache, loadCoverageMap, loadMokoshConfig, parseQuery, proposeAffectedTests, proposeTags, queryCallGraph, queryChangeImpact, queryTypeGraph, registerConfigMatcher, registerMonorepoDetector, registerParser, registerTestLibrary, registerTestPattern, saveChangeImpactCache, slimSerialize, summarizeWorkspacePackages, toMermaid };
package/dist/index.d.ts CHANGED
@@ -442,6 +442,56 @@ declare function saveChangeImpactCache(cache: ChangeImpactCache, cachePath: stri
442
442
  */
443
443
  declare function loadChangeImpactCache(cachePath: string): ChangeImpactCache | null;
444
444
 
445
+ /**
446
+ * Sliding-window (shingle) hashing over a normalized token stream, plus chain-merging of
447
+ * consecutive matching windows into contiguous duplicate blocks. Shared by every language
448
+ * `tokenize()` supports — the shingling step itself has no language awareness at all.
449
+ */
450
+
451
+ interface DuplicateOccurrence {
452
+ file: string;
453
+ startLine: number;
454
+ endLine: number;
455
+ }
456
+ interface DuplicateGroup {
457
+ /** Two locations sharing this duplicated block. */
458
+ occurrences: [DuplicateOccurrence, DuplicateOccurrence];
459
+ /** Line span covered by the block (measured on the first occurrence). */
460
+ lines: number;
461
+ /** Token-window length backing this block, after chain-merging adjacent windows. */
462
+ tokens: number;
463
+ }
464
+
465
+ interface FindDuplicatesOptions {
466
+ /** Minimum duplicated block size, in source lines, to report (default 6). */
467
+ minLines?: number | undefined;
468
+ /** Shingle window size, in tokens — the smallest duplicate the scan can detect (default 15). */
469
+ windowSize?: number | undefined;
470
+ /** When true (default), string/number literals are normalized too, so only structural shape
471
+ * — not the specific values used — drives a match. Set false for stricter, Type-1-only matching. */
472
+ ignoreLiterals?: boolean | undefined;
473
+ /** Caps the number of duplicate blocks returned, largest-first (default 50). */
474
+ limit?: number | undefined;
475
+ /** Directory names to exclude, matched against any path segment (default `DEFAULT_IGNORE_DIRS`
476
+ * — `node_modules`, `dist`, `.git`, `mokosh-cache`, `coverage`, etc.). Pass `[]` to disable. */
477
+ ignoreDirs?: readonly string[] | undefined;
478
+ }
479
+ /**
480
+ * @description Scans every file already present in `graph` for cross-file (and within-file)
481
+ * duplicated code, using a language-agnostic token-shingling pipeline: comments are stripped
482
+ * per `FileType`, identifiers (and, by default, literals) are normalized to placeholders so
483
+ * renamed-variable copies still match, then a sliding token window is hashed and chain-merged
484
+ * into contiguous blocks. Works uniformly across every language in `DEFAULT_EXTENSIONS`.
485
+ * @param graph - The graph to scan; its node paths (already ignore-rule-filtered) are the file
486
+ * list, re-read from disk since duplication data isn't cached on `FileNode`.
487
+ * @param rootDir - Absolute project root that graph paths are relative to.
488
+ * @param options - `minLines`/`windowSize` tune sensitivity; `ignoreLiterals` toggles Type-2 vs
489
+ * Type-1 matching; `ignoreDirs` excludes files under matching directory names; `limit` caps
490
+ * results. Lock files are always excluded, independent of `ignoreDirs`.
491
+ * @returns Duplicate blocks, each a pair of occurrences, sorted largest-first.
492
+ */
493
+ declare function findDuplicates(graph: Graph, rootDir: string, options?: FindDuplicatesOptions): Promise<DuplicateGroup[]>;
494
+
445
495
  /** Controls how aggressively `detectFeatures` promotes files to features. */
446
496
  interface FeatureDetectionOptions {
447
497
  /**
@@ -1303,4 +1353,4 @@ declare function createWorkspaceGraph(rootDir: string, options?: {
1303
1353
  */
1304
1354
  declare function getAllProjectFiles(rootDir: string, options?: ScanOptions): string[];
1305
1355
 
1306
- export { type ApiSurface, type ApplyTagsFileResult, type ApplyTagsResult, CALL_EDGE_TYPES, CallEdge, type CalleeEntry, type CallerEntry$1 as CallerEntry, type ChangeImpactCache, type ComplexFunctionEntry, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type DependencyGraph, EXPORT_TRACKING_TYPES, type ExportKind, type FeatureDetectionOptions, type FeatureDomain, type FeatureGraph, type FeatureGraphOptions, type FeatureInfo, FileNode, FileType, type FindComplexFunctionsOptions, type FunctionCallInfo, type GetAffectedOptions, type GetCallersOptions, Graph, type CallerEntry as GraphCallerEntry, type GraphExporter, IMPORT_SYMBOL_TYPES, ImportEdge, type LanguageCoverage, MermaidExporter, type ModuleResponsibility, type ModuleRole, type MokoshConfig, type MonorepoDetector, type MonorepoLayout, NodeCategory, type NodeMeta, type NodeQuery, type ParallelParsingOption, type PathWithSymbols, type ProposeTagsOptions, type PublicExport, type ResponsibilityGraph, type ScanOptions, type SerializedGraph, type SerializedWorkspaceGraph, type SlimNode, type SlimSerializedGraph, StructuredTag, type SymbolCaller, type SymbolImporter, type SymbolMatch, type SymbolPrecision, SymbolTraversalContext, type TestNodeIdentifier, type TraversalOptions, type TraversalVisitor, type TypeEdge, type TypeGraph, type TypeKind, type TypeNode, type TypeQueryResult, WorkspaceGraph, type WorkspacePackage, type WorkspacePackageSummary, type WorkspacePackagesSummary, applyConfig, applyTags, buildApiSurface, buildChangeImpactCache, buildFeatureGraph, buildResponsibilityGraph, buildTypeGraph, computeGraphHash, configToGraphOptions, createImportMap, createWorkspaceGraph, detectAllEntryPoints, detectEntryPoint, detectFeatures, detectMonorepo, filterGraph, findComplexFunctions, findSymbol, getAffected, getAllProjectFiles, getCallers, getDependencies, getDependents, getLanguageCoverage, getNodeMeta, hasCoverageData, isChangeImpactCacheValid, loadChangeImpactCache, loadCoverageMap, loadMokoshConfig, parseQuery, proposeAffectedTests, proposeTags, queryCallGraph, queryChangeImpact, queryTypeGraph, registerConfigMatcher, registerMonorepoDetector, registerParser, registerTestLibrary, registerTestPattern, saveChangeImpactCache, slimSerialize, summarizeWorkspacePackages, toMermaid };
1356
+ export { type ApiSurface, type ApplyTagsFileResult, type ApplyTagsResult, CALL_EDGE_TYPES, CallEdge, type CalleeEntry, type CallerEntry$1 as CallerEntry, type ChangeImpactCache, type ComplexFunctionEntry, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type DependencyGraph, type DuplicateGroup, type DuplicateOccurrence, EXPORT_TRACKING_TYPES, type ExportKind, type FeatureDetectionOptions, type FeatureDomain, type FeatureGraph, type FeatureGraphOptions, type FeatureInfo, FileNode, FileType, type FindComplexFunctionsOptions, type FindDuplicatesOptions, type FunctionCallInfo, type GetAffectedOptions, type GetCallersOptions, Graph, type CallerEntry as GraphCallerEntry, type GraphExporter, IMPORT_SYMBOL_TYPES, ImportEdge, type LanguageCoverage, MermaidExporter, type ModuleResponsibility, type ModuleRole, type MokoshConfig, type MonorepoDetector, type MonorepoLayout, NodeCategory, type NodeMeta, type NodeQuery, type ParallelParsingOption, type PathWithSymbols, type ProposeTagsOptions, type PublicExport, type ResponsibilityGraph, type ScanOptions, type SerializedGraph, type SerializedWorkspaceGraph, type SlimNode, type SlimSerializedGraph, StructuredTag, type SymbolCaller, type SymbolImporter, type SymbolMatch, type SymbolPrecision, SymbolTraversalContext, type TestNodeIdentifier, type TraversalOptions, type TraversalVisitor, type TypeEdge, type TypeGraph, type TypeKind, type TypeNode, type TypeQueryResult, WorkspaceGraph, type WorkspacePackage, type WorkspacePackageSummary, type WorkspacePackagesSummary, applyConfig, applyTags, buildApiSurface, buildChangeImpactCache, buildFeatureGraph, buildResponsibilityGraph, buildTypeGraph, computeGraphHash, configToGraphOptions, createImportMap, createWorkspaceGraph, detectAllEntryPoints, detectEntryPoint, detectFeatures, detectMonorepo, filterGraph, findComplexFunctions, findDuplicates, findSymbol, getAffected, getAllProjectFiles, getCallers, getDependencies, getDependents, getLanguageCoverage, getNodeMeta, hasCoverageData, isChangeImpactCacheValid, loadChangeImpactCache, loadCoverageMap, loadMokoshConfig, parseQuery, proposeAffectedTests, proposeTags, queryCallGraph, queryChangeImpact, queryTypeGraph, registerConfigMatcher, registerMonorepoDetector, registerParser, registerTestLibrary, registerTestPattern, saveChangeImpactCache, slimSerialize, summarizeWorkspacePackages, toMermaid };