@aiready/cli 0.9.40 → 0.9.43
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/.aiready/aiready-report-20260227-133806.json +40 -141
- package/.aiready/aiready-report-20260227-133938.json +40 -141
- package/.aiready/aiready-report-20260228-003433.json +7939 -0
- package/.aiready/aiready-report-20260228-003613.json +771 -0
- package/.github/FUNDING.yml +2 -2
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-lint.log +5 -0
- package/.turbo/turbo-test.log +5 -5
- package/CONTRIBUTING.md +11 -2
- package/dist/chunk-HLBKROD3.mjs +237 -0
- package/dist/chunk-LLJMKNBI.mjs +243 -0
- package/dist/cli.js +708 -184
- package/dist/cli.mjs +687 -178
- package/dist/index.js +24 -9
- package/dist/index.mjs +1 -1
- package/package.json +12 -12
- package/src/__tests__/cli.test.ts +1 -1
- package/src/cli.ts +114 -28
- package/src/commands/agent-grounding.ts +22 -7
- package/src/commands/ai-signal-clarity.ts +14 -9
- package/src/commands/consistency.ts +70 -30
- package/src/commands/context.ts +109 -39
- package/src/commands/deps-health.ts +15 -6
- package/src/commands/doc-drift.ts +10 -4
- package/src/commands/index.ts +6 -2
- package/src/commands/patterns.ts +67 -26
- package/src/commands/scan.ts +411 -126
- package/src/commands/testability.ts +22 -9
- package/src/commands/visualize.ts +102 -45
- package/src/index.ts +40 -10
- package/src/utils/helpers.ts +57 -32
package/.github/FUNDING.yml
CHANGED
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/cli@0.9.
|
|
3
|
+
> @aiready/cli@0.9.43 build /Users/pengcao/projects/aiready/packages/cli
|
|
4
4
|
> tsup src/index.ts src/cli.ts --format cjs,esm
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
|
|
13
|
-
[90m[[
|
|
13
|
+
[90m[[90m12:55:45 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1m"import.meta" is not available with the "cjs" output format and will be empty[0m [empty-import-meta]
|
|
14
14
|
|
|
15
15
|
src/cli.ts:23:31:
|
|
16
16
|
[37m 23 │ return dirname(fileURLToPath([32mimport.meta[37m.url));
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
[
|
|
23
|
+
[32mCJS[39m [1mdist/index.js [22m[32m9.42 KB[39m
|
|
24
|
+
[32mCJS[39m [1mdist/cli.js [22m[32m80.79 KB[39m
|
|
25
|
+
[32mCJS[39m ⚡️ Build success in 100ms
|
|
26
|
+
[32mESM[39m [1mdist/cli.mjs [22m[32m70.25 KB[39m
|
|
27
|
+
[32mESM[39m [1mdist/chunk-LLJMKNBI.mjs [22m[32m8.07 KB[39m
|
|
24
28
|
[32mESM[39m [1mdist/index.mjs [22m[32m138.00 B[39m
|
|
25
|
-
[32mESM[39m
|
|
26
|
-
[32mESM[39m ⚡️ Build success in 491ms
|
|
27
|
-
[32mCJS[39m [1mdist/index.js [22m[32m9.15 KB[39m
|
|
28
|
-
[32mCJS[39m [1mdist/cli.js [22m[32m75.53 KB[39m
|
|
29
|
-
[32mCJS[39m ⚡️ Build success in 492ms
|
|
29
|
+
[32mESM[39m ⚡️ Build success in 104ms
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/cli@0.9.
|
|
3
|
+
> @aiready/cli@0.9.43 test /Users/pengcao/projects/aiready/packages/cli
|
|
4
4
|
> vitest run
|
|
5
5
|
|
|
6
6
|
[?25l
|
|
7
7
|
[1m[46m RUN [49m[22m [36mv4.0.18 [39m[90m/Users/pengcao/projects/aiready/packages/cli[39m
|
|
8
8
|
|
|
9
|
-
[32m✓[39m src/__tests__/cli.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m
|
|
10
|
-
[32m✓[39m dist/__tests__/cli.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m
|
|
9
|
+
[32m✓[39m src/__tests__/cli.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
10
|
+
[32m✓[39m dist/__tests__/cli.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 9[2mms[22m[39m
|
|
11
11
|
|
|
12
12
|
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
13
13
|
[2m Tests [22m [1m[32m6 passed[39m[22m[90m (6)[39m
|
|
14
|
-
[2m Start at [22m
|
|
15
|
-
[2m Duration [22m
|
|
14
|
+
[2m Start at [22m 00:56:33
|
|
15
|
+
[2m Duration [22m 7.83s[2m (transform 2.63s, setup 0ms, import 12.42s, tests 12ms, environment 0ms)[22m
|
|
16
16
|
|
|
17
17
|
[?25h
|
package/CONTRIBUTING.md
CHANGED
|
@@ -5,6 +5,7 @@ Thank you for your interest in contributing to AIReady CLI! We welcome bug repor
|
|
|
5
5
|
## 🎯 What is the CLI?
|
|
6
6
|
|
|
7
7
|
The CLI is the **unified interface** for all AIReady analysis tools. It provides:
|
|
8
|
+
|
|
8
9
|
- **Unified scanning**: Run multiple tools (patterns, context, consistency) with one command
|
|
9
10
|
- **Individual tool access**: Use each tool directly for focused analysis
|
|
10
11
|
- **Consistent output**: Unified reporting across all tools
|
|
@@ -41,6 +42,7 @@ The CLI follows a **hub-and-spoke** pattern:
|
|
|
41
42
|
## 🐛 Reporting Issues
|
|
42
43
|
|
|
43
44
|
Found a bug or have a feature request? [Open an issue](https://github.com/caopengau/aiready-cli/issues) with:
|
|
45
|
+
|
|
44
46
|
- Clear description of the problem or feature
|
|
45
47
|
- Steps to reproduce (for bugs)
|
|
46
48
|
- Expected vs actual behavior
|
|
@@ -69,6 +71,7 @@ pnpm link
|
|
|
69
71
|
## 📝 Making Changes
|
|
70
72
|
|
|
71
73
|
1. **Fork the repository** and create a new branch:
|
|
74
|
+
|
|
72
75
|
```bash
|
|
73
76
|
git checkout -b fix/cli-output-format
|
|
74
77
|
# or
|
|
@@ -82,15 +85,17 @@ pnpm link
|
|
|
82
85
|
- Keep commands modular and focused
|
|
83
86
|
|
|
84
87
|
3. **Test your changes**:
|
|
88
|
+
|
|
85
89
|
```bash
|
|
86
90
|
pnpm build
|
|
87
91
|
pnpm test
|
|
88
|
-
|
|
92
|
+
|
|
89
93
|
# Test CLI locally
|
|
90
94
|
./dist/cli.js scan /path/to/project
|
|
91
95
|
```
|
|
92
96
|
|
|
93
97
|
4. **Commit using conventional commits**:
|
|
98
|
+
|
|
94
99
|
```bash
|
|
95
100
|
git commit -m "fix: correct output format for JSON"
|
|
96
101
|
git commit -m "feat: add new tool integration"
|
|
@@ -121,6 +126,7 @@ We use [Conventional Commits](https://www.conventionalcommits.org/):
|
|
|
121
126
|
- Test edge cases (missing arguments, invalid paths)
|
|
122
127
|
|
|
123
128
|
Example test:
|
|
129
|
+
|
|
124
130
|
```typescript
|
|
125
131
|
test('scan command runs all tools by default', async () => {
|
|
126
132
|
const result = await runCli(['scan', './test-project']);
|
|
@@ -157,10 +163,11 @@ src/
|
|
|
157
163
|
### Adding a New Command
|
|
158
164
|
|
|
159
165
|
1. Create `src/commands/your-command.ts`:
|
|
166
|
+
|
|
160
167
|
```typescript
|
|
161
168
|
import { Command } from 'commander';
|
|
162
169
|
import { globalOptions } from '../options/global';
|
|
163
|
-
|
|
170
|
+
|
|
164
171
|
export const yourCommand = new Command('your-command')
|
|
165
172
|
.description('Description of your command')
|
|
166
173
|
.argument('<directory>', 'Directory to analyze')
|
|
@@ -187,6 +194,7 @@ src/
|
|
|
187
194
|
## 🎯 Areas for Contribution
|
|
188
195
|
|
|
189
196
|
Great places to start:
|
|
197
|
+
|
|
190
198
|
- **New commands**: Add new CLI commands
|
|
191
199
|
- **Tool integration**: Integrate new analysis tools
|
|
192
200
|
- **Output formats**: Add new output options (XML, CSV, HTML)
|
|
@@ -211,6 +219,7 @@ Great places to start:
|
|
|
211
219
|
## 💡 Feature Ideas
|
|
212
220
|
|
|
213
221
|
Looking for inspiration? Consider:
|
|
222
|
+
|
|
214
223
|
- Interactive mode with guided analysis
|
|
215
224
|
- Watch mode for file changes
|
|
216
225
|
- IDE plugins integration
|
|
@@ -0,0 +1,237 @@
|
|
|
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
|
+
var severityOrder = {
|
|
13
|
+
critical: 4,
|
|
14
|
+
major: 3,
|
|
15
|
+
minor: 2,
|
|
16
|
+
info: 1
|
|
17
|
+
};
|
|
18
|
+
function sortBySeverity(results) {
|
|
19
|
+
return results.map((file) => {
|
|
20
|
+
const sortedIssues = [...file.issues].sort((a, b) => {
|
|
21
|
+
const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
|
|
22
|
+
if (severityDiff !== 0) return severityDiff;
|
|
23
|
+
return (a.location?.line || 0) - (b.location?.line || 0);
|
|
24
|
+
});
|
|
25
|
+
return { ...file, issues: sortedIssues };
|
|
26
|
+
}).sort((a, b) => {
|
|
27
|
+
const aMaxSeverity = Math.max(
|
|
28
|
+
...a.issues.map((i) => severityOrder[i.severity] || 0),
|
|
29
|
+
0
|
|
30
|
+
);
|
|
31
|
+
const bMaxSeverity = Math.max(
|
|
32
|
+
...b.issues.map((i) => severityOrder[i.severity] || 0),
|
|
33
|
+
0
|
|
34
|
+
);
|
|
35
|
+
if (aMaxSeverity !== bMaxSeverity) {
|
|
36
|
+
return bMaxSeverity - aMaxSeverity;
|
|
37
|
+
}
|
|
38
|
+
if (a.issues.length !== b.issues.length) {
|
|
39
|
+
return b.issues.length - a.issues.length;
|
|
40
|
+
}
|
|
41
|
+
return a.fileName.localeCompare(b.fileName);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function analyzeUnified(options) {
|
|
45
|
+
const startTime = Date.now();
|
|
46
|
+
const tools = options.tools || ["patterns", "context", "consistency"];
|
|
47
|
+
const result = {
|
|
48
|
+
summary: {
|
|
49
|
+
totalIssues: 0,
|
|
50
|
+
toolsRun: tools,
|
|
51
|
+
executionTime: 0
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (tools.includes("patterns")) {
|
|
55
|
+
const patternResult = await analyzePatterns(options);
|
|
56
|
+
if (options.progressCallback) {
|
|
57
|
+
options.progressCallback({ tool: "patterns", data: patternResult });
|
|
58
|
+
}
|
|
59
|
+
result.patterns = sortBySeverity(patternResult.results);
|
|
60
|
+
result.duplicates = patternResult.duplicates;
|
|
61
|
+
result.summary.totalIssues += patternResult.results.reduce(
|
|
62
|
+
(sum, file) => sum + file.issues.length,
|
|
63
|
+
0
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (tools.includes("context")) {
|
|
67
|
+
const contextResults = await analyzeContext(options);
|
|
68
|
+
if (options.progressCallback) {
|
|
69
|
+
options.progressCallback({ tool: "context", data: contextResults });
|
|
70
|
+
}
|
|
71
|
+
result.context = contextResults.sort((a, b) => {
|
|
72
|
+
const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
|
|
73
|
+
if (severityDiff !== 0) return severityDiff;
|
|
74
|
+
if (a.tokenCost !== b.tokenCost) return b.tokenCost - a.tokenCost;
|
|
75
|
+
return b.fragmentationScore - a.fragmentationScore;
|
|
76
|
+
});
|
|
77
|
+
result.summary.totalIssues += result.context?.length || 0;
|
|
78
|
+
}
|
|
79
|
+
if (tools.includes("consistency")) {
|
|
80
|
+
const consistencyOptions = {
|
|
81
|
+
rootDir: options.rootDir,
|
|
82
|
+
include: options.include,
|
|
83
|
+
exclude: options.exclude,
|
|
84
|
+
...options.consistency || {}
|
|
85
|
+
};
|
|
86
|
+
const report = await analyzeConsistency(consistencyOptions);
|
|
87
|
+
if (options.progressCallback) {
|
|
88
|
+
options.progressCallback({ tool: "consistency", data: report });
|
|
89
|
+
}
|
|
90
|
+
if (report.results) {
|
|
91
|
+
report.results = sortBySeverity(report.results);
|
|
92
|
+
}
|
|
93
|
+
result.consistency = report;
|
|
94
|
+
result.summary.totalIssues += report.summary.totalIssues;
|
|
95
|
+
}
|
|
96
|
+
if (tools.includes("doc-drift")) {
|
|
97
|
+
const { analyzeDocDrift } = await import("@aiready/doc-drift");
|
|
98
|
+
const report = await analyzeDocDrift({
|
|
99
|
+
rootDir: options.rootDir,
|
|
100
|
+
include: options.include,
|
|
101
|
+
exclude: options.exclude
|
|
102
|
+
});
|
|
103
|
+
if (options.progressCallback) {
|
|
104
|
+
options.progressCallback({ tool: "doc-drift", data: report });
|
|
105
|
+
}
|
|
106
|
+
result.docDrift = report;
|
|
107
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
108
|
+
}
|
|
109
|
+
if (tools.includes("deps-health")) {
|
|
110
|
+
const { analyzeDeps } = await import("@aiready/deps");
|
|
111
|
+
const report = await analyzeDeps({
|
|
112
|
+
rootDir: options.rootDir,
|
|
113
|
+
include: options.include,
|
|
114
|
+
exclude: options.exclude
|
|
115
|
+
});
|
|
116
|
+
if (options.progressCallback) {
|
|
117
|
+
options.progressCallback({ tool: "deps-health", data: report });
|
|
118
|
+
}
|
|
119
|
+
result.deps = report;
|
|
120
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
121
|
+
}
|
|
122
|
+
if (tools.includes("aiSignalClarity")) {
|
|
123
|
+
const { analyzeAiSignalClarity } = await import("@aiready/ai-signal-clarity");
|
|
124
|
+
const report = await analyzeAiSignalClarity({
|
|
125
|
+
rootDir: options.rootDir,
|
|
126
|
+
include: options.include,
|
|
127
|
+
exclude: options.exclude
|
|
128
|
+
});
|
|
129
|
+
if (options.progressCallback) {
|
|
130
|
+
options.progressCallback({ tool: "aiSignalClarity", data: report });
|
|
131
|
+
}
|
|
132
|
+
result.aiSignalClarity = report;
|
|
133
|
+
result.summary.totalIssues += report.results?.reduce(
|
|
134
|
+
(sum, r) => sum + (r.issues?.length || 0),
|
|
135
|
+
0
|
|
136
|
+
) || 0;
|
|
137
|
+
}
|
|
138
|
+
if (tools.includes("grounding")) {
|
|
139
|
+
const { analyzeAgentGrounding } = await import("@aiready/agent-grounding");
|
|
140
|
+
const report = await analyzeAgentGrounding({
|
|
141
|
+
rootDir: options.rootDir,
|
|
142
|
+
include: options.include,
|
|
143
|
+
exclude: options.exclude
|
|
144
|
+
});
|
|
145
|
+
if (options.progressCallback) {
|
|
146
|
+
options.progressCallback({ tool: "grounding", data: report });
|
|
147
|
+
}
|
|
148
|
+
result.grounding = report;
|
|
149
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
150
|
+
}
|
|
151
|
+
if (tools.includes("testability")) {
|
|
152
|
+
const { analyzeTestability } = await import("@aiready/testability");
|
|
153
|
+
const report = await analyzeTestability({
|
|
154
|
+
rootDir: options.rootDir,
|
|
155
|
+
include: options.include,
|
|
156
|
+
exclude: options.exclude
|
|
157
|
+
});
|
|
158
|
+
if (options.progressCallback) {
|
|
159
|
+
options.progressCallback({ tool: "testability", data: report });
|
|
160
|
+
}
|
|
161
|
+
result.testability = report;
|
|
162
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
163
|
+
}
|
|
164
|
+
if (tools.includes("changeAmplification")) {
|
|
165
|
+
const { analyzeChangeAmplification } = await import("@aiready/change-amplification");
|
|
166
|
+
const report = await analyzeChangeAmplification({
|
|
167
|
+
rootDir: options.rootDir,
|
|
168
|
+
include: options.include,
|
|
169
|
+
exclude: options.exclude
|
|
170
|
+
});
|
|
171
|
+
if (options.progressCallback) {
|
|
172
|
+
options.progressCallback({ tool: "changeAmplification", data: report });
|
|
173
|
+
}
|
|
174
|
+
result.changeAmplification = report;
|
|
175
|
+
result.summary.totalIssues += report.summary?.totalIssues || 0;
|
|
176
|
+
}
|
|
177
|
+
result.summary.executionTime = Date.now() - startTime;
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
function generateUnifiedSummary(result) {
|
|
181
|
+
const { summary } = result;
|
|
182
|
+
let output = `\u{1F680} AIReady Analysis Complete
|
|
183
|
+
|
|
184
|
+
`;
|
|
185
|
+
output += `\u{1F4CA} Summary:
|
|
186
|
+
`;
|
|
187
|
+
output += ` Tools run: ${summary.toolsRun.join(", ")}
|
|
188
|
+
`;
|
|
189
|
+
output += ` Total issues found: ${summary.totalIssues}
|
|
190
|
+
`;
|
|
191
|
+
output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
|
|
192
|
+
|
|
193
|
+
`;
|
|
194
|
+
if (result.patterns) {
|
|
195
|
+
output += `\u{1F50D} Pattern Analysis: ${result.patterns.length} issues
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
if (result.context) {
|
|
199
|
+
output += `\u{1F9E0} Context Analysis: ${result.context.length} issues
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
if (result.consistency) {
|
|
203
|
+
output += `\u{1F3F7}\uFE0F Consistency Analysis: ${result.consistency.summary.totalIssues} issues
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
if (result.docDrift) {
|
|
207
|
+
output += `\u{1F4DD} Doc Drift Analysis: ${result.docDrift.issues?.length || 0} issues
|
|
208
|
+
`;
|
|
209
|
+
}
|
|
210
|
+
if (result.deps) {
|
|
211
|
+
output += `\u{1F4E6} Dependency Health: ${result.deps.issues?.length || 0} issues
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
if (result.aiSignalClarity) {
|
|
215
|
+
output += `\u{1F9E0} AI Signal Clarity: ${result.aiSignalClarity.summary?.totalSignals || 0} signals
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
if (result.grounding) {
|
|
219
|
+
output += `\u{1F9ED} Agent Grounding: ${result.grounding.issues?.length || 0} issues
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
if (result.testability) {
|
|
223
|
+
output += `\u{1F9EA} Testability Index: ${result.testability.issues?.length || 0} issues
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
if (result.changeAmplification) {
|
|
227
|
+
output += `\u{1F4A5} Change Amplification: ${result.changeAmplification.summary?.totalIssues || 0} cascading risks
|
|
228
|
+
`;
|
|
229
|
+
}
|
|
230
|
+
return output;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
__require,
|
|
235
|
+
analyzeUnified,
|
|
236
|
+
generateUnifiedSummary
|
|
237
|
+
};
|
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
var severityOrder = {
|
|
13
|
+
critical: 4,
|
|
14
|
+
major: 3,
|
|
15
|
+
minor: 2,
|
|
16
|
+
info: 1
|
|
17
|
+
};
|
|
18
|
+
function sortBySeverity(results) {
|
|
19
|
+
return results.map((file) => {
|
|
20
|
+
const sortedIssues = [...file.issues].sort((a, b) => {
|
|
21
|
+
const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
|
|
22
|
+
if (severityDiff !== 0) return severityDiff;
|
|
23
|
+
return (a.location?.line || 0) - (b.location?.line || 0);
|
|
24
|
+
});
|
|
25
|
+
return { ...file, issues: sortedIssues };
|
|
26
|
+
}).sort((a, b) => {
|
|
27
|
+
const aMaxSeverity = Math.max(
|
|
28
|
+
...a.issues.map((i) => severityOrder[i.severity] || 0),
|
|
29
|
+
0
|
|
30
|
+
);
|
|
31
|
+
const bMaxSeverity = Math.max(
|
|
32
|
+
...b.issues.map((i) => severityOrder[i.severity] || 0),
|
|
33
|
+
0
|
|
34
|
+
);
|
|
35
|
+
if (aMaxSeverity !== bMaxSeverity) {
|
|
36
|
+
return bMaxSeverity - aMaxSeverity;
|
|
37
|
+
}
|
|
38
|
+
if (a.issues.length !== b.issues.length) {
|
|
39
|
+
return b.issues.length - a.issues.length;
|
|
40
|
+
}
|
|
41
|
+
return a.fileName.localeCompare(b.fileName);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function analyzeUnified(options) {
|
|
45
|
+
const startTime = Date.now();
|
|
46
|
+
const tools = options.tools || ["patterns", "context", "consistency"];
|
|
47
|
+
const result = {
|
|
48
|
+
summary: {
|
|
49
|
+
totalIssues: 0,
|
|
50
|
+
toolsRun: tools,
|
|
51
|
+
executionTime: 0
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (tools.includes("patterns")) {
|
|
55
|
+
const patternResult = await analyzePatterns(options);
|
|
56
|
+
if (options.progressCallback) {
|
|
57
|
+
options.progressCallback({ tool: "patterns", data: patternResult });
|
|
58
|
+
}
|
|
59
|
+
result.patterns = sortBySeverity(patternResult.results);
|
|
60
|
+
result.duplicates = patternResult.duplicates;
|
|
61
|
+
result.summary.totalIssues += patternResult.results.reduce(
|
|
62
|
+
(sum, file) => sum + file.issues.length,
|
|
63
|
+
0
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (tools.includes("context")) {
|
|
67
|
+
const contextResults = await analyzeContext(options);
|
|
68
|
+
if (options.progressCallback) {
|
|
69
|
+
options.progressCallback({ tool: "context", data: contextResults });
|
|
70
|
+
}
|
|
71
|
+
result.context = contextResults.sort((a, b) => {
|
|
72
|
+
const severityDiff = (severityOrder[b.severity] || 0) - (severityOrder[a.severity] || 0);
|
|
73
|
+
if (severityDiff !== 0) return severityDiff;
|
|
74
|
+
if (a.tokenCost !== b.tokenCost) return b.tokenCost - a.tokenCost;
|
|
75
|
+
return b.fragmentationScore - a.fragmentationScore;
|
|
76
|
+
});
|
|
77
|
+
result.summary.totalIssues += result.context?.length || 0;
|
|
78
|
+
}
|
|
79
|
+
if (tools.includes("consistency")) {
|
|
80
|
+
const consistencyOptions = {
|
|
81
|
+
rootDir: options.rootDir,
|
|
82
|
+
include: options.include,
|
|
83
|
+
exclude: options.exclude,
|
|
84
|
+
...options.consistency || {}
|
|
85
|
+
};
|
|
86
|
+
const report = await analyzeConsistency(consistencyOptions);
|
|
87
|
+
if (options.progressCallback) {
|
|
88
|
+
options.progressCallback({ tool: "consistency", data: report });
|
|
89
|
+
}
|
|
90
|
+
if (report.results) {
|
|
91
|
+
report.results = sortBySeverity(report.results);
|
|
92
|
+
}
|
|
93
|
+
result.consistency = report;
|
|
94
|
+
result.summary.totalIssues += report.summary.totalIssues;
|
|
95
|
+
}
|
|
96
|
+
if (tools.includes("doc-drift")) {
|
|
97
|
+
const { analyzeDocDrift } = await import("@aiready/doc-drift");
|
|
98
|
+
const report = await analyzeDocDrift({
|
|
99
|
+
rootDir: options.rootDir,
|
|
100
|
+
include: options.include,
|
|
101
|
+
exclude: options.exclude,
|
|
102
|
+
onProgress: options.onProgress
|
|
103
|
+
});
|
|
104
|
+
if (options.progressCallback) {
|
|
105
|
+
options.progressCallback({ tool: "doc-drift", data: report });
|
|
106
|
+
}
|
|
107
|
+
result.docDrift = report;
|
|
108
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
109
|
+
}
|
|
110
|
+
if (tools.includes("deps-health")) {
|
|
111
|
+
const { analyzeDeps } = await import("@aiready/deps");
|
|
112
|
+
const report = await analyzeDeps({
|
|
113
|
+
rootDir: options.rootDir,
|
|
114
|
+
include: options.include,
|
|
115
|
+
exclude: options.exclude,
|
|
116
|
+
onProgress: options.onProgress
|
|
117
|
+
});
|
|
118
|
+
if (options.progressCallback) {
|
|
119
|
+
options.progressCallback({ tool: "deps-health", data: report });
|
|
120
|
+
}
|
|
121
|
+
result.deps = report;
|
|
122
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
123
|
+
}
|
|
124
|
+
if (tools.includes("aiSignalClarity")) {
|
|
125
|
+
const { analyzeAiSignalClarity } = await import("@aiready/ai-signal-clarity");
|
|
126
|
+
const report = await analyzeAiSignalClarity({
|
|
127
|
+
rootDir: options.rootDir,
|
|
128
|
+
include: options.include,
|
|
129
|
+
exclude: options.exclude,
|
|
130
|
+
onProgress: options.onProgress
|
|
131
|
+
});
|
|
132
|
+
if (options.progressCallback) {
|
|
133
|
+
options.progressCallback({ tool: "aiSignalClarity", data: report });
|
|
134
|
+
}
|
|
135
|
+
result.aiSignalClarity = report;
|
|
136
|
+
result.summary.totalIssues += report.results?.reduce(
|
|
137
|
+
(sum, r) => sum + (r.issues?.length || 0),
|
|
138
|
+
0
|
|
139
|
+
) || 0;
|
|
140
|
+
}
|
|
141
|
+
if (tools.includes("grounding")) {
|
|
142
|
+
const { analyzeAgentGrounding } = await import("@aiready/agent-grounding");
|
|
143
|
+
const report = await analyzeAgentGrounding({
|
|
144
|
+
rootDir: options.rootDir,
|
|
145
|
+
include: options.include,
|
|
146
|
+
exclude: options.exclude,
|
|
147
|
+
onProgress: options.onProgress
|
|
148
|
+
});
|
|
149
|
+
if (options.progressCallback) {
|
|
150
|
+
options.progressCallback({ tool: "grounding", data: report });
|
|
151
|
+
}
|
|
152
|
+
result.grounding = report;
|
|
153
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
154
|
+
}
|
|
155
|
+
if (tools.includes("testability")) {
|
|
156
|
+
const { analyzeTestability } = await import("@aiready/testability");
|
|
157
|
+
const report = await analyzeTestability({
|
|
158
|
+
rootDir: options.rootDir,
|
|
159
|
+
include: options.include,
|
|
160
|
+
exclude: options.exclude,
|
|
161
|
+
onProgress: options.onProgress
|
|
162
|
+
});
|
|
163
|
+
if (options.progressCallback) {
|
|
164
|
+
options.progressCallback({ tool: "testability", data: report });
|
|
165
|
+
}
|
|
166
|
+
result.testability = report;
|
|
167
|
+
result.summary.totalIssues += report.issues?.length || 0;
|
|
168
|
+
}
|
|
169
|
+
if (tools.includes("changeAmplification")) {
|
|
170
|
+
const { analyzeChangeAmplification } = await import("@aiready/change-amplification");
|
|
171
|
+
const report = await analyzeChangeAmplification({
|
|
172
|
+
rootDir: options.rootDir,
|
|
173
|
+
include: options.include,
|
|
174
|
+
exclude: options.exclude,
|
|
175
|
+
onProgress: options.onProgress
|
|
176
|
+
});
|
|
177
|
+
if (options.progressCallback) {
|
|
178
|
+
options.progressCallback({ tool: "changeAmplification", data: report });
|
|
179
|
+
}
|
|
180
|
+
result.changeAmplification = report;
|
|
181
|
+
result.summary.totalIssues += report.summary?.totalIssues || 0;
|
|
182
|
+
}
|
|
183
|
+
result.summary.executionTime = Date.now() - startTime;
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
function generateUnifiedSummary(result) {
|
|
187
|
+
const { summary } = result;
|
|
188
|
+
let output = `\u{1F680} AIReady Analysis Complete
|
|
189
|
+
|
|
190
|
+
`;
|
|
191
|
+
output += `\u{1F4CA} Summary:
|
|
192
|
+
`;
|
|
193
|
+
output += ` Tools run: ${summary.toolsRun.join(", ")}
|
|
194
|
+
`;
|
|
195
|
+
output += ` Total issues found: ${summary.totalIssues}
|
|
196
|
+
`;
|
|
197
|
+
output += ` Execution time: ${(summary.executionTime / 1e3).toFixed(2)}s
|
|
198
|
+
|
|
199
|
+
`;
|
|
200
|
+
if (result.patterns) {
|
|
201
|
+
output += `\u{1F50D} Pattern Analysis: ${result.patterns.length} issues
|
|
202
|
+
`;
|
|
203
|
+
}
|
|
204
|
+
if (result.context) {
|
|
205
|
+
output += `\u{1F9E0} Context Analysis: ${result.context.length} issues
|
|
206
|
+
`;
|
|
207
|
+
}
|
|
208
|
+
if (result.consistency) {
|
|
209
|
+
output += `\u{1F3F7}\uFE0F Consistency Analysis: ${result.consistency.summary.totalIssues} issues
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
if (result.docDrift) {
|
|
213
|
+
output += `\u{1F4DD} Doc Drift Analysis: ${result.docDrift.issues?.length || 0} issues
|
|
214
|
+
`;
|
|
215
|
+
}
|
|
216
|
+
if (result.deps) {
|
|
217
|
+
output += `\u{1F4E6} Dependency Health: ${result.deps.issues?.length || 0} issues
|
|
218
|
+
`;
|
|
219
|
+
}
|
|
220
|
+
if (result.aiSignalClarity) {
|
|
221
|
+
output += `\u{1F9E0} AI Signal Clarity: ${result.aiSignalClarity.summary?.totalSignals || 0} signals
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
if (result.grounding) {
|
|
225
|
+
output += `\u{1F9ED} Agent Grounding: ${result.grounding.issues?.length || 0} issues
|
|
226
|
+
`;
|
|
227
|
+
}
|
|
228
|
+
if (result.testability) {
|
|
229
|
+
output += `\u{1F9EA} Testability Index: ${result.testability.issues?.length || 0} issues
|
|
230
|
+
`;
|
|
231
|
+
}
|
|
232
|
+
if (result.changeAmplification) {
|
|
233
|
+
output += `\u{1F4A5} Change Amplification: ${result.changeAmplification.summary?.totalIssues || 0} cascading risks
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
return output;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export {
|
|
240
|
+
__require,
|
|
241
|
+
analyzeUnified,
|
|
242
|
+
generateUnifiedSummary
|
|
243
|
+
};
|