@aiready/context-analyzer 0.9.25 → 0.9.28

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/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  calculatePathEntropy,
13
13
  calculateDirectoryDistance,
14
14
  classifyFile,
15
+ adjustCohesionForClassification,
15
16
  adjustFragmentationForClassification,
16
17
  getClassificationRecommendations,
17
18
  } from './analyzer';
@@ -252,7 +253,7 @@ export async function analyzeContext(
252
253
 
253
254
  const cohesionScore =
254
255
  focus === 'cohesion' || focus === 'all'
255
- ? calculateCohesion(node.exports, file)
256
+ ? calculateCohesion(node.exports, file, { coUsageMatrix: graph.coUsageMatrix })
256
257
  : 1;
257
258
 
258
259
  const fragmentationScore = fragmentationMap.get(file) || 0;
@@ -289,6 +290,13 @@ export async function analyzeContext(
289
290
  // Classify the file to help distinguish real issues from false positives
290
291
  const fileClassification = classifyFile(node, cohesionScore, domains);
291
292
 
293
+ // Adjust cohesion based on classification (utility/service/handler files get boosted)
294
+ const adjustedCohesionScore = adjustCohesionForClassification(
295
+ cohesionScore,
296
+ fileClassification,
297
+ node
298
+ );
299
+
292
300
  // Adjust fragmentation based on classification
293
301
  const adjustedFragmentationScore = adjustFragmentationForClassification(
294
302
  fragmentationScore,
@@ -302,7 +310,7 @@ export async function analyzeContext(
302
310
  issues
303
311
  );
304
312
 
305
- // Re-analyze issues with adjusted fragmentation
313
+ // Re-analyze issues with adjusted cohesion and fragmentation
306
314
  const {
307
315
  severity: adjustedSeverity,
308
316
  issues: adjustedIssues,
@@ -312,7 +320,7 @@ export async function analyzeContext(
312
320
  file,
313
321
  importDepth,
314
322
  contextBudget,
315
- cohesionScore,
323
+ cohesionScore: adjustedCohesionScore, // Use adjusted cohesion
316
324
  fragmentationScore: adjustedFragmentationScore,
317
325
  maxDepth,
318
326
  maxContextBudget,
@@ -329,7 +337,7 @@ export async function analyzeContext(
329
337
  dependencyCount: dependencyList.length,
330
338
  dependencyList,
331
339
  circularDeps: circularDeps.filter((cycle) => cycle.includes(file)),
332
- cohesionScore,
340
+ cohesionScore: adjustedCohesionScore, // Report adjusted cohesion
333
341
  domains,
334
342
  exportCount: node.exports.length,
335
343
  contextBudget,
package/src/scoring.ts CHANGED
@@ -1,3 +1,9 @@
1
+ import {
2
+ calculateMonthlyCost,
3
+ calculateProductivityImpact,
4
+ DEFAULT_COST_CONFIG,
5
+ type CostConfig
6
+ } from '@aiready/core';
1
7
  import type { ToolScoringOutput } from '@aiready/core';
2
8
  import type { ContextSummary } from './types';
3
9
 
@@ -9,9 +15,14 @@ import type { ContextSummary } from './types';
9
15
  * - Import depth (dependency chain length)
10
16
  * - Fragmentation score (code organization)
11
17
  * - Critical/major issues
18
+ *
19
+ * Includes business value metrics:
20
+ * - Estimated monthly cost of context waste
21
+ * - Estimated developer hours to fix
12
22
  */
13
23
  export function calculateContextScore(
14
- summary: ContextSummary
24
+ summary: ContextSummary,
25
+ costConfig?: Partial<CostConfig>
15
26
  ): ToolScoringOutput {
16
27
  const {
17
28
  avgContextBudget,
@@ -144,6 +155,19 @@ export function calculateContextScore(
144
155
  });
145
156
  }
146
157
 
158
+ // Calculate business value metrics
159
+ const cfg = { ...DEFAULT_COST_CONFIG, ...costConfig };
160
+ // Total context budget across all files
161
+ const totalContextBudget = avgContextBudget * summary.totalFiles;
162
+ const estimatedMonthlyCost = calculateMonthlyCost(totalContextBudget, cfg);
163
+
164
+ // Convert issues to format for productivity calculation
165
+ const issues = [
166
+ ...Array(criticalIssues).fill({ severity: 'critical' as const }),
167
+ ...Array(majorIssues).fill({ severity: 'major' as const }),
168
+ ];
169
+ const productivityImpact = calculateProductivityImpact(issues);
170
+
147
171
  return {
148
172
  toolName: 'context-analyzer',
149
173
  score,
@@ -155,6 +179,9 @@ export function calculateContextScore(
155
179
  avgFragmentation: Math.round(avgFragmentation * 100) / 100,
156
180
  criticalIssues,
157
181
  majorIssues,
182
+ // Business value metrics
183
+ estimatedMonthlyCost,
184
+ estimatedDeveloperHours: productivityImpact.totalHours,
158
185
  },
159
186
  factors,
160
187
  recommendations,
package/src/types.ts CHANGED
@@ -50,6 +50,12 @@ export type FileClassification =
50
50
  | 'barrel-export' // Re-exports from other modules (index.ts files)
51
51
  | 'type-definition' // Primarily type/interface definitions
52
52
  | 'cohesive-module' // Single domain, high cohesion (acceptable large files)
53
+ | 'utility-module' // Utility/helper files with cohesive purpose despite multi-domain
54
+ | 'service-file' // Service files orchestrating multiple dependencies
55
+ | 'lambda-handler' // Lambda/API handlers with single business purpose
56
+ | 'email-template' // Email templates/layouts with structural cohesion
57
+ | 'parser-file' // Parser/transformer files with single transformation purpose
58
+ | 'nextjs-page' // Next.js App Router page with SEO/structured data exports
53
59
  | 'mixed-concerns' // Multiple domains, potential refactoring candidate
54
60
  | 'unknown'; // Unable to classify
55
61