@aiready/cli 0.9.43 → 0.9.46

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,389 @@
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 { analyzePatterns } from "@aiready/pattern-detect";
10
+ import { analyzeContext } from "@aiready/context-analyzer";
11
+ import { analyzeConsistency } from "@aiready/consistency";
12
+ import { calculateOverallScore, calculateTokenBudget } from "@aiready/core";
13
+ var severityOrder = {
14
+ critical: 4,
15
+ major: 3,
16
+ minor: 2,
17
+ info: 1
18
+ };
19
+ function sortBySeverity(results) {
20
+ return results.map((file) => {
21
+ const sortedIssues = [...file.issues].sort((a, b) => {
22
+ const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
23
+ if (severityDiff !== 0) return severityDiff;
24
+ return (a.location?.line || 0) - (b.location?.line || 0);
25
+ });
26
+ return { ...file, issues: sortedIssues };
27
+ }).sort((a, b) => {
28
+ const aMaxSeverity = Math.max(
29
+ ...a.issues.map((i) => severityOrder[i.severity] || 0),
30
+ 0
31
+ );
32
+ const bMaxSeverity = Math.max(
33
+ ...b.issues.map((i) => severityOrder[i.severity] || 0),
34
+ 0
35
+ );
36
+ if (aMaxSeverity !== bMaxSeverity) {
37
+ return bMaxSeverity - aMaxSeverity;
38
+ }
39
+ if (a.issues.length !== b.issues.length) {
40
+ return b.issues.length - a.issues.length;
41
+ }
42
+ return a.fileName.localeCompare(b.fileName);
43
+ });
44
+ }
45
+ async function analyzeUnified(options) {
46
+ const startTime = Date.now();
47
+ const tools = options.tools || ["patterns", "context", "consistency"];
48
+ const result = {
49
+ summary: {
50
+ totalIssues: 0,
51
+ toolsRun: tools,
52
+ executionTime: 0
53
+ }
54
+ };
55
+ if (tools.includes("patterns")) {
56
+ const patternResult = await analyzePatterns(options);
57
+ if (options.progressCallback) {
58
+ options.progressCallback({ tool: "patterns", data: patternResult });
59
+ }
60
+ result.patterns = sortBySeverity(patternResult.results);
61
+ result.duplicates = patternResult.duplicates;
62
+ result.summary.totalIssues += patternResult.results.reduce(
63
+ (sum, file) => sum + file.issues.length,
64
+ 0
65
+ );
66
+ }
67
+ if (tools.includes("context")) {
68
+ const contextResults = await analyzeContext(options);
69
+ if (options.progressCallback) {
70
+ options.progressCallback({ tool: "context", data: contextResults });
71
+ }
72
+ result.context = contextResults.sort((a, b) => {
73
+ const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
74
+ if (severityDiff !== 0) return severityDiff;
75
+ if (a.tokenCost !== b.tokenCost) return b.tokenCost - a.tokenCost;
76
+ return b.fragmentationScore - a.fragmentationScore;
77
+ });
78
+ result.summary.totalIssues += result.context?.length || 0;
79
+ }
80
+ if (tools.includes("consistency")) {
81
+ const consistencyOptions = {
82
+ rootDir: options.rootDir,
83
+ include: options.include,
84
+ exclude: options.exclude,
85
+ ...options.consistency || {}
86
+ };
87
+ const report = await analyzeConsistency(consistencyOptions);
88
+ if (options.progressCallback) {
89
+ options.progressCallback({ tool: "consistency", data: report });
90
+ }
91
+ if (report.results) {
92
+ report.results = sortBySeverity(report.results);
93
+ }
94
+ result.consistency = report;
95
+ result.summary.totalIssues += report.summary.totalIssues;
96
+ }
97
+ if (tools.includes("doc-drift")) {
98
+ const { analyzeDocDrift } = await import("@aiready/doc-drift");
99
+ const report = await analyzeDocDrift({
100
+ rootDir: options.rootDir,
101
+ include: options.include,
102
+ exclude: options.exclude,
103
+ onProgress: options.onProgress
104
+ });
105
+ if (options.progressCallback) {
106
+ options.progressCallback({ tool: "doc-drift", data: report });
107
+ }
108
+ result.docDrift = report;
109
+ result.summary.totalIssues += report.issues?.length || 0;
110
+ }
111
+ if (tools.includes("deps-health")) {
112
+ const { analyzeDeps } = await import("@aiready/deps");
113
+ const report = await analyzeDeps({
114
+ rootDir: options.rootDir,
115
+ include: options.include,
116
+ exclude: options.exclude,
117
+ onProgress: options.onProgress
118
+ });
119
+ if (options.progressCallback) {
120
+ options.progressCallback({ tool: "deps-health", data: report });
121
+ }
122
+ result.deps = report;
123
+ result.summary.totalIssues += report.issues?.length || 0;
124
+ }
125
+ if (tools.includes("aiSignalClarity")) {
126
+ const { analyzeAiSignalClarity } = await import("@aiready/ai-signal-clarity");
127
+ const report = await analyzeAiSignalClarity({
128
+ rootDir: options.rootDir,
129
+ include: options.include,
130
+ exclude: options.exclude,
131
+ onProgress: options.onProgress
132
+ });
133
+ if (options.progressCallback) {
134
+ options.progressCallback({ tool: "aiSignalClarity", data: report });
135
+ }
136
+ result.aiSignalClarity = report;
137
+ result.summary.totalIssues += report.results?.reduce(
138
+ (sum, r) => sum + (r.issues?.length || 0),
139
+ 0
140
+ ) || 0;
141
+ }
142
+ if (tools.includes("grounding")) {
143
+ const { analyzeAgentGrounding } = await import("@aiready/agent-grounding");
144
+ const report = await analyzeAgentGrounding({
145
+ rootDir: options.rootDir,
146
+ include: options.include,
147
+ exclude: options.exclude,
148
+ onProgress: options.onProgress
149
+ });
150
+ if (options.progressCallback) {
151
+ options.progressCallback({ tool: "grounding", data: report });
152
+ }
153
+ result.grounding = report;
154
+ result.summary.totalIssues += report.issues?.length || 0;
155
+ }
156
+ if (tools.includes("testability")) {
157
+ const { analyzeTestability } = await import("@aiready/testability");
158
+ const report = await analyzeTestability({
159
+ rootDir: options.rootDir,
160
+ include: options.include,
161
+ exclude: options.exclude,
162
+ onProgress: options.onProgress
163
+ });
164
+ if (options.progressCallback) {
165
+ options.progressCallback({ tool: "testability", data: report });
166
+ }
167
+ result.testability = report;
168
+ result.summary.totalIssues += report.issues?.length || 0;
169
+ }
170
+ if (tools.includes("changeAmplification")) {
171
+ const { analyzeChangeAmplification } = await import("@aiready/change-amplification");
172
+ const report = await analyzeChangeAmplification({
173
+ rootDir: options.rootDir,
174
+ include: options.include,
175
+ exclude: options.exclude,
176
+ onProgress: options.onProgress
177
+ });
178
+ if (options.progressCallback) {
179
+ options.progressCallback({ tool: "changeAmplification", data: report });
180
+ }
181
+ result.changeAmplification = report;
182
+ result.summary.totalIssues += report.summary?.totalIssues || 0;
183
+ }
184
+ result.summary.executionTime = Date.now() - startTime;
185
+ return result;
186
+ }
187
+ async function scoreUnified(results, options) {
188
+ const toolScores = /* @__PURE__ */ new Map();
189
+ if (results.duplicates) {
190
+ const { calculatePatternScore } = await import("@aiready/pattern-detect");
191
+ try {
192
+ const patternScore = calculatePatternScore(
193
+ results.duplicates,
194
+ results.patterns?.length || 0
195
+ );
196
+ const wastedTokens = results.duplicates.reduce(
197
+ (sum, d) => sum + (d.tokenCost || 0),
198
+ 0
199
+ );
200
+ patternScore.tokenBudget = calculateTokenBudget({
201
+ totalContextTokens: wastedTokens * 2,
202
+ // Estimated context
203
+ wastedTokens: {
204
+ duplication: wastedTokens,
205
+ fragmentation: 0,
206
+ chattiness: 0
207
+ }
208
+ });
209
+ toolScores.set("pattern-detect", patternScore);
210
+ } catch (err) {
211
+ void err;
212
+ }
213
+ }
214
+ if (results.context) {
215
+ const { generateSummary: genContextSummary, calculateContextScore } = await import("@aiready/context-analyzer");
216
+ try {
217
+ const ctxSummary = genContextSummary(results.context);
218
+ const contextScore = calculateContextScore(ctxSummary);
219
+ contextScore.tokenBudget = calculateTokenBudget({
220
+ totalContextTokens: ctxSummary.totalTokens,
221
+ wastedTokens: {
222
+ duplication: 0,
223
+ fragmentation: ctxSummary.totalPotentialSavings || 0,
224
+ chattiness: 0
225
+ }
226
+ });
227
+ toolScores.set("context-analyzer", contextScore);
228
+ } catch (err) {
229
+ void err;
230
+ }
231
+ }
232
+ if (results.consistency) {
233
+ const { calculateConsistencyScore } = await import("@aiready/consistency");
234
+ try {
235
+ const issues = results.consistency.results?.flatMap((r) => r.issues) || [];
236
+ const totalFiles = results.consistency.summary?.filesAnalyzed || 0;
237
+ const consistencyScore = calculateConsistencyScore(issues, totalFiles);
238
+ toolScores.set("consistency", consistencyScore);
239
+ } catch (err) {
240
+ void err;
241
+ }
242
+ }
243
+ if (results.aiSignalClarity) {
244
+ const { calculateAiSignalClarityScore } = await import("@aiready/ai-signal-clarity");
245
+ try {
246
+ const hrScore = calculateAiSignalClarityScore(results.aiSignalClarity);
247
+ toolScores.set("ai-signal-clarity", hrScore);
248
+ } catch (err) {
249
+ void err;
250
+ }
251
+ }
252
+ if (results.grounding) {
253
+ const { calculateGroundingScore } = await import("@aiready/agent-grounding");
254
+ try {
255
+ const agScore = calculateGroundingScore(results.grounding);
256
+ toolScores.set("agent-grounding", agScore);
257
+ } catch (err) {
258
+ void err;
259
+ }
260
+ }
261
+ if (results.testability) {
262
+ const { calculateTestabilityScore } = await import("@aiready/testability");
263
+ try {
264
+ const tbScore = calculateTestabilityScore(results.testability);
265
+ toolScores.set("testability", tbScore);
266
+ } catch (err) {
267
+ void err;
268
+ }
269
+ }
270
+ if (results.docDrift) {
271
+ toolScores.set("doc-drift", {
272
+ toolName: "doc-drift",
273
+ score: results.docDrift.summary.score,
274
+ rawMetrics: results.docDrift.rawData,
275
+ factors: [],
276
+ recommendations: (results.docDrift.recommendations || []).map(
277
+ (action) => ({
278
+ action,
279
+ estimatedImpact: 5,
280
+ priority: "medium"
281
+ })
282
+ )
283
+ });
284
+ }
285
+ if (results.deps) {
286
+ toolScores.set("dependency-health", {
287
+ toolName: "dependency-health",
288
+ score: results.deps.summary.score,
289
+ rawMetrics: results.deps.rawData,
290
+ factors: [],
291
+ recommendations: (results.deps.recommendations || []).map(
292
+ (action) => ({
293
+ action,
294
+ estimatedImpact: 5,
295
+ priority: "medium"
296
+ })
297
+ )
298
+ });
299
+ }
300
+ if (results.changeAmplification) {
301
+ toolScores.set("change-amplification", {
302
+ toolName: "change-amplification",
303
+ score: results.changeAmplification.summary.score,
304
+ rawMetrics: results.changeAmplification.rawData,
305
+ factors: [],
306
+ recommendations: (results.changeAmplification.recommendations || []).map(
307
+ (action) => ({
308
+ action,
309
+ estimatedImpact: 5,
310
+ priority: "medium"
311
+ })
312
+ )
313
+ });
314
+ }
315
+ if (toolScores.size === 0) {
316
+ return {
317
+ overall: 0,
318
+ rating: "Critical",
319
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
320
+ toolsUsed: [],
321
+ breakdown: [],
322
+ calculation: {
323
+ formula: "0 / 0 = 0",
324
+ weights: {},
325
+ normalized: "0 / 0 = 0"
326
+ }
327
+ };
328
+ }
329
+ return calculateOverallScore(toolScores, options, void 0);
330
+ }
331
+ function generateUnifiedSummary(result) {
332
+ const { summary } = result;
333
+ let output = `\u{1F680} AIReady Analysis Complete
334
+
335
+ `;
336
+ output += `\u{1F4CA} Summary:
337
+ `;
338
+ output += ` Tools run: ${summary.toolsRun.join(", ")}
339
+ `;
340
+ output += ` Total issues found: ${summary.totalIssues}
341
+ `;
342
+ output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
343
+
344
+ `;
345
+ if (result.patterns) {
346
+ output += `\u{1F50D} Pattern Analysis: ${result.patterns.length} issues
347
+ `;
348
+ }
349
+ if (result.context) {
350
+ output += `\u{1F9E0} Context Analysis: ${result.context.length} issues
351
+ `;
352
+ }
353
+ if (result.consistency) {
354
+ output += `\u{1F3F7}\uFE0F Consistency Analysis: ${result.consistency.summary.totalIssues} issues
355
+ `;
356
+ }
357
+ if (result.docDrift) {
358
+ output += `\u{1F4DD} Doc Drift Analysis: ${result.docDrift.issues?.length || 0} issues
359
+ `;
360
+ }
361
+ if (result.deps) {
362
+ output += `\u{1F4E6} Dependency Health: ${result.deps.issues?.length || 0} issues
363
+ `;
364
+ }
365
+ if (result.aiSignalClarity) {
366
+ output += `\u{1F9E0} AI Signal Clarity: ${result.aiSignalClarity.summary?.totalSignals || 0} signals
367
+ `;
368
+ }
369
+ if (result.grounding) {
370
+ output += `\u{1F9ED} Agent Grounding: ${result.grounding.issues?.length || 0} issues
371
+ `;
372
+ }
373
+ if (result.testability) {
374
+ output += `\u{1F9EA} Testability Index: ${result.testability.issues?.length || 0} issues
375
+ `;
376
+ }
377
+ if (result.changeAmplification) {
378
+ output += `\u{1F4A5} Change Amplification: ${result.changeAmplification.summary?.totalIssues || 0} cascading risks
379
+ `;
380
+ }
381
+ return output;
382
+ }
383
+
384
+ export {
385
+ __require,
386
+ analyzeUnified,
387
+ scoreUnified,
388
+ generateUnifiedSummary
389
+ };