carto-md 1.0.14 → 1.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carto-md",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "The context layer for AI-native development.",
5
5
  "bin": {
6
6
  "carto": "src/cli/index.js"
@@ -1,10 +1,10 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const MAX_FILES_TOTAL = 50;
5
- const ROUTE_BUDGET = 20;
4
+ const MAX_FILES_TOTAL = 80;
5
+ const BASE_ROUTE_BUDGET = 20;
6
6
  const MODEL_BUDGET = 10;
7
- const UTILITY_BUDGET = 20;
7
+ const BASE_UTILITY_BUDGET = 20;
8
8
 
9
9
  const PYTHON_IGNORE = new Set(['__pycache__', '.venv', 'venv', 'migrations', 'node_modules', '.git', '.carto']);
10
10
  const JS_IGNORE = new Set(['node_modules', '.git', 'dist', 'build', '.carto', '.next', '.turbo', 'coverage', 'out', '.cache', 'generated', '__generated__', 'storybook-static', 'public', 'static']);
@@ -92,17 +92,19 @@ function smartSelect(allFiles, htmlFiles, projectRoot) {
92
92
  }
93
93
  }
94
94
 
95
- // Sort routes by score (entry points first)
95
+ // Dynamic route budget expand if many route files, compensate from utility budget
96
+ const routeBudget = routeCandidates.length > BASE_ROUTE_BUDGET
97
+ ? Math.min(routeCandidates.length, 40)
98
+ : BASE_ROUTE_BUDGET;
99
+ const utilityBudget = Math.max(10, MAX_FILES_TOTAL - routeBudget - MODEL_BUDGET);
100
+
96
101
  routeCandidates.sort((a, b) => scoreRoute(b) - scoreRoute(a));
97
- const selectedRoutes = routeCandidates.slice(0, ROUTE_BUDGET);
102
+ const selectedRoutes = routeCandidates.slice(0, routeBudget);
98
103
 
99
- // Sort models by score (schema files first)
100
104
  modelCandidates.sort((a, b) => scoreModel(b) - scoreModel(a));
101
105
  const selectedModels = modelCandidates.slice(0, MODEL_BUDGET);
102
106
 
103
- // For utilities: scan all files for import statements, count how many times each is imported
104
107
  const importCounts = countImportReferences(allFiles, projectRoot);
105
- // Rank other files by how often they're imported
106
108
  otherFiles.sort((a, b) => {
107
109
  const relA = path.relative(projectRoot, a);
108
110
  const relB = path.relative(projectRoot, b);
@@ -113,7 +115,7 @@ function smartSelect(allFiles, htmlFiles, projectRoot) {
113
115
  const remainingBudget = MAX_FILES_TOTAL - alreadySelected.size;
114
116
  const selectedUtilities = otherFiles
115
117
  .filter(f => !alreadySelected.has(f))
116
- .slice(0, Math.min(UTILITY_BUDGET, remainingBudget));
118
+ .slice(0, Math.min(utilityBudget, remainingBudget));
117
119
 
118
120
  const allSelected = [...new Set([...selectedRoutes, ...selectedModels, ...selectedUtilities])];
119
121
 
@@ -199,9 +199,14 @@ function buildImportGraph(fileContents, projectRoot) {
199
199
  const graph = {};
200
200
 
201
201
  for (const { filePath, content } of fileContents) {
202
+ const relPath = path.relative(projectRoot, filePath);
203
+ const base = path.basename(filePath);
204
+
205
+ // Skip generated files — they produce massive noisy edges
206
+ if (base.includes('.generated.') || relPath.includes('__generated__')) continue;
207
+
202
208
  const deps = extractImports(content, filePath, projectRoot);
203
209
  if (deps.length > 0) {
204
- const relPath = path.relative(projectRoot, filePath);
205
210
  graph[relPath] = deps;
206
211
  }
207
212
  }
@@ -27,18 +27,13 @@ module.exports = {
27
27
 
28
28
  function extractPrismaModels(content) {
29
29
  const models = [];
30
- const modelPattern = /^model\s+(\w+)\s*\{([^}]+)\}/gm;
30
+ const blocks = extractModelBlocks(content);
31
31
 
32
- let match;
33
- while ((match = modelPattern.exec(content)) !== null) {
34
- const className = match[1];
35
- const body = match[2];
32
+ for (const { name, body } of blocks) {
36
33
  const fields = [];
37
-
38
34
  const lines = body.split('\n');
39
35
  for (const line of lines) {
40
36
  const trimmed = line.trim();
41
- // Skip empty lines, comments, and @@directives
42
37
  if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('@@')) continue;
43
38
 
44
39
  const fieldMatch = trimmed.match(/^(\w+)\s+(\w+[\[\]?]*)/);
@@ -46,8 +41,7 @@ function extractPrismaModels(content) {
46
41
  fields.push({ name: fieldMatch[1], type: fieldMatch[2] });
47
42
  }
48
43
  }
49
-
50
- models.push({ className, fields });
44
+ models.push({ className: name, fields });
51
45
  }
52
46
 
53
47
  return models;
@@ -55,21 +49,43 @@ function extractPrismaModels(content) {
55
49
 
56
50
  function extractPrismaDBTables(content) {
57
51
  const tables = [];
58
- const modelPattern = /^model\s+(\w+)\s*\{([^}]+)\}/gm;
52
+ const blocks = extractModelBlocks(content);
53
+
54
+ for (const { name, body } of blocks) {
55
+ const mapMatch = body.match(/@@map\s*\(\s*['"]([^'"]+)['"]\s*\)/);
56
+ const tableName = mapMatch ? mapMatch[1] : toSnakeCase(name);
57
+ tables.push({ tableName, modelName: name });
58
+ }
59
59
 
60
+ return tables;
61
+ }
62
+
63
+ /**
64
+ * Brace-counting approach to extract model blocks.
65
+ * Handles } inside /// comments and @zod annotations.
66
+ */
67
+ function extractModelBlocks(content) {
68
+ const blocks = [];
69
+ const modelStart = /^model\s+(\w+)\s*\{/gm;
60
70
  let match;
61
- while ((match = modelPattern.exec(content)) !== null) {
62
- const modelName = match[1];
63
- const body = match[2];
64
71
 
65
- // Check for @@map('table_name')
66
- const mapMatch = body.match(/@@map\s*\(\s*['"]([^'"]+)['"]\s*\)/);
67
- const tableName = mapMatch ? mapMatch[1] : toSnakeCase(modelName);
72
+ while ((match = modelStart.exec(content)) !== null) {
73
+ const name = match[1];
74
+ const startIdx = match.index + match[0].length;
75
+ let depth = 1;
76
+ let i = startIdx;
68
77
 
69
- tables.push({ tableName, modelName });
78
+ while (i < content.length && depth > 0) {
79
+ if (content[i] === '{') depth++;
80
+ else if (content[i] === '}') depth--;
81
+ if (depth > 0) i++;
82
+ }
83
+
84
+ const body = content.substring(startIdx, i);
85
+ blocks.push({ name, body });
70
86
  }
71
87
 
72
- return tables;
88
+ return blocks;
73
89
  }
74
90
 
75
91
  function toSnakeCase(str) {