@aiready/cli 0.14.25 → 0.14.26

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