codemelt-core 0.1.0

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 (82) hide show
  1. package/dist/analyzer/compressionAnalyzer.d.ts +4 -0
  2. package/dist/analyzer/compressionAnalyzer.d.ts.map +1 -0
  3. package/dist/analyzer/compressionAnalyzer.js +21 -0
  4. package/dist/analyzer/index.d.ts +3 -0
  5. package/dist/analyzer/index.d.ts.map +1 -0
  6. package/dist/analyzer/index.js +2 -0
  7. package/dist/analyzer/prompts/onboarding.d.ts +3 -0
  8. package/dist/analyzer/prompts/onboarding.d.ts.map +1 -0
  9. package/dist/analyzer/prompts/onboarding.js +14 -0
  10. package/dist/analyzer/prompts/performance.d.ts +3 -0
  11. package/dist/analyzer/prompts/performance.d.ts.map +1 -0
  12. package/dist/analyzer/prompts/performance.js +18 -0
  13. package/dist/analyzer/prompts/refactor.d.ts +3 -0
  14. package/dist/analyzer/prompts/refactor.d.ts.map +1 -0
  15. package/dist/analyzer/prompts/refactor.js +19 -0
  16. package/dist/analyzer/purposeDetector.d.ts +4 -0
  17. package/dist/analyzer/purposeDetector.d.ts.map +1 -0
  18. package/dist/analyzer/purposeDetector.js +141 -0
  19. package/dist/analyzer/readinessAnalyzer.d.ts +4 -0
  20. package/dist/analyzer/readinessAnalyzer.d.ts.map +1 -0
  21. package/dist/analyzer/readinessAnalyzer.js +111 -0
  22. package/dist/analyzer/repositoryAnalyzer.d.ts +4 -0
  23. package/dist/analyzer/repositoryAnalyzer.d.ts.map +1 -0
  24. package/dist/analyzer/repositoryAnalyzer.js +231 -0
  25. package/dist/analyzer/rules.d.ts +3 -0
  26. package/dist/analyzer/rules.d.ts.map +1 -0
  27. package/dist/analyzer/rules.js +156 -0
  28. package/dist/analyzer/types.d.ts +70 -0
  29. package/dist/analyzer/types.d.ts.map +1 -0
  30. package/dist/analyzer/types.js +1 -0
  31. package/dist/analyzer/workflowGenerator.d.ts +3 -0
  32. package/dist/analyzer/workflowGenerator.d.ts.map +1 -0
  33. package/dist/analyzer/workflowGenerator.js +22 -0
  34. package/dist/filters/shouldIgnore.d.ts +2 -0
  35. package/dist/filters/shouldIgnore.d.ts.map +1 -0
  36. package/dist/filters/shouldIgnore.js +10 -0
  37. package/dist/formatter/generateRepositoryContext.d.ts +10 -0
  38. package/dist/formatter/generateRepositoryContext.d.ts.map +1 -0
  39. package/dist/formatter/generateRepositoryContext.js +311 -0
  40. package/dist/index.d.ts +13 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +12 -0
  43. package/dist/prioritizer/scoreFile.d.ts +3 -0
  44. package/dist/prioritizer/scoreFile.d.ts.map +1 -0
  45. package/dist/prioritizer/scoreFile.js +25 -0
  46. package/dist/prioritizer/sortFiles.d.ts +3 -0
  47. package/dist/prioritizer/sortFiles.d.ts.map +1 -0
  48. package/dist/prioritizer/sortFiles.js +9 -0
  49. package/dist/scanner/importanceDetector.d.ts +3 -0
  50. package/dist/scanner/importanceDetector.d.ts.map +1 -0
  51. package/dist/scanner/importanceDetector.js +70 -0
  52. package/dist/scanner/scanFiles.d.ts +3 -0
  53. package/dist/scanner/scanFiles.d.ts.map +1 -0
  54. package/dist/scanner/scanFiles.js +127 -0
  55. package/dist/summarizer/extractPatterns.d.ts +12 -0
  56. package/dist/summarizer/extractPatterns.d.ts.map +1 -0
  57. package/dist/summarizer/extractPatterns.js +83 -0
  58. package/dist/summarizer/flowDetector.d.ts +6 -0
  59. package/dist/summarizer/flowDetector.d.ts.map +1 -0
  60. package/dist/summarizer/flowDetector.js +29 -0
  61. package/dist/summarizer/index.d.ts +5 -0
  62. package/dist/summarizer/index.d.ts.map +1 -0
  63. package/dist/summarizer/index.js +25 -0
  64. package/dist/summarizer/inferPurpose.d.ts +10 -0
  65. package/dist/summarizer/inferPurpose.d.ts.map +1 -0
  66. package/dist/summarizer/inferPurpose.js +162 -0
  67. package/dist/summarizer/summarizeDirectory.d.ts +3 -0
  68. package/dist/summarizer/summarizeDirectory.d.ts.map +1 -0
  69. package/dist/summarizer/summarizeDirectory.js +87 -0
  70. package/dist/summarizer/summarizeFile.d.ts +4 -0
  71. package/dist/summarizer/summarizeFile.d.ts.map +1 -0
  72. package/dist/summarizer/summarizeFile.js +45 -0
  73. package/dist/summarizer/types.d.ts +35 -0
  74. package/dist/summarizer/types.d.ts.map +1 -0
  75. package/dist/summarizer/types.js +1 -0
  76. package/dist/tokenizer/estimateTokens.d.ts +2 -0
  77. package/dist/tokenizer/estimateTokens.d.ts.map +1 -0
  78. package/dist/tokenizer/estimateTokens.js +3 -0
  79. package/dist/tokenizer/estimateWords.d.ts +2 -0
  80. package/dist/tokenizer/estimateWords.d.ts.map +1 -0
  81. package/dist/tokenizer/estimateWords.js +6 -0
  82. package/package.json +28 -0
@@ -0,0 +1,156 @@
1
+ export const TECHNOLOGY_RULES = [
2
+ // --- 1. FRAMEWORKS & LIBRARIES ---
3
+ {
4
+ name: "Next.js",
5
+ category: "framework",
6
+ dependencies: ["next"],
7
+ filePatterns: ["next.config.js", "next.config.mjs", "next.config.ts"]
8
+ },
9
+ {
10
+ name: "React",
11
+ category: "framework",
12
+ dependencies: ["react", "react-dom"]
13
+ },
14
+ {
15
+ name: "Vue.js",
16
+ category: "framework",
17
+ dependencies: ["vue"],
18
+ filePatterns: ["nuxt.config.js", "nuxt.config.ts"]
19
+ },
20
+ {
21
+ name: "Angular",
22
+ category: "framework",
23
+ dependencies: ["@angular/core", "@angular/cli"],
24
+ filePatterns: ["angular.json"]
25
+ },
26
+ {
27
+ name: "Svelte / SvelteKit",
28
+ category: "framework",
29
+ dependencies: ["svelte", "@sveltejs/kit"],
30
+ filePatterns: ["svelte.config.js"]
31
+ },
32
+ {
33
+ name: "Express.js",
34
+ category: "framework",
35
+ dependencies: ["express"]
36
+ },
37
+ {
38
+ name: "NestJS",
39
+ category: "framework",
40
+ dependencies: ["@nestjs/core"],
41
+ filePatterns: ["nest-cli.json"]
42
+ },
43
+ // --- 2. DATABASES & ORMS ---
44
+ {
45
+ name: "Prisma (ORM)",
46
+ category: "database",
47
+ dependencies: ["@prisma/client", "prisma"],
48
+ filePatterns: ["schema.prisma"]
49
+ },
50
+ {
51
+ name: "Drizzle (ORM)",
52
+ category: "database",
53
+ dependencies: ["drizzle-orm"],
54
+ filePatterns: ["drizzle.config.ts", "drizzle.config.js"]
55
+ },
56
+ {
57
+ name: "Mongoose / MongoDB",
58
+ category: "database",
59
+ dependencies: ["mongoose", "mongodb"]
60
+ },
61
+ {
62
+ name: "PostgreSQL",
63
+ category: "database",
64
+ dependencies: ["pg", "postgres"]
65
+ },
66
+ {
67
+ name: "MySQL / MariaDB",
68
+ category: "database",
69
+ dependencies: ["mysql2", "mysql"]
70
+ },
71
+ {
72
+ name: "Redis",
73
+ category: "database",
74
+ dependencies: ["redis", "ioredis"]
75
+ },
76
+ // --- 3. STYLING SYSTEMS ---
77
+ {
78
+ name: "Tailwind CSS",
79
+ category: "styling",
80
+ dependencies: ["tailwindcss", "postcss"],
81
+ filePatterns: ["tailwind.config.js", "tailwind.config.ts", "tailwind.config.cjs"]
82
+ },
83
+ {
84
+ name: "Styled Components",
85
+ category: "styling",
86
+ dependencies: ["styled-components"]
87
+ },
88
+ {
89
+ name: "Emotion",
90
+ category: "styling",
91
+ dependencies: ["@emotion/react", "@emotion/styled"]
92
+ },
93
+ {
94
+ name: "Sass / SCSS",
95
+ category: "styling",
96
+ dependencies: ["sass", "node-sass"]
97
+ },
98
+ // --- 4. RUNTIMES & BUILD TOOLS ---
99
+ {
100
+ name: "Node.js",
101
+ category: "runtime",
102
+ filePatterns: ["package.json"] // Virtually every JS repo uses Node runtime tooling
103
+ },
104
+ {
105
+ name: "Bun",
106
+ category: "runtime",
107
+ filePatterns: ["bun.lockb", "bunfig.toml"]
108
+ },
109
+ {
110
+ name: "Deno",
111
+ category: "runtime",
112
+ filePatterns: ["deno.json", "deno.jsonc"]
113
+ },
114
+ // --- 5. STATE MANAGEMENT ---
115
+ {
116
+ name: "Redux",
117
+ category: "state-management",
118
+ dependencies: ["redux", "@reduxjs/toolkit", "react-redux"]
119
+ },
120
+ {
121
+ name: "Zustand",
122
+ category: "state-management",
123
+ dependencies: ["zustand"]
124
+ },
125
+ {
126
+ name: "Jotai",
127
+ category: "state-management",
128
+ dependencies: ["jotai"]
129
+ },
130
+ {
131
+ name: "Recoil",
132
+ category: "state-management",
133
+ dependencies: ["recoil"]
134
+ },
135
+ {
136
+ name: "Pinia (Vue)",
137
+ category: "state-management",
138
+ dependencies: ["pinia"]
139
+ },
140
+ // --- 6. REALTIME & COMMUNICATION ---
141
+ {
142
+ name: "Socket.io",
143
+ category: "realtime",
144
+ dependencies: ["socket.io", "socket.io-client"]
145
+ },
146
+ {
147
+ name: "Pusher",
148
+ category: "realtime",
149
+ dependencies: ["pusher", "pusher-js"]
150
+ },
151
+ {
152
+ name: "ws (WebSocket Client)",
153
+ category: "realtime",
154
+ dependencies: ["ws"]
155
+ }
156
+ ];
@@ -0,0 +1,70 @@
1
+ import { SemanticRepositoryAnalysis } from "../summarizer/types.js";
2
+ export type ArchitectureType = "monorepo" | "fullstack-monolith" | "frontend-only" | "backend-api" | "realtime-system" | "unknown";
3
+ export type RepositoryPurpose = "developer-tooling" | "saas-dashboard" | "chat-application" | "ecommerce-platform" | "cms" | "portfolio" | "api-platform" | "unknown";
4
+ export interface PurposeResult {
5
+ name: RepositoryPurpose;
6
+ confidence: number;
7
+ confidenceTier?: "Strong" | "Moderate" | "Low";
8
+ matchedSignals: string[];
9
+ }
10
+ export type DetectionCategory = "framework" | "database" | "runtime" | "state-management" | "realtime" | "styling";
11
+ export interface DetectionResult {
12
+ name: string;
13
+ category: DetectionCategory;
14
+ version?: string;
15
+ confidence: number;
16
+ confidenceTier?: "Strong" | "Moderate" | "Low";
17
+ matchedBy: ("dependency" | "file-pattern")[];
18
+ explainability: {
19
+ matchedDependencies: string[];
20
+ matchedFiles: string[];
21
+ };
22
+ }
23
+ export interface CompressionStats {
24
+ originalBytes: number;
25
+ compressedBytes: number;
26
+ originalFilesCount: number;
27
+ compressedFilesCount: number;
28
+ savingsPercentage: number;
29
+ }
30
+ export interface AIReadinessScore {
31
+ score: number;
32
+ breakdown: {
33
+ documentation: number;
34
+ typingQuality: number;
35
+ structureClarity: number;
36
+ configCompleteness: number;
37
+ contextOptimization: number;
38
+ };
39
+ recommendations: string[];
40
+ }
41
+ export interface AIWorkflowPrompt {
42
+ title: string;
43
+ description: string;
44
+ prompt: string;
45
+ }
46
+ export interface ProjectAnalysis {
47
+ technologies: DetectionResult[];
48
+ architecture: ArchitectureType;
49
+ purpose: PurposeResult;
50
+ readinessScore: AIReadinessScore;
51
+ prompts: AIWorkflowPrompt[];
52
+ compression: CompressionStats;
53
+ summary: string;
54
+ fileCount: number;
55
+ totalSize: number;
56
+ importanceStats: {
57
+ critical: number;
58
+ high: number;
59
+ normal: number;
60
+ low: number;
61
+ };
62
+ semanticAnalysis?: SemanticRepositoryAnalysis;
63
+ }
64
+ export interface HeuristicRule {
65
+ name: string;
66
+ category: DetectionCategory;
67
+ dependencies?: string[];
68
+ filePatterns?: string[];
69
+ }
70
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analyzer/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GACxB,UAAU,GACV,oBAAoB,GACpB,eAAe,GACf,aAAa,GACb,iBAAiB,GACjB,SAAS,CAAC;AAEd,MAAM,MAAM,iBAAiB,GACzB,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,KAAK,GACL,WAAW,GACX,cAAc,GACd,SAAS,CAAC;AAEd,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,KAAK,CAAC;IAC/C,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,UAAU,GACV,SAAS,GACT,kBAAkB,GAClB,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,KAAK,CAAC;IAC/C,SAAS,EAAE,CAAC,YAAY,GAAG,cAAc,CAAC,EAAE,CAAC;IAC7C,cAAc,EAAE;QACd,mBAAmB,EAAE,MAAM,EAAE,CAAC;QAC9B,YAAY,EAAE,MAAM,EAAE,CAAC;KACxB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE;QACT,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;QACzB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,YAAY,EAAE,gBAAgB,CAAC;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,cAAc,EAAE,gBAAgB,CAAC;IACjC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,WAAW,EAAE,gBAAgB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;CAC/C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { ArchitectureType, DetectionResult, AIWorkflowPrompt } from "./types.js";
2
+ export declare function generateWorkflows(architecture: ArchitectureType, technologies: DetectionResult[]): AIWorkflowPrompt[];
3
+ //# sourceMappingURL=workflowGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowGenerator.d.ts","sourceRoot":"","sources":["../../src/analyzer/workflowGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKjF,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,gBAAgB,EAC9B,YAAY,EAAE,eAAe,EAAE,GAC9B,gBAAgB,EAAE,CAkBpB"}
@@ -0,0 +1,22 @@
1
+ import { getOnboardingPrompt } from "./prompts/onboarding.js";
2
+ import { getRefactorPrompt } from "./prompts/refactor.js";
3
+ import { getPerformancePrompt } from "./prompts/performance.js";
4
+ export function generateWorkflows(architecture, technologies) {
5
+ return [
6
+ {
7
+ title: "Project Onboarding",
8
+ description: "Instructs the AI to guide a new developer through the codebase topology, entrypoints, and local workspace boot instructions.",
9
+ prompt: getOnboardingPrompt(architecture, technologies)
10
+ },
11
+ {
12
+ title: "Refactoring & Abstraction",
13
+ description: "Instructs the AI to audit files for design violations, locate candidate files for refactoring, and provide drop-in cleaner codes.",
14
+ prompt: getRefactorPrompt(architecture, technologies)
15
+ },
16
+ {
17
+ title: "Performance Optimization",
18
+ description: "Instructs the AI to analyze computational loads, locate memory/rendering bottlenecks, and provide high-efficiency replacements.",
19
+ prompt: getPerformancePrompt(architecture, technologies)
20
+ }
21
+ ];
22
+ }
@@ -0,0 +1,2 @@
1
+ export declare function shouldIgnore(path: string, customRules?: string[]): boolean;
2
+ //# sourceMappingURL=shouldIgnore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldIgnore.d.ts","sourceRoot":"","sources":["../../src/filters/shouldIgnore.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E"}
@@ -0,0 +1,10 @@
1
+ import { minimatch } from "minimatch";
2
+ import { DEFAULT_IGNORES, normalizePath } from "@codemelt/shared";
3
+ export function shouldIgnore(path, customRules) {
4
+ const rules = customRules || DEFAULT_IGNORES;
5
+ const normalized = normalizePath(path);
6
+ return rules.some((rule) => minimatch(normalized, rule, {
7
+ matchBase: true,
8
+ dot: true,
9
+ }));
10
+ }
@@ -0,0 +1,10 @@
1
+ import { ScannedFile, ExportMode, ExportIntent } from "@codemelt/shared";
2
+ export declare function generateRepositoryContextChunks(files: ScannedFile[], format?: "markdown" | "xml", mode?: ExportMode, intent?: ExportIntent): Generator<string, void, unknown>;
3
+ /**
4
+ * Standard in-memory context generation.
5
+ * NOTE: For extremely large repositories where memory overhead must be kept to zero,
6
+ * developers should consume the chunk-friendly generator function `generateRepositoryContextChunks`
7
+ * directly (e.g., piping yielded strings into a writable file stream or network response).
8
+ */
9
+ export declare function generateRepositoryContext(files: ScannedFile[], format?: "markdown" | "xml", mode?: ExportMode, intent?: ExportIntent): string;
10
+ //# sourceMappingURL=generateRepositoryContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateRepositoryContext.d.ts","sourceRoot":"","sources":["../../src/formatter/generateRepositoryContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BzE,wBAAiB,+BAA+B,CAC5C,KAAK,EAAE,WAAW,EAAE,EACpB,MAAM,GAAE,UAAU,GAAG,KAAkB,EACvC,IAAI,GAAE,UAAuB,EAC7B,MAAM,GAAE,YAAwB,GACjC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAmSlC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,WAAW,EAAE,EACpB,MAAM,GAAE,UAAU,GAAG,KAAkB,EACvC,IAAI,GAAE,UAAuB,EAC7B,MAAM,GAAE,YAAwB,GACjC,MAAM,CAOR"}
@@ -0,0 +1,311 @@
1
+ import { sortFiles } from "../prioritizer/sortFiles.js";
2
+ import { analyzeRepository } from "../analyzer/repositoryAnalyzer.js";
3
+ function getSemanticFileDescription(path, name) {
4
+ const lowerPath = path.toLowerCase();
5
+ const lowerName = name.toLowerCase();
6
+ if (lowerName === "package.json")
7
+ return "Project dependency and build script definitions";
8
+ if (lowerName === "tsconfig.json")
9
+ return "TypeScript compiler settings";
10
+ if (lowerName === "schema.prisma")
11
+ return "Prisma database schema and models";
12
+ if (lowerName === "tailwind.config.js" || lowerName === "tailwind.config.ts" || lowerName === "tailwind.config.cjs")
13
+ return "Tailwind CSS configuration rules";
14
+ if (lowerName === ".gitignore")
15
+ return "Git ignore rules";
16
+ if (lowerName.endsWith(".d.ts"))
17
+ return "TypeScript ambient declaration file";
18
+ if (lowerPath.includes("route") || lowerPath.includes("api/"))
19
+ return "API route endpoint handler configuration";
20
+ if (lowerPath.includes("controller"))
21
+ return "Controller mapping incoming requests to backend logic";
22
+ if (lowerPath.includes("model") || lowerPath.includes("db/"))
23
+ return "Database data model definition";
24
+ if (lowerPath.includes("store") || lowerPath.includes("state"))
25
+ return "State management module";
26
+ if (lowerPath.includes("component") || lowerPath.includes("ui/"))
27
+ return "User interface view component";
28
+ if (lowerPath.includes("util") || lowerPath.includes("helper"))
29
+ return "Utility functions";
30
+ if (lowerPath.endsWith(".css") || lowerPath.endsWith(".scss"))
31
+ return "Style sheet definition";
32
+ if (lowerPath.endsWith(".html"))
33
+ return "HTML template file";
34
+ return "Source code file";
35
+ }
36
+ export function* generateRepositoryContextChunks(files, format = "markdown", mode = "standard", intent = "general") {
37
+ // 1. Prioritize/Filter files based on Export Mode
38
+ let filteredFiles = files.filter((f) => f.included);
39
+ if (mode === "tiny") {
40
+ // Tiny mode excludes low/normal-importance files, binary, and oversized
41
+ filteredFiles = filteredFiles.filter((f) => (f.importance === "critical" || f.importance === "high") && f.type === "text");
42
+ }
43
+ if (mode === "standard") {
44
+ // Standard mode excludes low-importance files, binary, and oversized
45
+ filteredFiles = filteredFiles.filter((f) => f.importance !== "low" && f.type === "text");
46
+ }
47
+ if (mode === "deep") {
48
+ // Deep mode includes all text files, but excludes oversized/binary
49
+ filteredFiles = filteredFiles.filter((f) => f.type === "text");
50
+ }
51
+ // Maximum mode (mode === "maximum") includes everything (except what's ignored).
52
+ const prioritizedFiles = sortFiles(filteredFiles);
53
+ const includedCount = filteredFiles.length;
54
+ // 2. Perform intelligence repository analysis
55
+ const analysis = analyzeRepository(files);
56
+ const archLabels = {
57
+ "monorepo": "Monorepo Workspace",
58
+ "fullstack-monolith": "Fullstack Monolith",
59
+ "frontend-only": "Frontend Application",
60
+ "backend-api": "Backend API Service",
61
+ "realtime-system": "Realtime Application",
62
+ "unknown": "Software Repository"
63
+ };
64
+ const purposeLabels = {
65
+ "developer-tooling": "Developer Tooling Project",
66
+ "saas-dashboard": "SaaS Dashboard Portal",
67
+ "chat-application": "Chat Application",
68
+ "ecommerce-platform": "Ecommerce Platform",
69
+ "cms": "Content Management System",
70
+ "portfolio": "Portfolio Website",
71
+ "api-platform": "API Platform Service",
72
+ "unknown": "Application"
73
+ };
74
+ // Intent Directive text blocks
75
+ const intentDirectives = {
76
+ "general": "Provide a comprehensive code synthesis and general structural walkthrough.",
77
+ "debugging": "PRIORITY DIRECTIVE: Focus intensely on tracing runtime exceptions, boundary conditions, typing declarations, linter configurations, and environmental setups.",
78
+ "onboarding": "PRIORITY DIRECTIVE: Primed for fast software onboarding. Structure responses around high-level architecture maps, topological flows, and setup triggers.",
79
+ "architecture": "PRIORITY DIRECTIVE: Evaluate architectural structural boundaries, tight-coupling issues, database schemas alignment, and design patterns consistency.",
80
+ "security": "PRIORITY DIRECTIVE: Evaluate third-party dependencies package licenses, environment configurations safety, input validation layers, and security-risk variables."
81
+ };
82
+ // --- XML EXPORT MODE FORMATTING ---
83
+ if (format === "xml") {
84
+ yield `<?xml version="1.0" encoding="UTF-8"?>\n`;
85
+ yield `<repository>\n`;
86
+ let xmlHeader = ` <repository_analysis>\n`;
87
+ xmlHeader += ` <architecture>${analysis.architecture}</architecture>\n`;
88
+ xmlHeader += ` <architecture_label>${archLabels[analysis.architecture]}</architecture_label>\n`;
89
+ xmlHeader += ` <purpose>${analysis.purpose.name}</purpose>\n`;
90
+ xmlHeader += ` <purpose_label>${purposeLabels[analysis.purpose.name]}</purpose_label>\n`;
91
+ xmlHeader += ` <ai_readiness_score>${analysis.readinessScore.score}</ai_readiness_score>\n`;
92
+ if (analysis.compression.savingsPercentage > 0) {
93
+ xmlHeader += ` <compression_savings>${analysis.compression.savingsPercentage.toFixed(1)}%</compression_savings>\n`;
94
+ }
95
+ xmlHeader += ` <intent_directive>${intentDirectives[intent]}</intent_directive>\n`;
96
+ // Compact list of technologies
97
+ xmlHeader += ` <technologies>\n`;
98
+ for (const tech of analysis.technologies) {
99
+ xmlHeader += ` <technology name="${tech.name}" category="${tech.category}" confidence="${tech.confidence.toFixed(2)}" confidence_tier="${tech.confidenceTier || 'Low'}" />\n`;
100
+ }
101
+ xmlHeader += ` </technologies>\n`;
102
+ // Condensed Recommended Workflows
103
+ xmlHeader += ` <recommended_workflows>\n`;
104
+ for (const prompt of analysis.prompts) {
105
+ xmlHeader += ` <workflow type="${prompt.title.toLowerCase().replace(/ & /g, "-").replace(/ /g, "-")}" />\n`;
106
+ }
107
+ xmlHeader += ` </recommended_workflows>\n`;
108
+ // Semantic analysis injections
109
+ if (analysis.semanticAnalysis) {
110
+ const sem = analysis.semanticAnalysis;
111
+ if (sem.entrypoints.length > 0) {
112
+ xmlHeader += ` <entrypoints>\n`;
113
+ for (const ep of sem.entrypoints) {
114
+ xmlHeader += ` <entrypoint path="${ep.path}" type="${ep.entrypointType || 'general'}" summary="${ep.summary}" />\n`;
115
+ }
116
+ xmlHeader += ` </entrypoints>\n`;
117
+ }
118
+ if (sem.routes.length > 0) {
119
+ xmlHeader += ` <routes>\n`;
120
+ for (const r of sem.routes) {
121
+ xmlHeader += ` <route path="${r.path}" method="${r.method}" handler="${r.handlerFile}" />\n`;
122
+ }
123
+ xmlHeader += ` </routes>\n`;
124
+ }
125
+ if (sem.flows.length > 0) {
126
+ xmlHeader += ` <flows>\n`;
127
+ for (const f of sem.flows) {
128
+ xmlHeader += ` <flow name="${f.name}">\n`;
129
+ for (const step of f.steps) {
130
+ xmlHeader += ` <step>${step}</step>\n`;
131
+ }
132
+ xmlHeader += ` </flow>\n`;
133
+ }
134
+ xmlHeader += ` </flows>\n`;
135
+ }
136
+ }
137
+ xmlHeader += ` </repository_analysis>\n\n`;
138
+ yield xmlHeader;
139
+ let xmlMeta = ` <metadata>\n`;
140
+ xmlMeta += ` <generator>CodeMelt AI-Context Generator</generator>\n`;
141
+ xmlMeta += ` <export_mode>${mode}</export_mode>\n`;
142
+ xmlMeta += ` <export_intent>${intent}</export_intent>\n`;
143
+ xmlMeta += ` <total_files>${includedCount}</total_files>\n`;
144
+ xmlMeta += ` </metadata>\n\n`;
145
+ yield xmlMeta;
146
+ // Add Directory Structure Tree
147
+ let xmlDir = ` <directory_structure>\n`;
148
+ const dirRegistered = new Set();
149
+ for (const file of prioritizedFiles) {
150
+ if (analysis.semanticAnalysis) {
151
+ const parts = file.path.split("/");
152
+ parts.pop();
153
+ let currentPath = "";
154
+ for (const part of parts) {
155
+ currentPath = currentPath ? `${currentPath}/${part}` : part;
156
+ if (!dirRegistered.has(currentPath)) {
157
+ dirRegistered.add(currentPath);
158
+ const dirSem = analysis.semanticAnalysis.directorySummaries[currentPath];
159
+ const dirSummary = dirSem ? dirSem.summary : "Directory subfolder";
160
+ xmlDir += ` <directory path="${currentPath}" summary="${dirSummary}" />\n`;
161
+ }
162
+ }
163
+ }
164
+ const sem = analysis.semanticAnalysis?.fileSummaries[file.path];
165
+ const desc = sem?.summary || getSemanticFileDescription(file.path, file.name);
166
+ xmlDir += ` <item path="${file.path}" type="${file.type}" importance="${file.importance}" desc="${desc}" size="${file.size}" is_entrypoint="${sem?.isEntrypoint ? 'true' : 'false'}" />\n`;
167
+ }
168
+ xmlDir += ` </directory_structure>\n\n`;
169
+ yield xmlDir;
170
+ yield ` <files>\n`;
171
+ for (const file of prioritizedFiles) {
172
+ const sem = analysis.semanticAnalysis?.fileSummaries[file.path];
173
+ const summaryVal = sem?.summary || getSemanticFileDescription(file.path, file.name);
174
+ let xmlFile = ` <file path="${file.path}" type="${file.type}" importance="${file.importance}" summary="${summaryVal}" is_entrypoint="${sem?.isEntrypoint ? 'true' : 'false'}">\n`;
175
+ if (file.type === "text") {
176
+ xmlFile += ` <![CDATA[\n${file.content}\n]]>\n`;
177
+ }
178
+ else if (file.type === "binary") {
179
+ xmlFile += ` <!-- Binary file content omitted (${file.size} bytes) -->\n`;
180
+ }
181
+ else if (file.type === "oversized") {
182
+ xmlFile += ` <!-- Oversized file content omitted (${file.size} bytes) -->\n`;
183
+ }
184
+ xmlFile += ` </file>\n`;
185
+ yield xmlFile;
186
+ }
187
+ yield ` </files>\n`;
188
+ yield `</repository>\n`;
189
+ return;
190
+ }
191
+ // --- MARKDOWN EXPORT MODE FORMATTING ---
192
+ yield `# CodeMelt Project Context\n\n`;
193
+ // Semantic XML Boundary Block for LLM Parsing in Markdown Mode
194
+ let mdHeader = `<repository_analysis>\n`;
195
+ mdHeader += `## Repository Architecture Profile\n`;
196
+ mdHeader += `- **Architecture Profile**: ${archLabels[analysis.architecture]}\n`;
197
+ mdHeader += `- **Repository Purpose**: ${purposeLabels[analysis.purpose.name]} (Confidence: ${analysis.purpose.confidenceTier || 'Low'} - ${(analysis.purpose.confidence * 100).toFixed(0)}%)\n`;
198
+ mdHeader += `- **AI Readiness Score**: ${analysis.readinessScore.score} / 100\n`;
199
+ if (analysis.compression.savingsPercentage > 0) {
200
+ mdHeader += `- **Context Compression Savings**: ${analysis.compression.savingsPercentage.toFixed(1)}% (Savings calculated on lockfiles, builds, and media filters)\n`;
201
+ }
202
+ mdHeader += `- **Export Configuration**: Mode [${mode}] / Intent [${intent}]\n`;
203
+ mdHeader += `- **Workflows Directive**: ${intentDirectives[intent]}\n\n`;
204
+ yield mdHeader;
205
+ let mdTech = `## Detected Technology Stack\n`;
206
+ if (analysis.technologies.length === 0) {
207
+ mdTech += `*No prominent framework or library signatures detected in dependencies or configurations.*\n`;
208
+ }
209
+ else {
210
+ for (const tech of analysis.technologies) {
211
+ const versionStr = tech.version ? ` (v${tech.version})` : "";
212
+ mdTech += `- **${tech.name}**${versionStr} - [Category: ${tech.category}] - Confidence: ${tech.confidenceTier || 'Low'} (${(tech.confidence * 100).toFixed(0)}%)\n`;
213
+ }
214
+ }
215
+ yield mdTech;
216
+ // Compact list of suggested workflows
217
+ let mdWorkflows = `\n## Recommended Workflow Invocations\n`;
218
+ for (const prompt of analysis.prompts) {
219
+ const wfKey = prompt.title.toLowerCase().replace(/ & /g, "-").replace(/ /g, "-");
220
+ mdWorkflows += `<recommended_workflow type="${wfKey}" />\n`;
221
+ }
222
+ yield mdWorkflows;
223
+ // Semantic analysis navigation mapping
224
+ if (analysis.semanticAnalysis) {
225
+ const sem = analysis.semanticAnalysis;
226
+ let mdNav = `\n## Navigation & Architecture Map\n`;
227
+ if (sem.entrypoints.length > 0) {
228
+ mdNav += `### System Entrypoints\n`;
229
+ for (const ep of sem.entrypoints) {
230
+ mdNav += `- **${ep.path}** [${ep.entrypointType || 'entrypoint'}] - ${ep.summary}\n`;
231
+ }
232
+ mdNav += `\n`;
233
+ }
234
+ if (sem.routes.length > 0) {
235
+ mdNav += `### API Routing\n`;
236
+ for (const r of sem.routes) {
237
+ mdNav += `- **${r.method} ${r.path}** -> Handled by \`${r.handlerFile.split('/').pop()}\`\n`;
238
+ }
239
+ mdNav += `\n`;
240
+ }
241
+ if (sem.flows.length > 0) {
242
+ mdNav += `### Semantic Data Flows\n`;
243
+ for (const f of sem.flows) {
244
+ mdNav += `- **${f.name}**: ${f.steps.join(" ➔ ")}\n`;
245
+ }
246
+ mdNav += `\n`;
247
+ }
248
+ yield mdNav;
249
+ }
250
+ yield `</repository_analysis>\n\n`;
251
+ // Add Directory Structure Tree in Markdown with semantic descriptors
252
+ let mdDir = `## Directory Structure\n\n\`\`\`text\n`;
253
+ const dirRegisteredMd = new Set();
254
+ for (const file of prioritizedFiles) {
255
+ if (analysis.semanticAnalysis) {
256
+ const parts = file.path.split("/");
257
+ parts.pop();
258
+ let currentPath = "";
259
+ for (const part of parts) {
260
+ currentPath = currentPath ? `${currentPath}/${part}` : part;
261
+ if (!dirRegisteredMd.has(currentPath)) {
262
+ dirRegisteredMd.add(currentPath);
263
+ const dirSem = analysis.semanticAnalysis.directorySummaries[currentPath];
264
+ const dirSummary = dirSem ? dirSem.summary : "Directory subfolder";
265
+ mdDir += `/${currentPath} - ${dirSummary}\n`;
266
+ }
267
+ }
268
+ }
269
+ const typeStr = file.type === "text" ? "" : ` [${file.type}]`;
270
+ const importanceStr = file.importance === "normal" ? "" : ` [${file.importance}]`;
271
+ const sem = analysis.semanticAnalysis?.fileSummaries[file.path];
272
+ const desc = sem?.summary || getSemanticFileDescription(file.path, file.name);
273
+ mdDir += ` ├── ${file.path}${typeStr}${importanceStr} (${(file.size / 1024).toFixed(1)} KB) - ${desc}\n`;
274
+ }
275
+ mdDir += `\`\`\`\n\n`;
276
+ yield mdDir;
277
+ yield `## Repository Files\n\n`;
278
+ for (const file of prioritizedFiles) {
279
+ const sem = analysis.semanticAnalysis?.fileSummaries[file.path];
280
+ const summaryVal = sem?.summary || getSemanticFileDescription(file.path, file.name);
281
+ let mdFile = `### File: ${file.path}\n`;
282
+ mdFile += `<file path="${file.path}" type="${file.type}" importance="${file.importance}" summary="${summaryVal}" is_entrypoint="${sem?.isEntrypoint ? 'true' : 'false'}">\n\n`;
283
+ if (file.type === "text") {
284
+ mdFile += "```" + file.extension + "\n";
285
+ mdFile += file.content + "\n";
286
+ mdFile += "```\n";
287
+ }
288
+ else if (file.type === "binary") {
289
+ mdFile += `*Binary file omitted (${(file.size / 1024).toFixed(1)} KB)*\n`;
290
+ }
291
+ else if (file.type === "oversized") {
292
+ mdFile += `*Oversized file omitted (>1MB) (${(file.size / 1024).toFixed(1)} KB)*\n`;
293
+ }
294
+ mdFile += `\n</file>\n\n`;
295
+ yield mdFile;
296
+ }
297
+ }
298
+ /**
299
+ * Standard in-memory context generation.
300
+ * NOTE: For extremely large repositories where memory overhead must be kept to zero,
301
+ * developers should consume the chunk-friendly generator function `generateRepositoryContextChunks`
302
+ * directly (e.g., piping yielded strings into a writable file stream or network response).
303
+ */
304
+ export function generateRepositoryContext(files, format = "markdown", mode = "standard", intent = "general") {
305
+ let result = "";
306
+ // Append-friendly iteration avoiding Array.from memory spikes
307
+ for (const chunk of generateRepositoryContextChunks(files, format, mode, intent)) {
308
+ result += chunk;
309
+ }
310
+ return result;
311
+ }
@@ -0,0 +1,13 @@
1
+ export { scanFiles } from "./scanner/scanFiles.js";
2
+ export { detectImportance } from "./scanner/importanceDetector.js";
3
+ export { shouldIgnore } from "./filters/shouldIgnore.js";
4
+ export { analyzeRepository } from "./analyzer/repositoryAnalyzer.js";
5
+ export * from "./analyzer/types.js";
6
+ export { analyzeSemanticRepository } from "./summarizer/index.js";
7
+ export * from "./summarizer/types.js";
8
+ export { sortFiles } from "./prioritizer/sortFiles.js";
9
+ export { scoreFile } from "./prioritizer/scoreFile.js";
10
+ export { estimateWords } from "./tokenizer/estimateWords.js";
11
+ export { estimateTokens } from "./tokenizer/estimateTokens.js";
12
+ export { generateRepositoryContext } from "./formatter/generateRepositoryContext.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export { scanFiles } from "./scanner/scanFiles.js";
2
+ export { detectImportance } from "./scanner/importanceDetector.js";
3
+ export { shouldIgnore } from "./filters/shouldIgnore.js";
4
+ export { analyzeRepository } from "./analyzer/repositoryAnalyzer.js";
5
+ export * from "./analyzer/types.js";
6
+ export { analyzeSemanticRepository } from "./summarizer/index.js";
7
+ export * from "./summarizer/types.js";
8
+ export { sortFiles } from "./prioritizer/sortFiles.js";
9
+ export { scoreFile } from "./prioritizer/scoreFile.js";
10
+ export { estimateWords } from "./tokenizer/estimateWords.js";
11
+ export { estimateTokens } from "./tokenizer/estimateTokens.js";
12
+ export { generateRepositoryContext } from "./formatter/generateRepositoryContext.js";
@@ -0,0 +1,3 @@
1
+ import { ScannedFile } from "@codemelt/shared";
2
+ export declare function scoreFile(file: ScannedFile): number;
3
+ //# sourceMappingURL=scoreFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoreFile.d.ts","sourceRoot":"","sources":["../../src/prioritizer/scoreFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,wBAAgB,SAAS,CACrB,IAAI,EAAE,WAAW,GAClB,MAAM,CAkCR"}