@aiready/cli 0.14.22 → 0.14.24

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.
@@ -0,0 +1,298 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/index.ts
9
+ import {
10
+ ToolRegistry,
11
+ ToolName,
12
+ calculateOverallScore,
13
+ calculateTokenBudget,
14
+ GLOBAL_INFRA_OPTIONS,
15
+ COMMON_FINE_TUNING_OPTIONS,
16
+ initializeParsers
17
+ } from "@aiready/core";
18
+ var TOOL_PACKAGE_MAP = {
19
+ [ToolName.PatternDetect]: "@aiready/pattern-detect",
20
+ [ToolName.ContextAnalyzer]: "@aiready/context-analyzer",
21
+ [ToolName.NamingConsistency]: "@aiready/consistency",
22
+ [ToolName.AiSignalClarity]: "@aiready/ai-signal-clarity",
23
+ [ToolName.AgentGrounding]: "@aiready/agent-grounding",
24
+ [ToolName.TestabilityIndex]: "@aiready/testability",
25
+ [ToolName.DocDrift]: "@aiready/doc-drift",
26
+ [ToolName.DependencyHealth]: "@aiready/deps",
27
+ [ToolName.ChangeAmplification]: "@aiready/change-amplification",
28
+ // Aliases handled by registry
29
+ patterns: "@aiready/pattern-detect",
30
+ duplicates: "@aiready/pattern-detect",
31
+ context: "@aiready/context-analyzer",
32
+ fragmentation: "@aiready/context-analyzer",
33
+ consistency: "@aiready/consistency",
34
+ "ai-signal": "@aiready/ai-signal-clarity",
35
+ grounding: "@aiready/agent-grounding",
36
+ testability: "@aiready/testability",
37
+ "deps-health": "@aiready/deps",
38
+ "change-amp": "@aiready/change-amplification"
39
+ };
40
+ function sanitizeConfigRecursive(obj) {
41
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return obj;
42
+ const sanitized = {};
43
+ const infraToStrip = [
44
+ "rootDir",
45
+ "onProgress",
46
+ "progressCallback",
47
+ "streamResults",
48
+ "batchSize",
49
+ "useSmartDefaults"
50
+ ];
51
+ for (const [key, value] of Object.entries(obj)) {
52
+ if (infraToStrip.includes(key)) continue;
53
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
54
+ sanitized[key] = sanitizeConfigRecursive(value);
55
+ } else {
56
+ sanitized[key] = value;
57
+ }
58
+ }
59
+ return sanitized;
60
+ }
61
+ function sanitizeToolConfig(config) {
62
+ return sanitizeConfigRecursive(config);
63
+ }
64
+ async function analyzeUnified(options) {
65
+ await initializeParsers();
66
+ const startTime = Date.now();
67
+ const requestedTools = options.tools ?? [
68
+ "patterns",
69
+ "context",
70
+ "consistency"
71
+ ];
72
+ const result = {
73
+ summary: {
74
+ totalIssues: 0,
75
+ criticalIssues: 0,
76
+ // Added as per instruction
77
+ majorIssues: 0,
78
+ // Added as per instruction
79
+ totalFiles: 0,
80
+ toolsRun: [],
81
+ executionTime: 0,
82
+ config: options,
83
+ toolConfigs: {}
84
+ }
85
+ };
86
+ for (const toolName of requestedTools) {
87
+ let provider = ToolRegistry.find(toolName);
88
+ if (!provider) {
89
+ const packageName = TOOL_PACKAGE_MAP[toolName] ?? (toolName.startsWith("@aiready/") ? toolName : `@aiready/${toolName}`);
90
+ try {
91
+ await import(packageName);
92
+ provider = ToolRegistry.find(toolName);
93
+ if (provider) {
94
+ console.log(
95
+ `\u2705 Successfully loaded tool provider: ${toolName} from ${packageName}`
96
+ );
97
+ } else {
98
+ console.log(
99
+ `\u26A0\uFE0F Loaded ${packageName} but provider ${toolName} still not found in registry.`
100
+ );
101
+ }
102
+ } catch (err) {
103
+ console.log(
104
+ `\u274C Failed to dynamically load tool ${toolName} (${packageName}):`,
105
+ err.message
106
+ );
107
+ }
108
+ }
109
+ if (!provider) {
110
+ console.warn(
111
+ `\u26A0\uFE0F Warning: Tool provider for '${toolName}' not found. Skipping.`
112
+ );
113
+ continue;
114
+ }
115
+ try {
116
+ const sanitizedOptions = { ...options };
117
+ delete sanitizedOptions.onProgress;
118
+ delete sanitizedOptions.progressCallback;
119
+ const toolOptions = {
120
+ rootDir: options.rootDir
121
+ // Always include rootDir
122
+ };
123
+ [...GLOBAL_INFRA_OPTIONS, ...COMMON_FINE_TUNING_OPTIONS].forEach(
124
+ (key) => {
125
+ if (key in options && key !== "toolConfigs" && key !== "tools") {
126
+ toolOptions[key] = options[key];
127
+ }
128
+ }
129
+ );
130
+ if (options.toolConfigs?.[provider.id]) {
131
+ Object.assign(toolOptions, options.toolConfigs[provider.id]);
132
+ } else if (options.tools && !Array.isArray(options.tools) && typeof options.tools === "object" && options.tools[provider.id]) {
133
+ Object.assign(toolOptions, options.tools[provider.id]);
134
+ } else if (options[provider.id]) {
135
+ Object.assign(toolOptions, options[provider.id]);
136
+ }
137
+ toolOptions.onProgress = (processed, total, message) => {
138
+ if (options.progressCallback) {
139
+ options.progressCallback({
140
+ tool: provider.id,
141
+ processed,
142
+ total,
143
+ message
144
+ });
145
+ }
146
+ };
147
+ const output = await provider.analyze(toolOptions);
148
+ if (output.metadata) {
149
+ output.metadata.config = sanitizeToolConfig(toolOptions);
150
+ }
151
+ if (options.progressCallback) {
152
+ options.progressCallback({ tool: provider.id, data: output });
153
+ }
154
+ result[provider.id] = output;
155
+ result.summary.toolsRun.push(provider.id);
156
+ if (output.summary?.config) {
157
+ result.summary.toolConfigs[provider.id] = sanitizeToolConfig(
158
+ output.summary.config
159
+ );
160
+ } else if (output.metadata?.config) {
161
+ result.summary.toolConfigs[provider.id] = sanitizeToolConfig(
162
+ output.metadata.config
163
+ );
164
+ } else {
165
+ result.summary.toolConfigs[provider.id] = sanitizeToolConfig(toolOptions);
166
+ }
167
+ const toolFiles = output.summary?.totalFiles ?? output.summary?.filesAnalyzed ?? 0;
168
+ if (toolFiles > result.summary.totalFiles) {
169
+ result.summary.totalFiles = toolFiles;
170
+ }
171
+ const issueCount = output.results.reduce(
172
+ (sum, file) => sum + (file.issues?.length ?? 0),
173
+ 0
174
+ );
175
+ result.summary.totalIssues += issueCount;
176
+ } catch (err) {
177
+ console.error(`\u274C Error running tool '${provider.id}':`, err);
178
+ }
179
+ }
180
+ result.summary.config = sanitizeConfigRecursive({
181
+ scan: {
182
+ tools: requestedTools,
183
+ include: options.include,
184
+ exclude: options.exclude
185
+ },
186
+ // Use 'tools' for tool-specific configurations to match AIReadyConfig
187
+ tools: result.summary.toolConfigs
188
+ });
189
+ result.summary.executionTime = Date.now() - startTime;
190
+ const keyMappings = {
191
+ "pattern-detect": ["patternDetect", "patterns"],
192
+ "context-analyzer": ["contextAnalyzer", "context"],
193
+ "naming-consistency": ["namingConsistency", "consistency"],
194
+ "ai-signal-clarity": ["aiSignalClarity"],
195
+ "agent-grounding": ["agentGrounding"],
196
+ "testability-index": ["testabilityIndex", "testability"],
197
+ "doc-drift": ["docDrift"],
198
+ "dependency-health": ["dependencyHealth", "deps"],
199
+ "change-amplification": ["changeAmplification"]
200
+ };
201
+ for (const [kebabKey, aliases] of Object.entries(keyMappings)) {
202
+ if (result[kebabKey]) {
203
+ for (const alias of aliases) {
204
+ result[alias] = result[kebabKey];
205
+ }
206
+ }
207
+ }
208
+ return result;
209
+ }
210
+ async function scoreUnified(results, options) {
211
+ const toolScores = /* @__PURE__ */ new Map();
212
+ for (const toolId of results.summary.toolsRun) {
213
+ const provider = ToolRegistry.get(toolId);
214
+ if (!provider) continue;
215
+ const output = results[toolId];
216
+ if (!output) continue;
217
+ try {
218
+ const toolScore = provider.score(output, options);
219
+ if (!toolScore.tokenBudget) {
220
+ if (toolId === ToolName.PatternDetect && output.duplicates) {
221
+ const wastedTokens = output.duplicates.reduce(
222
+ (sum, d) => sum + (d.tokenCost ?? 0),
223
+ 0
224
+ );
225
+ toolScore.tokenBudget = calculateTokenBudget({
226
+ totalContextTokens: wastedTokens * 2,
227
+ wastedTokens: {
228
+ duplication: wastedTokens,
229
+ fragmentation: 0,
230
+ chattiness: 0
231
+ }
232
+ });
233
+ } else if (toolId === ToolName.ContextAnalyzer && output.summary) {
234
+ toolScore.tokenBudget = calculateTokenBudget({
235
+ totalContextTokens: output.summary.totalTokens,
236
+ wastedTokens: {
237
+ duplication: 0,
238
+ fragmentation: output.summary.totalPotentialSavings ?? 0,
239
+ chattiness: 0
240
+ }
241
+ });
242
+ }
243
+ }
244
+ toolScores.set(toolId, toolScore);
245
+ } catch (err) {
246
+ console.error(`\u274C Error scoring tool '${toolId}':`, err);
247
+ }
248
+ }
249
+ if (toolScores.size === 0) {
250
+ return {
251
+ overall: 0,
252
+ rating: "Critical",
253
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
254
+ toolsUsed: [],
255
+ breakdown: [],
256
+ calculation: {
257
+ formula: "0 / 0 = 0",
258
+ weights: {},
259
+ normalized: "0 / 0 = 0"
260
+ }
261
+ };
262
+ }
263
+ return calculateOverallScore(toolScores, options, void 0);
264
+ }
265
+ function generateUnifiedSummary(result) {
266
+ const { summary } = result;
267
+ let output = `\u{1F680} AIReady Analysis Complete
268
+
269
+ `;
270
+ output += `\u{1F4CA} Summary:
271
+ `;
272
+ output += ` Tools run: ${summary.toolsRun.join(", ")}
273
+ `;
274
+ output += ` Total issues found: ${summary.totalIssues}
275
+ `;
276
+ output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
277
+
278
+ `;
279
+ for (const provider of ToolRegistry.getAll()) {
280
+ const toolResult = result[provider.id];
281
+ if (toolResult) {
282
+ const issueCount = toolResult.results.reduce(
283
+ (sum, r) => sum + (r.issues?.length ?? 0),
284
+ 0
285
+ );
286
+ output += `\u2022 ${provider.id}: ${issueCount} issues
287
+ `;
288
+ }
289
+ }
290
+ return output;
291
+ }
292
+
293
+ export {
294
+ __require,
295
+ analyzeUnified,
296
+ scoreUnified,
297
+ generateUnifiedSummary
298
+ };