@omfalos/mokosh 0.2.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
@@ -357,8 +357,9 @@ interface FunctionCallInfo {
357
357
  * field matches `functionName`. Callees are found by looking at the defining
358
358
  * file's `callEdges` for edges whose `from` field matches `functionName`.
359
359
  *
360
- * Call edges are populated only for TypeScript/JavaScript files. Functions in
361
- * other language files will return empty `callers` and `callees` arrays.
360
+ * Call edges are populated only for TypeScript/JavaScript, Go, and Python files
361
+ * (see `CALL_EDGE_TYPES` in `../language-support`). Functions in other language
362
+ * files will return empty `callers` and `callees` arrays.
362
363
  *
363
364
  * @param {Graph} graph - The import graph that carries `callEdges` on each node.
364
365
  * @param {string} functionName - Exact name of the function to look up.
@@ -441,6 +442,56 @@ declare function saveChangeImpactCache(cache: ChangeImpactCache, cachePath: stri
441
442
  */
442
443
  declare function loadChangeImpactCache(cachePath: string): ChangeImpactCache | null;
443
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
+
444
495
  /** Controls how aggressively `detectFeatures` promotes files to features. */
445
496
  interface FeatureDetectionOptions {
446
497
  /**
@@ -956,7 +1007,8 @@ interface FindComplexFunctionsOptions {
956
1007
  }
957
1008
  /**
958
1009
  * @description Scans every file's per-function complexity breakdown and returns functions/methods
959
- * at or above the given threshold, sorted worst-first. TypeScript/JavaScript only.
1010
+ * at or above the given threshold, sorted worst-first. Populated for TypeScript/JavaScript, Go,
1011
+ * and Python.
960
1012
  * @param graph - The graph to scan.
961
1013
  * @param options - `metric` picks which score to threshold/sort on (default `cognitiveComplexity`); `threshold` is the minimum score to include (default 10); `limit` caps the results (default 20).
962
1014
  * @returns Matching functions, sorted worst-first.
@@ -1012,7 +1064,7 @@ declare function hasCoverageData(graph: Graph): boolean;
1012
1064
 
1013
1065
  /** Symbol-name lookup across the whole graph — generalizes queryCallGraph beyond TS/JS functions. */
1014
1066
 
1015
- type SymbolPrecision = "call" | "import-symbol" | "file-level";
1067
+ type SymbolPrecision = "call" | "file-level";
1016
1068
  interface SymbolCaller {
1017
1069
  file: string;
1018
1070
  callerFunction: string;
@@ -1031,9 +1083,11 @@ interface SymbolMatch {
1031
1083
  /**
1032
1084
  * @description Finds every file that exports a symbol by name, with the best available
1033
1085
  * usage info per match. Precision depends on what the defining file's language parser
1034
- * tracks: TS/JS gets function-level callers via call edges, Python gets named-import
1035
- * tracking, everything else falls back to whole-file dependents (import-level, not
1036
- * symbol-level the file might not even use this specific export).
1086
+ * tracks: TS/JS, Go, and Python get function-level callers via call edges (`"call"`);
1087
+ * everything else falls back to whole-file dependents (`"file-level"` — import-level, not
1088
+ * symbol-level, since the file might not even use this specific export). Coverage still
1089
+ * differs across the `"call"` languages: TS/JS tracks any directly imported symbol, Go only
1090
+ * package-qualified calls, Python only bare calls to `from <module> import <name>` symbols.
1037
1091
  * @param graph - The graph to search.
1038
1092
  * @param name - Exact export name to look up.
1039
1093
  * @returns One entry per file that exports `name`; empty if no file does (including
@@ -1299,4 +1353,4 @@ declare function createWorkspaceGraph(rootDir: string, options?: {
1299
1353
  */
1300
1354
  declare function getAllProjectFiles(rootDir: string, options?: ScanOptions): string[];
1301
1355
 
1302
- 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
@@ -357,8 +357,9 @@ interface FunctionCallInfo {
357
357
  * field matches `functionName`. Callees are found by looking at the defining
358
358
  * file's `callEdges` for edges whose `from` field matches `functionName`.
359
359
  *
360
- * Call edges are populated only for TypeScript/JavaScript files. Functions in
361
- * other language files will return empty `callers` and `callees` arrays.
360
+ * Call edges are populated only for TypeScript/JavaScript, Go, and Python files
361
+ * (see `CALL_EDGE_TYPES` in `../language-support`). Functions in other language
362
+ * files will return empty `callers` and `callees` arrays.
362
363
  *
363
364
  * @param {Graph} graph - The import graph that carries `callEdges` on each node.
364
365
  * @param {string} functionName - Exact name of the function to look up.
@@ -441,6 +442,56 @@ declare function saveChangeImpactCache(cache: ChangeImpactCache, cachePath: stri
441
442
  */
442
443
  declare function loadChangeImpactCache(cachePath: string): ChangeImpactCache | null;
443
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
+
444
495
  /** Controls how aggressively `detectFeatures` promotes files to features. */
445
496
  interface FeatureDetectionOptions {
446
497
  /**
@@ -956,7 +1007,8 @@ interface FindComplexFunctionsOptions {
956
1007
  }
957
1008
  /**
958
1009
  * @description Scans every file's per-function complexity breakdown and returns functions/methods
959
- * at or above the given threshold, sorted worst-first. TypeScript/JavaScript only.
1010
+ * at or above the given threshold, sorted worst-first. Populated for TypeScript/JavaScript, Go,
1011
+ * and Python.
960
1012
  * @param graph - The graph to scan.
961
1013
  * @param options - `metric` picks which score to threshold/sort on (default `cognitiveComplexity`); `threshold` is the minimum score to include (default 10); `limit` caps the results (default 20).
962
1014
  * @returns Matching functions, sorted worst-first.
@@ -1012,7 +1064,7 @@ declare function hasCoverageData(graph: Graph): boolean;
1012
1064
 
1013
1065
  /** Symbol-name lookup across the whole graph — generalizes queryCallGraph beyond TS/JS functions. */
1014
1066
 
1015
- type SymbolPrecision = "call" | "import-symbol" | "file-level";
1067
+ type SymbolPrecision = "call" | "file-level";
1016
1068
  interface SymbolCaller {
1017
1069
  file: string;
1018
1070
  callerFunction: string;
@@ -1031,9 +1083,11 @@ interface SymbolMatch {
1031
1083
  /**
1032
1084
  * @description Finds every file that exports a symbol by name, with the best available
1033
1085
  * usage info per match. Precision depends on what the defining file's language parser
1034
- * tracks: TS/JS gets function-level callers via call edges, Python gets named-import
1035
- * tracking, everything else falls back to whole-file dependents (import-level, not
1036
- * symbol-level the file might not even use this specific export).
1086
+ * tracks: TS/JS, Go, and Python get function-level callers via call edges (`"call"`);
1087
+ * everything else falls back to whole-file dependents (`"file-level"` — import-level, not
1088
+ * symbol-level, since the file might not even use this specific export). Coverage still
1089
+ * differs across the `"call"` languages: TS/JS tracks any directly imported symbol, Go only
1090
+ * package-qualified calls, Python only bare calls to `from <module> import <name>` symbols.
1037
1091
  * @param graph - The graph to search.
1038
1092
  * @param name - Exact export name to look up.
1039
1093
  * @returns One entry per file that exports `name`; empty if no file does (including
@@ -1299,4 +1353,4 @@ declare function createWorkspaceGraph(rootDir: string, options?: {
1299
1353
  */
1300
1354
  declare function getAllProjectFiles(rootDir: string, options?: ScanOptions): string[];
1301
1355
 
1302
- 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 };