@aiready/cli 0.14.25 → 0.15.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.
package/dist/index.js CHANGED
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ ScoringOrchestrator: () => ScoringOrchestrator,
24
+ TOOL_PACKAGE_MAP: () => TOOL_PACKAGE_MAP,
25
+ UnifiedOrchestrator: () => UnifiedOrchestrator,
23
26
  analyzeUnified: () => analyzeUnified,
24
27
  generateUnifiedSummary: () => generateUnifiedSummary,
25
28
  scoreUnified: () => scoreUnified
26
29
  });
27
30
  module.exports = __toCommonJS(index_exports);
31
+
32
+ // src/orchestrator.ts
28
33
  var import_core = require("@aiready/core");
29
34
  var TOOL_PACKAGE_MAP = {
30
35
  [import_core.ToolName.PatternDetect]: "@aiready/pattern-detect",
@@ -36,6 +41,7 @@ var TOOL_PACKAGE_MAP = {
36
41
  [import_core.ToolName.DocDrift]: "@aiready/doc-drift",
37
42
  [import_core.ToolName.DependencyHealth]: "@aiready/deps",
38
43
  [import_core.ToolName.ChangeAmplification]: "@aiready/change-amplification",
44
+ [import_core.ToolName.ContractEnforcement]: "@aiready/contract-enforcement",
39
45
  // Aliases handled by registry
40
46
  patterns: "@aiready/pattern-detect",
41
47
  duplicates: "@aiready/pattern-detect",
@@ -46,218 +52,261 @@ var TOOL_PACKAGE_MAP = {
46
52
  grounding: "@aiready/agent-grounding",
47
53
  testability: "@aiready/testability",
48
54
  "deps-health": "@aiready/deps",
49
- "change-amp": "@aiready/change-amplification"
55
+ "change-amp": "@aiready/change-amplification",
56
+ contract: "@aiready/contract-enforcement"
50
57
  };
51
- function sanitizeConfigRecursive(obj) {
52
- if (!obj || typeof obj !== "object" || Array.isArray(obj)) return obj;
53
- const sanitized = {};
54
- const infraToStrip = [
55
- "rootDir",
56
- "onProgress",
57
- "progressCallback",
58
- "streamResults",
59
- "batchSize",
60
- "useSmartDefaults"
61
- ];
62
- for (const [key, value] of Object.entries(obj)) {
63
- if (infraToStrip.includes(key)) continue;
64
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
65
- sanitized[key] = sanitizeConfigRecursive(value);
66
- } else {
67
- sanitized[key] = value;
68
- }
58
+ var UnifiedOrchestrator = class {
59
+ /**
60
+ * Initialize orchestrator with a tool registry.
61
+ * Injection pattern helps with testability and AI readiness score.
62
+ */
63
+ constructor(registry = import_core.ToolRegistry) {
64
+ this.registry = registry;
69
65
  }
70
- return sanitized;
71
- }
72
- function sanitizeToolConfig(config) {
73
- return sanitizeConfigRecursive(config);
74
- }
75
- async function analyzeUnified(options) {
76
- await (0, import_core.initializeParsers)();
77
- const startTime = Date.now();
78
- const requestedTools = options.tools ?? [
79
- "patterns",
80
- "context",
81
- "consistency"
82
- ];
83
- const result = {
84
- summary: {
85
- totalIssues: 0,
86
- criticalIssues: 0,
87
- // Added as per instruction
88
- majorIssues: 0,
89
- // Added as per instruction
90
- totalFiles: 0,
91
- toolsRun: [],
92
- executionTime: 0,
93
- config: options,
94
- toolConfigs: {}
66
+ /**
67
+ * Deeply sanitizes a configuration object.
68
+ */
69
+ sanitizeConfig(obj) {
70
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return obj;
71
+ const sanitized = {};
72
+ const infraToStrip = [
73
+ "rootDir",
74
+ "onProgress",
75
+ "progressCallback",
76
+ "streamResults",
77
+ "batchSize",
78
+ "useSmartDefaults"
79
+ ];
80
+ for (const [key, value] of Object.entries(obj)) {
81
+ if (infraToStrip.includes(key)) continue;
82
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
83
+ sanitized[key] = this.sanitizeConfig(value);
84
+ } else {
85
+ sanitized[key] = value;
86
+ }
95
87
  }
96
- };
97
- for (const toolName of requestedTools) {
98
- let provider = import_core.ToolRegistry.find(toolName);
99
- if (!provider) {
100
- const packageName = TOOL_PACKAGE_MAP[toolName] ?? (toolName.startsWith("@aiready/") ? toolName : `@aiready/${toolName}`);
101
- try {
102
- await import(packageName);
103
- provider = import_core.ToolRegistry.find(toolName);
104
- if (provider) {
105
- console.log(
106
- `\u2705 Successfully loaded tool provider: ${toolName} from ${packageName}`
107
- );
108
- } else {
88
+ return sanitized;
89
+ }
90
+ /**
91
+ * Performs the unified analysis.
92
+ */
93
+ async analyze(options) {
94
+ await (0, import_core.initializeParsers)();
95
+ const startTime = Date.now();
96
+ const requestedTools = options.tools ?? [
97
+ "patterns",
98
+ "context",
99
+ "consistency"
100
+ ];
101
+ const result = {
102
+ summary: {
103
+ totalIssues: 0,
104
+ criticalIssues: 0,
105
+ majorIssues: 0,
106
+ totalFiles: 0,
107
+ toolsRun: [],
108
+ executionTime: 0,
109
+ config: options,
110
+ toolConfigs: {}
111
+ }
112
+ };
113
+ for (const toolName of requestedTools) {
114
+ let provider = this.registry.find(toolName);
115
+ if (!provider) {
116
+ const packageName = TOOL_PACKAGE_MAP[toolName] ?? (toolName.startsWith("@aiready/") ? toolName : `@aiready/${toolName}`);
117
+ try {
118
+ await import(packageName);
119
+ provider = this.registry.find(toolName);
120
+ } catch (err) {
109
121
  console.log(
110
- `\u26A0\uFE0F Loaded ${packageName} but provider ${toolName} still not found in registry.`
122
+ `\u274C Failed to dynamically load tool ${toolName} (${packageName}):`,
123
+ err.message
111
124
  );
112
125
  }
113
- } catch (err) {
114
- console.log(
115
- `\u274C Failed to dynamically load tool ${toolName} (${packageName}):`,
116
- err.message
126
+ }
127
+ if (!provider) {
128
+ console.warn(
129
+ `\u26A0\uFE0F Warning: Tool provider for '${toolName}' not found. Skipping.`
117
130
  );
131
+ continue;
118
132
  }
119
- }
120
- if (!provider) {
121
- console.warn(
122
- `\u26A0\uFE0F Warning: Tool provider for '${toolName}' not found. Skipping.`
123
- );
124
- continue;
125
- }
126
- try {
127
- const sanitizedOptions = { ...options };
128
- delete sanitizedOptions.onProgress;
129
- delete sanitizedOptions.progressCallback;
130
- const toolOptions = {
131
- rootDir: options.rootDir
132
- // Always include rootDir
133
- };
134
- [...import_core.GLOBAL_INFRA_OPTIONS, ...import_core.COMMON_FINE_TUNING_OPTIONS].forEach(
135
- (key) => {
136
- if (key in options && key !== "toolConfigs" && key !== "tools") {
137
- toolOptions[key] = options[key];
133
+ try {
134
+ const toolOptions = {
135
+ rootDir: options.rootDir
136
+ };
137
+ [...import_core.GLOBAL_INFRA_OPTIONS, ...import_core.COMMON_FINE_TUNING_OPTIONS].forEach(
138
+ (key) => {
139
+ if (key in options && key !== "toolConfigs" && key !== "tools") {
140
+ toolOptions[key] = options[key];
141
+ }
138
142
  }
143
+ );
144
+ if (options.toolConfigs?.[provider.id]) {
145
+ Object.assign(toolOptions, options.toolConfigs[provider.id]);
146
+ } else if (options.tools && !Array.isArray(options.tools) && typeof options.tools === "object" && options.tools[provider.id]) {
147
+ Object.assign(toolOptions, options.tools[provider.id]);
148
+ }
149
+ toolOptions.onProgress = (processed, total, msg) => {
150
+ if (options.progressCallback) {
151
+ options.progressCallback({
152
+ tool: provider.id,
153
+ processed,
154
+ total,
155
+ message: msg
156
+ });
157
+ }
158
+ };
159
+ const output = await provider.analyze(toolOptions);
160
+ if (output.metadata) {
161
+ output.metadata.config = this.sanitizeConfig(toolOptions);
139
162
  }
140
- );
141
- if (options.toolConfigs?.[provider.id]) {
142
- Object.assign(toolOptions, options.toolConfigs[provider.id]);
143
- } else if (options.tools && !Array.isArray(options.tools) && typeof options.tools === "object" && options.tools[provider.id]) {
144
- Object.assign(toolOptions, options.tools[provider.id]);
145
- } else if (options[provider.id]) {
146
- Object.assign(toolOptions, options[provider.id]);
147
- }
148
- toolOptions.onProgress = (processed, total, message) => {
149
163
  if (options.progressCallback) {
150
- options.progressCallback({
151
- tool: provider.id,
152
- processed,
153
- total,
154
- message
155
- });
164
+ options.progressCallback({ tool: provider.id, data: output });
156
165
  }
157
- };
158
- const output = await provider.analyze(toolOptions);
159
- if (output.metadata) {
160
- output.metadata.config = sanitizeToolConfig(toolOptions);
161
- }
162
- if (options.progressCallback) {
163
- options.progressCallback({ tool: provider.id, data: output });
164
- }
165
- result[provider.id] = output;
166
- result.summary.toolsRun.push(provider.id);
167
- if (output.summary?.config) {
168
- result.summary.toolConfigs[provider.id] = sanitizeToolConfig(
169
- output.summary.config
170
- );
171
- } else if (output.metadata?.config) {
172
- result.summary.toolConfigs[provider.id] = sanitizeToolConfig(
173
- output.metadata.config
166
+ result[provider.id] = output;
167
+ result.summary.toolsRun.push(provider.id);
168
+ const toolConfig = output.summary?.config ?? output.metadata?.config ?? toolOptions;
169
+ result.summary.toolConfigs[provider.id] = this.sanitizeConfig(toolConfig);
170
+ const toolFiles = output.summary?.totalFiles ?? output.summary?.filesAnalyzed ?? 0;
171
+ if (toolFiles > result.summary.totalFiles) {
172
+ result.summary.totalFiles = toolFiles;
173
+ }
174
+ const issueCount = output.results.reduce(
175
+ (sum, file) => sum + (file.issues?.length ?? 0),
176
+ 0
174
177
  );
175
- } else {
176
- result.summary.toolConfigs[provider.id] = sanitizeToolConfig(toolOptions);
177
- }
178
- const toolFiles = output.summary?.totalFiles ?? output.summary?.filesAnalyzed ?? 0;
179
- if (toolFiles > result.summary.totalFiles) {
180
- result.summary.totalFiles = toolFiles;
178
+ result.summary.totalIssues += issueCount;
179
+ } catch (err) {
180
+ console.error(`\u274C Error running tool '${provider.id}':`, err);
181
181
  }
182
- const issueCount = output.results.reduce(
183
- (sum, file) => sum + (file.issues?.length ?? 0),
184
- 0
185
- );
186
- result.summary.totalIssues += issueCount;
187
- } catch (err) {
188
- console.error(`\u274C Error running tool '${provider.id}':`, err);
189
182
  }
183
+ result.summary.config = this.sanitizeConfig({
184
+ scan: {
185
+ tools: requestedTools,
186
+ include: options.include,
187
+ exclude: options.exclude
188
+ },
189
+ tools: result.summary.toolConfigs
190
+ });
191
+ result.summary.executionTime = Date.now() - startTime;
192
+ this.applyLegacyKeys(result);
193
+ return result;
190
194
  }
191
- result.summary.config = sanitizeConfigRecursive({
192
- scan: {
193
- tools: requestedTools,
194
- include: options.include,
195
- exclude: options.exclude
196
- },
197
- // Use 'tools' for tool-specific configurations to match AIReadyConfig
198
- tools: result.summary.toolConfigs
199
- });
200
- result.summary.executionTime = Date.now() - startTime;
201
- const keyMappings = {
202
- "pattern-detect": ["patternDetect", "patterns"],
203
- "context-analyzer": ["contextAnalyzer", "context"],
204
- "naming-consistency": ["namingConsistency", "consistency"],
205
- "ai-signal-clarity": ["aiSignalClarity"],
206
- "agent-grounding": ["agentGrounding"],
207
- "testability-index": ["testabilityIndex", "testability"],
208
- "doc-drift": ["docDrift"],
209
- "dependency-health": ["dependencyHealth", "deps"],
210
- "change-amplification": ["changeAmplification"]
211
- };
212
- for (const [kebabKey, aliases] of Object.entries(keyMappings)) {
213
- if (result[kebabKey]) {
214
- for (const alias of aliases) {
215
- result[alias] = result[kebabKey];
195
+ applyLegacyKeys(result) {
196
+ const keyMappings = {
197
+ "pattern-detect": ["patternDetect", "patterns"],
198
+ "context-analyzer": ["contextAnalyzer", "context"],
199
+ "naming-consistency": ["namingConsistency", "consistency"],
200
+ "ai-signal-clarity": ["aiSignalClarity"],
201
+ "agent-grounding": ["agentGrounding"],
202
+ "testability-index": ["testabilityIndex", "testability"],
203
+ "doc-drift": ["docDrift"],
204
+ "dependency-health": ["dependencyHealth", "deps"],
205
+ "change-amplification": ["changeAmplification"],
206
+ "contract-enforcement": ["contractEnforcement", "contract"]
207
+ };
208
+ for (const [kebabKey, aliases] of Object.entries(keyMappings)) {
209
+ if (result[kebabKey]) {
210
+ for (const alias of aliases) {
211
+ result[alias] = result[kebabKey];
212
+ }
216
213
  }
217
214
  }
218
215
  }
219
- return result;
216
+ };
217
+ async function analyzeUnified(options) {
218
+ const orchestrator = new UnifiedOrchestrator(import_core.ToolRegistry);
219
+ return orchestrator.analyze(options);
220
220
  }
221
- async function scoreUnified(results, options) {
222
- const toolScores = /* @__PURE__ */ new Map();
223
- for (const toolId of results.summary.toolsRun) {
224
- const provider = import_core.ToolRegistry.get(toolId);
225
- if (!provider) continue;
226
- const output = results[toolId];
227
- if (!output) continue;
228
- try {
229
- const toolScore = provider.score(output, options);
230
- if (!toolScore.tokenBudget) {
231
- if (toolId === import_core.ToolName.PatternDetect && output.duplicates) {
232
- const wastedTokens = output.duplicates.reduce(
233
- (sum, d) => sum + (d.tokenCost ?? 0),
234
- 0
235
- );
236
- toolScore.tokenBudget = (0, import_core.calculateTokenBudget)({
237
- totalContextTokens: wastedTokens * 2,
238
- wastedTokens: {
239
- duplication: wastedTokens,
240
- fragmentation: 0,
241
- chattiness: 0
242
- }
243
- });
244
- } else if (toolId === import_core.ToolName.ContextAnalyzer && output.summary) {
245
- toolScore.tokenBudget = (0, import_core.calculateTokenBudget)({
246
- totalContextTokens: output.summary.totalTokens,
247
- wastedTokens: {
248
- duplication: 0,
249
- fragmentation: output.summary.totalPotentialSavings ?? 0,
250
- chattiness: 0
251
- }
252
- });
221
+
222
+ // src/scoring-orchestrator.ts
223
+ var import_core2 = require("@aiready/core");
224
+ var ScoringOrchestrator = class {
225
+ /**
226
+ * Initialize scoring orchestrator with a tool registry.
227
+ * Injection pattern helps with testability and AI readiness score.
228
+ */
229
+ constructor(registry = import_core2.ToolRegistry) {
230
+ this.registry = registry;
231
+ }
232
+ /**
233
+ * Calculates scores for all analyzed tools.
234
+ */
235
+ async score(results, options) {
236
+ const toolScores = /* @__PURE__ */ new Map();
237
+ for (const toolId of results.summary.toolsRun) {
238
+ const provider = this.registry.get(toolId);
239
+ if (!provider) continue;
240
+ const output = results[toolId];
241
+ if (!output) continue;
242
+ try {
243
+ const toolScore = provider.score(output, options);
244
+ if (!toolScore.tokenBudget) {
245
+ if (toolId === import_core2.ToolName.PatternDetect && output.duplicates) {
246
+ const wastedTokens = output.duplicates.reduce(
247
+ (sum, d) => sum + (d.tokenCost ?? 0),
248
+ 0
249
+ );
250
+ toolScore.tokenBudget = (0, import_core2.calculateTokenBudget)({
251
+ totalContextTokens: wastedTokens * 2,
252
+ wastedTokens: {
253
+ duplication: wastedTokens,
254
+ fragmentation: 0,
255
+ chattiness: 0
256
+ }
257
+ });
258
+ } else if (toolId === import_core2.ToolName.ContextAnalyzer && output.summary) {
259
+ toolScore.tokenBudget = (0, import_core2.calculateTokenBudget)({
260
+ totalContextTokens: output.summary.totalTokens,
261
+ wastedTokens: {
262
+ duplication: 0,
263
+ fragmentation: output.summary.totalPotentialSavings ?? 0,
264
+ chattiness: 0
265
+ }
266
+ });
267
+ }
253
268
  }
269
+ toolScores.set(toolId, toolScore);
270
+ } catch (err) {
271
+ console.error(`\u274C Error scoring tool '${toolId}':`, err);
272
+ }
273
+ }
274
+ if (toolScores.size === 0) {
275
+ return this.emptyScoringResult();
276
+ }
277
+ return (0, import_core2.calculateOverallScore)(toolScores, options, void 0);
278
+ }
279
+ /**
280
+ * Generate human-readable summary of unified results.
281
+ */
282
+ generateSummary(result) {
283
+ const { summary } = result;
284
+ let output = `\u{1F680} AIReady Analysis Complete
285
+
286
+ `;
287
+ output += `\u{1F4CA} Summary:
288
+ `;
289
+ output += ` Tools run: ${summary.toolsRun.join(", ")}
290
+ `;
291
+ output += ` Total issues found: ${summary.totalIssues}
292
+ `;
293
+ output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
294
+
295
+ `;
296
+ for (const provider of this.registry.getAll()) {
297
+ const toolResult = result[provider.id];
298
+ if (toolResult) {
299
+ const issueCount = toolResult.results.reduce(
300
+ (sum, r) => sum + (r.issues?.length ?? 0),
301
+ 0
302
+ );
303
+ output += `\u2022 ${provider.id}: ${issueCount} issues
304
+ `;
254
305
  }
255
- toolScores.set(toolId, toolScore);
256
- } catch (err) {
257
- console.error(`\u274C Error scoring tool '${toolId}':`, err);
258
306
  }
307
+ return output;
259
308
  }
260
- if (toolScores.size === 0) {
309
+ emptyScoringResult() {
261
310
  return {
262
311
  overall: 0,
263
312
  rating: "Critical",
@@ -271,37 +320,20 @@ async function scoreUnified(results, options) {
271
320
  }
272
321
  };
273
322
  }
274
- return (0, import_core.calculateOverallScore)(toolScores, options, void 0);
323
+ };
324
+ async function scoreUnified(results, options) {
325
+ const orchestrator = new ScoringOrchestrator(import_core2.ToolRegistry);
326
+ return orchestrator.score(results, options);
275
327
  }
276
328
  function generateUnifiedSummary(result) {
277
- const { summary } = result;
278
- let output = `\u{1F680} AIReady Analysis Complete
279
-
280
- `;
281
- output += `\u{1F4CA} Summary:
282
- `;
283
- output += ` Tools run: ${summary.toolsRun.join(", ")}
284
- `;
285
- output += ` Total issues found: ${summary.totalIssues}
286
- `;
287
- output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
288
-
289
- `;
290
- for (const provider of import_core.ToolRegistry.getAll()) {
291
- const toolResult = result[provider.id];
292
- if (toolResult) {
293
- const issueCount = toolResult.results.reduce(
294
- (sum, r) => sum + (r.issues?.length ?? 0),
295
- 0
296
- );
297
- output += `\u2022 ${provider.id}: ${issueCount} issues
298
- `;
299
- }
300
- }
301
- return output;
329
+ const orchestrator = new ScoringOrchestrator(import_core2.ToolRegistry);
330
+ return orchestrator.generateSummary(result);
302
331
  }
303
332
  // Annotate the CommonJS export names for ESM import in node:
304
333
  0 && (module.exports = {
334
+ ScoringOrchestrator,
335
+ TOOL_PACKAGE_MAP,
336
+ UnifiedOrchestrator,
305
337
  analyzeUnified,
306
338
  generateUnifiedSummary,
307
339
  scoreUnified
package/dist/index.mjs CHANGED
@@ -1,9 +1,15 @@
1
1
  import {
2
+ ScoringOrchestrator,
3
+ TOOL_PACKAGE_MAP,
4
+ UnifiedOrchestrator,
2
5
  analyzeUnified,
3
6
  generateUnifiedSummary,
4
7
  scoreUnified
5
- } from "./chunk-HUSUJEQJ.mjs";
8
+ } from "./chunk-HX6H3VOE.mjs";
6
9
  export {
10
+ ScoringOrchestrator,
11
+ TOOL_PACKAGE_MAP,
12
+ UnifiedOrchestrator,
7
13
  analyzeUnified,
8
14
  generateUnifiedSummary,
9
15
  scoreUnified
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/cli",
3
- "version": "0.14.25",
3
+ "version": "0.15.0",
4
4
  "description": "Assess and improve your codebase's AI-readiness. Get an AI Readiness Score (0-100) and detect semantic duplicates, context fragmentation, and naming inconsistencies.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -24,17 +24,18 @@
24
24
  "dependencies": {
25
25
  "chalk": "^5.3.0",
26
26
  "commander": "^14.0.0",
27
- "@aiready/agent-grounding": "0.13.22",
28
- "@aiready/consistency": "0.20.22",
29
- "@aiready/core": "0.23.23",
30
- "@aiready/context-analyzer": "0.21.26",
31
- "@aiready/deps": "0.13.23",
32
- "@aiready/doc-drift": "0.13.22",
33
- "@aiready/change-amplification": "0.13.22",
34
- "@aiready/pattern-detect": "0.16.22",
35
- "@aiready/ai-signal-clarity": "0.13.23",
36
- "@aiready/testability": "0.6.22",
37
- "@aiready/visualizer": "0.6.22"
27
+ "@aiready/agent-grounding": "0.14.0",
28
+ "@aiready/consistency": "0.21.0",
29
+ "@aiready/deps": "0.14.0",
30
+ "@aiready/context-analyzer": "0.22.0",
31
+ "@aiready/core": "0.24.0",
32
+ "@aiready/doc-drift": "0.14.0",
33
+ "@aiready/change-amplification": "0.14.0",
34
+ "@aiready/contract-enforcement": "0.2.0",
35
+ "@aiready/ai-signal-clarity": "0.14.0",
36
+ "@aiready/pattern-detect": "0.17.0",
37
+ "@aiready/testability": "0.7.0",
38
+ "@aiready/visualizer": "0.7.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/node": "^24.0.0",