@kridaydave/code-mapper 1.0.0 → 1.0.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +1 -0
  3. package/bin/code-mapper.mjs +86 -0
  4. package/dist/graph/GraphAnalyzer.js +32 -65
  5. package/dist/graph/GraphAnalyzer.js.map +1 -1
  6. package/dist/graph/GraphBuilder.js +18 -45
  7. package/dist/graph/GraphBuilder.js.map +1 -1
  8. package/dist/index.js +100 -23
  9. package/dist/index.js.map +1 -1
  10. package/dist/mcp/cache.js +8 -17
  11. package/dist/mcp/cache.js.map +1 -1
  12. package/dist/mcp/resources.js +5 -1
  13. package/dist/mcp/resources.js.map +1 -1
  14. package/dist/mcp/tools.js +190 -35
  15. package/dist/mcp/tools.js.map +1 -1
  16. package/dist/parser/ComplexityAnalyzer.js +19 -2
  17. package/dist/parser/ComplexityAnalyzer.js.map +1 -1
  18. package/dist/parser/FileAnalyzer.js +8 -30
  19. package/dist/parser/FileAnalyzer.js.map +1 -1
  20. package/dist/parser/ProjectParser.js +8 -5
  21. package/dist/parser/ProjectParser.js.map +1 -1
  22. package/dist/parser/ProjectParser.test.js +1 -17
  23. package/dist/parser/ProjectParser.test.js.map +1 -1
  24. package/dist/tui/index.js +239 -0
  25. package/dist/tui/index.js.map +1 -0
  26. package/package.json +82 -35
  27. package/AGENTS.md +0 -174
  28. package/docs/PHASE2_PLAN.md +0 -435
  29. package/fixtures/test-project/calculator.ts +0 -28
  30. package/fixtures/test-project/index.ts +0 -2
  31. package/fixtures/test-project/math.ts +0 -11
  32. package/src/graph/Graph.test.ts +0 -222
  33. package/src/graph/GraphAnalyzer.ts +0 -502
  34. package/src/graph/GraphBuilder.ts +0 -258
  35. package/src/graph/types.ts +0 -42
  36. package/src/index.ts +0 -38
  37. package/src/mcp/cache.ts +0 -89
  38. package/src/mcp/resources.ts +0 -137
  39. package/src/mcp/tools.test.ts +0 -104
  40. package/src/mcp/tools.ts +0 -529
  41. package/src/parser/ComplexityAnalyzer.ts +0 -275
  42. package/src/parser/FileAnalyzer.ts +0 -215
  43. package/src/parser/ProjectParser.test.ts +0 -96
  44. package/src/parser/ProjectParser.ts +0 -172
  45. package/src/parser/types.ts +0 -77
  46. package/src/types/graphology-pagerank.d.ts +0 -20
  47. package/tsconfig.json +0 -17
  48. package/vitest.config.ts +0 -15
@@ -1,172 +0,0 @@
1
- import { Project } from "ts-morph";
2
- import { resolve, join } from "node:path";
3
- import * as fs from "node:fs";
4
- import { FileInfo, ParseResult } from "./types.js";
5
- import { FileAnalyzer } from "./FileAnalyzer.js";
6
-
7
- const IGNORE_PATTERNS = [
8
- /node_modules/,
9
- /dist/,
10
- /build/,
11
- /\.git/,
12
- /coverage/,
13
- /\.next/,
14
- /\.nuxt/,
15
- /\.svelte-kit/,
16
- /__tests__/,
17
- /\.cache/,
18
- /^\.env$/,
19
- /credentials\.json/,
20
- /^secrets\./,
21
- ];
22
-
23
- const MAX_FILES = 10000;
24
-
25
- export interface ProgressInfo {
26
- phase: "scanning" | "parsing" | "analyzing";
27
- current: number;
28
- total: number;
29
- currentFile?: string;
30
- percentComplete: number;
31
- }
32
-
33
- export type ProgressCallback = (progress: ProgressInfo) => void;
34
-
35
- export interface ParseOptions {
36
- directory: string;
37
- onProgress?: ProgressCallback;
38
- maxFiles?: number;
39
- }
40
-
41
- export class ProjectParser {
42
- private project: Project;
43
- private cache: Map<string, ParseResult> = new Map();
44
-
45
- constructor() {
46
- this.project = new Project({
47
- skipAddingFilesFromTsConfig: true,
48
- compilerOptions: {
49
- allowJs: true,
50
- checkJs: false,
51
- noEmit: true,
52
- },
53
- });
54
- }
55
-
56
- async parse(directory: string, options?: ParseOptions): Promise<ParseResult> {
57
- const absoluteDir = resolve(directory);
58
- const onProgress = options?.onProgress;
59
- const maxFiles = options?.maxFiles ?? MAX_FILES;
60
-
61
- if (!fs.existsSync(absoluteDir)) {
62
- throw new Error(`Directory does not exist: ${absoluteDir}`);
63
- }
64
- if (!fs.statSync(absoluteDir).isDirectory()) {
65
- throw new Error(`Path is not a directory: ${absoluteDir}`);
66
- }
67
-
68
- if (this.cache.has(absoluteDir)) {
69
- return this.cache.get(absoluteDir)!;
70
- }
71
-
72
- if (onProgress) {
73
- onProgress({ phase: "scanning", current: 0, total: 0, percentComplete: 0 });
74
- }
75
-
76
- const files = this.findFiles(absoluteDir);
77
-
78
- if (files.length > maxFiles) {
79
- throw new Error(`Too many files (${files.length}). Maximum allowed: ${maxFiles}. Consider scanning a subdirectory.`);
80
- }
81
-
82
- if (files.length === 0) {
83
- const empty: ParseResult = {
84
- directory: absoluteDir,
85
- files: [],
86
- totalFiles: 0,
87
- totalFunctions: 0,
88
- totalClasses: 0,
89
- totalImports: 0,
90
- totalExports: 0,
91
- };
92
- this.cache.set(absoluteDir, empty);
93
- return empty;
94
- }
95
-
96
- const sourceFiles = this.project.getSourceFiles();
97
- for (const sf of sourceFiles) {
98
- this.project.removeSourceFile(sf);
99
- }
100
- this.project.addSourceFilesAtPaths(files);
101
-
102
- const analyzer = new FileAnalyzer(this.project, absoluteDir);
103
-
104
- const fileInfos: FileInfo[] = [];
105
- const total = files.length;
106
- for (let i = 0; i < this.project.getSourceFiles().length; i++) {
107
- const sourceFile = this.project.getSourceFiles()[i];
108
- fileInfos.push(analyzer.analyze(sourceFile));
109
-
110
- if (onProgress) {
111
- const currentFile = sourceFile.getFilePath();
112
- onProgress({
113
- phase: "parsing",
114
- current: i + 1,
115
- total,
116
- currentFile,
117
- percentComplete: Math.round(((i + 1) / total) * 100),
118
- });
119
- }
120
- }
121
-
122
- const result: ParseResult = {
123
- directory: absoluteDir,
124
- files: fileInfos,
125
- totalFiles: fileInfos.length,
126
- totalFunctions: fileInfos.reduce((sum, f) => sum + f.functions.length, 0),
127
- totalClasses: fileInfos.reduce((sum, f) => sum + f.classes.length, 0),
128
- totalImports: fileInfos.reduce((sum, f) => sum + f.imports.length, 0),
129
- totalExports: fileInfos.reduce((sum, f) => sum + f.exports.length, 0),
130
- };
131
-
132
- if (onProgress) {
133
- onProgress({ phase: "analyzing", current: total, total, percentComplete: 100 });
134
- }
135
-
136
- this.cache.set(absoluteDir, result);
137
- return result;
138
- }
139
-
140
- clearCache(directory?: string): void {
141
- if (directory) {
142
- this.cache.delete(resolve(directory));
143
- } else {
144
- this.cache.clear();
145
- }
146
- }
147
-
148
- private findFiles(directory: string): string[] {
149
- const results: string[] = [];
150
-
151
- const walk = (dir: string) => {
152
- const entries = fs.readdirSync(dir, { withFileTypes: true });
153
-
154
- for (const entry of entries) {
155
- const fullPath = join(dir, entry.name);
156
-
157
- if (entry.isDirectory()) {
158
- if (!IGNORE_PATTERNS.some(pattern => pattern.test(fullPath))) {
159
- walk(fullPath);
160
- }
161
- } else if (entry.isFile()) {
162
- if (/\.(ts|tsx|js|jsx|mts|mjs|mcts|cjs|cts)$/i.test(entry.name)) {
163
- results.push(fullPath);
164
- }
165
- }
166
- }
167
- };
168
-
169
- walk(directory);
170
- return results;
171
- }
172
- }
@@ -1,77 +0,0 @@
1
- export interface FunctionInfo {
2
- name: string;
3
- filePath: string;
4
- lineNumber: number;
5
- parameters: string[];
6
- returnType: string;
7
- isAsync: boolean;
8
- isExported: boolean;
9
- isDefaultExport: boolean;
10
- body: string;
11
- }
12
-
13
- export interface MethodInfo {
14
- name: string;
15
- parameters: string[];
16
- returnType: string;
17
- isStatic: boolean;
18
- isAsync: boolean;
19
- lineNumber: number;
20
- }
21
-
22
- export interface PropertyInfo {
23
- name: string;
24
- type: string;
25
- isStatic: boolean;
26
- isReadonly: boolean;
27
- lineNumber: number;
28
- }
29
-
30
- export interface ClassInfo {
31
- name: string;
32
- filePath: string;
33
- lineNumber: number;
34
- isExported: boolean;
35
- isDefaultExport: boolean;
36
- extends: string | null;
37
- implements: string[];
38
- methods: MethodInfo[];
39
- properties: PropertyInfo[];
40
- }
41
-
42
- export interface ImportInfo {
43
- namedImports: string[];
44
- defaultImport: string | null;
45
- namespaceImport: string | null;
46
- moduleSpecifier: string;
47
- filePath: string;
48
- lineNumber: number;
49
- }
50
-
51
- export interface ExportInfo {
52
- name: string;
53
- kind: "function" | "class" | "variable" | "type" | "interface" | "re-export";
54
- isDefault: boolean;
55
- filePath: string;
56
- lineNumber: number;
57
- }
58
-
59
- export interface FileInfo {
60
- filePath: string;
61
- relativePath: string;
62
- functions: FunctionInfo[];
63
- classes: ClassInfo[];
64
- imports: ImportInfo[];
65
- exports: ExportInfo[];
66
- totalLines: number;
67
- }
68
-
69
- export interface ParseResult {
70
- directory: string;
71
- files: FileInfo[];
72
- totalFiles: number;
73
- totalFunctions: number;
74
- totalClasses: number;
75
- totalImports: number;
76
- totalExports: number;
77
- }
@@ -1,20 +0,0 @@
1
- declare module "graphology-metrics/centrality/pagerank" {
2
- import type { AbstractGraph, Attributes } from "graphology-types";
3
-
4
- type PagerankOptions<EdgeAttributes extends Attributes> = {
5
- nodePagerankAttribute?: string;
6
- getEdgeWeight?: keyof EdgeAttributes | null;
7
- alpha?: number;
8
- maxIterations?: number;
9
- tolerance?: number;
10
- };
11
-
12
- type PagerankMapping = { [node: string]: number };
13
-
14
- function pagerank<NodeAttributes extends Attributes = Attributes, EdgeAttributes extends Attributes = Attributes>(
15
- graph: AbstractGraph<NodeAttributes, EdgeAttributes>,
16
- options?: PagerankOptions<EdgeAttributes>
17
- ): PagerankMapping;
18
-
19
- export default pagerank;
20
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "sourceMap": true,
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "types": ["node"]
14
- },
15
- "include": ["src/**/*"],
16
- "exclude": ["node_modules", "dist"]
17
- }
package/vitest.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: "node",
7
- include: ["src/**/*.test.ts", "src/**/*.spec.ts"],
8
- coverage: {
9
- provider: "v8",
10
- reporter: ["text", "json", "html"],
11
- include: ["src/**/*.ts"],
12
- exclude: ["src/**/*.test.ts", "src/**/*.spec.ts", "src/index.ts"],
13
- },
14
- },
15
- });