@aiready/core 0.3.7 → 0.5.1
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/README.md +0 -15
- package/dist/index.d.mts +2 -11
- package/dist/index.d.ts +2 -11
- package/dist/index.js +28 -50
- package/dist/index.mjs +28 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,20 +44,7 @@ const tokenCount = estimateTokens(code);
|
|
|
44
44
|
console.log(`Estimated tokens: ${tokenCount}`);
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
### Similarity Detection
|
|
48
47
|
|
|
49
|
-
```typescript
|
|
50
|
-
import { similarityScore, levenshteinDistance } from '@aiready/core';
|
|
51
|
-
|
|
52
|
-
const code1 = 'function handleUser(user) { ... }';
|
|
53
|
-
const code2 = 'function handlePost(post) { ... }';
|
|
54
|
-
|
|
55
|
-
const similarity = similarityScore(code1, code2);
|
|
56
|
-
console.log(`Similarity: ${(similarity * 100).toFixed(1)}%`);
|
|
57
|
-
|
|
58
|
-
const distance = levenshteinDistance(code1, code2);
|
|
59
|
-
console.log(`Edit distance: ${distance}`);
|
|
60
|
-
```
|
|
61
48
|
|
|
62
49
|
### TypeScript Types
|
|
63
50
|
|
|
@@ -104,8 +91,6 @@ const result: AnalysisResult = {
|
|
|
104
91
|
### Metrics
|
|
105
92
|
|
|
106
93
|
- **`estimateTokens(text: string): number`** - Estimate token count (~4 chars = 1 token)
|
|
107
|
-
- **`levenshteinDistance(str1: string, str2: string): number`** - Calculate edit distance
|
|
108
|
-
- **`similarityScore(str1: string, str2: string): number`** - Calculate similarity (0-1)
|
|
109
94
|
|
|
110
95
|
### AST Parsing
|
|
111
96
|
|
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ interface Issue {
|
|
|
10
10
|
location: Location;
|
|
11
11
|
suggestion?: string;
|
|
12
12
|
}
|
|
13
|
-
type IssueType = 'duplicate-pattern' | 'context-fragmentation' | 'doc-drift' | 'naming-inconsistency' | 'dead-code' | 'circular-dependency' | 'missing-types';
|
|
13
|
+
type IssueType = 'duplicate-pattern' | 'context-fragmentation' | 'doc-drift' | 'naming-inconsistency' | 'naming-quality' | 'pattern-inconsistency' | 'architecture-inconsistency' | 'dead-code' | 'circular-dependency' | 'missing-types';
|
|
14
14
|
interface Location {
|
|
15
15
|
file: string;
|
|
16
16
|
line: number;
|
|
@@ -103,15 +103,6 @@ declare function extractImports(ast: ASTNode): string[];
|
|
|
103
103
|
* ~1 token ≈ 4 characters for code
|
|
104
104
|
*/
|
|
105
105
|
declare function estimateTokens(text: string): number;
|
|
106
|
-
/**
|
|
107
|
-
* Calculate Levenshtein distance between two strings
|
|
108
|
-
* Useful for similarity detection
|
|
109
|
-
*/
|
|
110
|
-
declare function levenshteinDistance(str1: string, str2: string): number;
|
|
111
|
-
/**
|
|
112
|
-
* Calculate similarity score (0-1) between two strings
|
|
113
|
-
*/
|
|
114
|
-
declare function similarityScore(str1: string, str2: string): number;
|
|
115
106
|
|
|
116
107
|
declare function loadConfig(rootDir: string): AIReadyConfig | null;
|
|
117
108
|
declare function mergeConfigWithDefaults(userConfig: AIReadyConfig | null, defaults: any): any;
|
|
@@ -144,4 +135,4 @@ declare function handleCLIError(error: unknown, commandName: string): never;
|
|
|
144
135
|
*/
|
|
145
136
|
declare function getElapsedTime(startTime: number): string;
|
|
146
137
|
|
|
147
|
-
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type Issue, type IssueType, type Location, type Metrics, type Report, type ScanOptions, estimateTokens, extractFunctions, extractImports, getElapsedTime, getFileExtension, handleCLIError, handleJSONOutput, isSourceFile,
|
|
138
|
+
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type Issue, type IssueType, type Location, type Metrics, type Report, type ScanOptions, estimateTokens, extractFunctions, extractImports, getElapsedTime, getFileExtension, handleCLIError, handleJSONOutput, isSourceFile, loadConfig, loadMergedConfig, mergeConfigWithDefaults, parseCode, readFileContent, scanFiles };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface Issue {
|
|
|
10
10
|
location: Location;
|
|
11
11
|
suggestion?: string;
|
|
12
12
|
}
|
|
13
|
-
type IssueType = 'duplicate-pattern' | 'context-fragmentation' | 'doc-drift' | 'naming-inconsistency' | 'dead-code' | 'circular-dependency' | 'missing-types';
|
|
13
|
+
type IssueType = 'duplicate-pattern' | 'context-fragmentation' | 'doc-drift' | 'naming-inconsistency' | 'naming-quality' | 'pattern-inconsistency' | 'architecture-inconsistency' | 'dead-code' | 'circular-dependency' | 'missing-types';
|
|
14
14
|
interface Location {
|
|
15
15
|
file: string;
|
|
16
16
|
line: number;
|
|
@@ -103,15 +103,6 @@ declare function extractImports(ast: ASTNode): string[];
|
|
|
103
103
|
* ~1 token ≈ 4 characters for code
|
|
104
104
|
*/
|
|
105
105
|
declare function estimateTokens(text: string): number;
|
|
106
|
-
/**
|
|
107
|
-
* Calculate Levenshtein distance between two strings
|
|
108
|
-
* Useful for similarity detection
|
|
109
|
-
*/
|
|
110
|
-
declare function levenshteinDistance(str1: string, str2: string): number;
|
|
111
|
-
/**
|
|
112
|
-
* Calculate similarity score (0-1) between two strings
|
|
113
|
-
*/
|
|
114
|
-
declare function similarityScore(str1: string, str2: string): number;
|
|
115
106
|
|
|
116
107
|
declare function loadConfig(rootDir: string): AIReadyConfig | null;
|
|
117
108
|
declare function mergeConfigWithDefaults(userConfig: AIReadyConfig | null, defaults: any): any;
|
|
@@ -144,4 +135,4 @@ declare function handleCLIError(error: unknown, commandName: string): never;
|
|
|
144
135
|
*/
|
|
145
136
|
declare function getElapsedTime(startTime: number): string;
|
|
146
137
|
|
|
147
|
-
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type Issue, type IssueType, type Location, type Metrics, type Report, type ScanOptions, estimateTokens, extractFunctions, extractImports, getElapsedTime, getFileExtension, handleCLIError, handleJSONOutput, isSourceFile,
|
|
138
|
+
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type Issue, type IssueType, type Location, type Metrics, type Report, type ScanOptions, estimateTokens, extractFunctions, extractImports, getElapsedTime, getFileExtension, handleCLIError, handleJSONOutput, isSourceFile, loadConfig, loadMergedConfig, mergeConfigWithDefaults, parseCode, readFileContent, scanFiles };
|
package/dist/index.js
CHANGED
|
@@ -28,14 +28,12 @@ __export(index_exports, {
|
|
|
28
28
|
handleCLIError: () => handleCLIError,
|
|
29
29
|
handleJSONOutput: () => handleJSONOutput,
|
|
30
30
|
isSourceFile: () => isSourceFile,
|
|
31
|
-
levenshteinDistance: () => levenshteinDistance,
|
|
32
31
|
loadConfig: () => loadConfig,
|
|
33
32
|
loadMergedConfig: () => loadMergedConfig,
|
|
34
33
|
mergeConfigWithDefaults: () => mergeConfigWithDefaults,
|
|
35
34
|
parseCode: () => parseCode,
|
|
36
35
|
readFileContent: () => readFileContent,
|
|
37
|
-
scanFiles: () => scanFiles
|
|
38
|
-
similarityScore: () => similarityScore
|
|
36
|
+
scanFiles: () => scanFiles
|
|
39
37
|
});
|
|
40
38
|
module.exports = __toCommonJS(index_exports);
|
|
41
39
|
|
|
@@ -53,6 +51,7 @@ var DEFAULT_EXCLUDE = [
|
|
|
53
51
|
"**/target/**",
|
|
54
52
|
"**/bin/**",
|
|
55
53
|
"**/obj/**",
|
|
54
|
+
"**/cdk.out/**",
|
|
56
55
|
// Framework-specific build dirs
|
|
57
56
|
"**/.next/**",
|
|
58
57
|
"**/.nuxt/**",
|
|
@@ -120,33 +119,6 @@ function extractImports(ast) {
|
|
|
120
119
|
function estimateTokens(text) {
|
|
121
120
|
return Math.ceil(text.length / 4);
|
|
122
121
|
}
|
|
123
|
-
function levenshteinDistance(str1, str2) {
|
|
124
|
-
const len1 = str1.length;
|
|
125
|
-
const len2 = str2.length;
|
|
126
|
-
const matrix = [];
|
|
127
|
-
for (let i = 0; i <= len1; i++) {
|
|
128
|
-
matrix[i] = [i];
|
|
129
|
-
}
|
|
130
|
-
for (let j = 0; j <= len2; j++) {
|
|
131
|
-
matrix[0][j] = j;
|
|
132
|
-
}
|
|
133
|
-
for (let i = 1; i <= len1; i++) {
|
|
134
|
-
for (let j = 1; j <= len2; j++) {
|
|
135
|
-
const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
136
|
-
matrix[i][j] = Math.min(
|
|
137
|
-
matrix[i - 1][j] + 1,
|
|
138
|
-
matrix[i][j - 1] + 1,
|
|
139
|
-
matrix[i - 1][j - 1] + cost
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return matrix[len1][len2];
|
|
144
|
-
}
|
|
145
|
-
function similarityScore(str1, str2) {
|
|
146
|
-
const distance = levenshteinDistance(str1, str2);
|
|
147
|
-
const maxLength = Math.max(str1.length, str2.length);
|
|
148
|
-
return maxLength === 0 ? 1 : 1 - distance / maxLength;
|
|
149
|
-
}
|
|
150
122
|
|
|
151
123
|
// src/utils/config.ts
|
|
152
124
|
var import_fs = require("fs");
|
|
@@ -160,26 +132,34 @@ var CONFIG_FILES = [
|
|
|
160
132
|
".aireadyrc.js"
|
|
161
133
|
];
|
|
162
134
|
function loadConfig(rootDir) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
135
|
+
let currentDir = (0, import_path.resolve)(rootDir);
|
|
136
|
+
while (true) {
|
|
137
|
+
for (const configFile of CONFIG_FILES) {
|
|
138
|
+
const configPath = (0, import_path.join)(currentDir, configFile);
|
|
139
|
+
if ((0, import_fs.existsSync)(configPath)) {
|
|
140
|
+
try {
|
|
141
|
+
let config;
|
|
142
|
+
if (configFile.endsWith(".js")) {
|
|
143
|
+
delete require.cache[require.resolve(configPath)];
|
|
144
|
+
config = require(configPath);
|
|
145
|
+
} else {
|
|
146
|
+
const content = (0, import_fs.readFileSync)(configPath, "utf-8");
|
|
147
|
+
config = JSON.parse(content);
|
|
148
|
+
}
|
|
149
|
+
if (typeof config !== "object" || config === null) {
|
|
150
|
+
throw new Error("Config must be an object");
|
|
151
|
+
}
|
|
152
|
+
return config;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
throw new Error(`Failed to load config from ${configPath}: ${error}`);
|
|
174
155
|
}
|
|
175
|
-
if (typeof config !== "object" || config === null) {
|
|
176
|
-
throw new Error("Config must be an object");
|
|
177
|
-
}
|
|
178
|
-
return config;
|
|
179
|
-
} catch (error) {
|
|
180
|
-
throw new Error(`Failed to load config from ${configPath}: ${error}`);
|
|
181
156
|
}
|
|
182
157
|
}
|
|
158
|
+
const parent = (0, import_path.dirname)(currentDir);
|
|
159
|
+
if (parent === currentDir) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
currentDir = parent;
|
|
183
163
|
}
|
|
184
164
|
return null;
|
|
185
165
|
}
|
|
@@ -243,12 +223,10 @@ function getElapsedTime(startTime) {
|
|
|
243
223
|
handleCLIError,
|
|
244
224
|
handleJSONOutput,
|
|
245
225
|
isSourceFile,
|
|
246
|
-
levenshteinDistance,
|
|
247
226
|
loadConfig,
|
|
248
227
|
loadMergedConfig,
|
|
249
228
|
mergeConfigWithDefaults,
|
|
250
229
|
parseCode,
|
|
251
230
|
readFileContent,
|
|
252
|
-
scanFiles
|
|
253
|
-
similarityScore
|
|
231
|
+
scanFiles
|
|
254
232
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ var DEFAULT_EXCLUDE = [
|
|
|
19
19
|
"**/target/**",
|
|
20
20
|
"**/bin/**",
|
|
21
21
|
"**/obj/**",
|
|
22
|
+
"**/cdk.out/**",
|
|
22
23
|
// Framework-specific build dirs
|
|
23
24
|
"**/.next/**",
|
|
24
25
|
"**/.nuxt/**",
|
|
@@ -86,37 +87,10 @@ function extractImports(ast) {
|
|
|
86
87
|
function estimateTokens(text) {
|
|
87
88
|
return Math.ceil(text.length / 4);
|
|
88
89
|
}
|
|
89
|
-
function levenshteinDistance(str1, str2) {
|
|
90
|
-
const len1 = str1.length;
|
|
91
|
-
const len2 = str2.length;
|
|
92
|
-
const matrix = [];
|
|
93
|
-
for (let i = 0; i <= len1; i++) {
|
|
94
|
-
matrix[i] = [i];
|
|
95
|
-
}
|
|
96
|
-
for (let j = 0; j <= len2; j++) {
|
|
97
|
-
matrix[0][j] = j;
|
|
98
|
-
}
|
|
99
|
-
for (let i = 1; i <= len1; i++) {
|
|
100
|
-
for (let j = 1; j <= len2; j++) {
|
|
101
|
-
const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
102
|
-
matrix[i][j] = Math.min(
|
|
103
|
-
matrix[i - 1][j] + 1,
|
|
104
|
-
matrix[i][j - 1] + 1,
|
|
105
|
-
matrix[i - 1][j - 1] + cost
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return matrix[len1][len2];
|
|
110
|
-
}
|
|
111
|
-
function similarityScore(str1, str2) {
|
|
112
|
-
const distance = levenshteinDistance(str1, str2);
|
|
113
|
-
const maxLength = Math.max(str1.length, str2.length);
|
|
114
|
-
return maxLength === 0 ? 1 : 1 - distance / maxLength;
|
|
115
|
-
}
|
|
116
90
|
|
|
117
91
|
// src/utils/config.ts
|
|
118
92
|
import { readFileSync, existsSync } from "fs";
|
|
119
|
-
import { resolve } from "path";
|
|
93
|
+
import { join, resolve, dirname } from "path";
|
|
120
94
|
var CONFIG_FILES = [
|
|
121
95
|
"aiready.json",
|
|
122
96
|
"aiready.config.json",
|
|
@@ -126,26 +100,34 @@ var CONFIG_FILES = [
|
|
|
126
100
|
".aireadyrc.js"
|
|
127
101
|
];
|
|
128
102
|
function loadConfig(rootDir) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
103
|
+
let currentDir = resolve(rootDir);
|
|
104
|
+
while (true) {
|
|
105
|
+
for (const configFile of CONFIG_FILES) {
|
|
106
|
+
const configPath = join(currentDir, configFile);
|
|
107
|
+
if (existsSync(configPath)) {
|
|
108
|
+
try {
|
|
109
|
+
let config;
|
|
110
|
+
if (configFile.endsWith(".js")) {
|
|
111
|
+
delete __require.cache[__require.resolve(configPath)];
|
|
112
|
+
config = __require(configPath);
|
|
113
|
+
} else {
|
|
114
|
+
const content = readFileSync(configPath, "utf-8");
|
|
115
|
+
config = JSON.parse(content);
|
|
116
|
+
}
|
|
117
|
+
if (typeof config !== "object" || config === null) {
|
|
118
|
+
throw new Error("Config must be an object");
|
|
119
|
+
}
|
|
120
|
+
return config;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new Error(`Failed to load config from ${configPath}: ${error}`);
|
|
140
123
|
}
|
|
141
|
-
if (typeof config !== "object" || config === null) {
|
|
142
|
-
throw new Error("Config must be an object");
|
|
143
|
-
}
|
|
144
|
-
return config;
|
|
145
|
-
} catch (error) {
|
|
146
|
-
throw new Error(`Failed to load config from ${configPath}: ${error}`);
|
|
147
124
|
}
|
|
148
125
|
}
|
|
126
|
+
const parent = dirname(currentDir);
|
|
127
|
+
if (parent === currentDir) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
currentDir = parent;
|
|
149
131
|
}
|
|
150
132
|
return null;
|
|
151
133
|
}
|
|
@@ -208,12 +190,10 @@ export {
|
|
|
208
190
|
handleCLIError,
|
|
209
191
|
handleJSONOutput,
|
|
210
192
|
isSourceFile,
|
|
211
|
-
levenshteinDistance,
|
|
212
193
|
loadConfig,
|
|
213
194
|
loadMergedConfig,
|
|
214
195
|
mergeConfigWithDefaults,
|
|
215
196
|
parseCode,
|
|
216
197
|
readFileContent,
|
|
217
|
-
scanFiles
|
|
218
|
-
similarityScore
|
|
198
|
+
scanFiles
|
|
219
199
|
};
|