@aiready/core 0.1.0 → 0.1.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 +131 -0
- package/package.json +6 -1
- package/.turbo/turbo-build.log +0 -61
- package/.turbo/turbo-test.log +0 -13
- package/src/index.ts +0 -4
- package/src/types.ts +0 -59
- package/src/utils/ast-parser.ts +0 -28
- package/src/utils/file-scanner.ts +0 -42
- package/src/utils/metrics.ts +0 -47
- package/tsconfig.json +0 -20
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @aiready/core
|
|
2
|
+
|
|
3
|
+
> **Shared utilities and types for AIReady analysis tools**
|
|
4
|
+
|
|
5
|
+
This package provides common utilities, type definitions, and helper functions used across all AIReady tools. It's designed as a foundational library for building code analysis tools focused on AI-readiness.
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @aiready/core
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @aiready/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🔧 Usage
|
|
16
|
+
|
|
17
|
+
### File Scanning
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { scanFiles } from '@aiready/core';
|
|
21
|
+
|
|
22
|
+
const files = await scanFiles({
|
|
23
|
+
rootDir: './src',
|
|
24
|
+
include: ['**/*.ts', '**/*.tsx'],
|
|
25
|
+
exclude: ['**/*.test.ts', '**/node_modules/**'],
|
|
26
|
+
maxDepth: 10,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(`Found ${files.length} files`);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Token Estimation
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { estimateTokens } from '@aiready/core';
|
|
36
|
+
|
|
37
|
+
const code = `
|
|
38
|
+
function hello() {
|
|
39
|
+
return "world";
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
const tokenCount = estimateTokens(code);
|
|
44
|
+
console.log(`Estimated tokens: ${tokenCount}`);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Similarity Detection
|
|
48
|
+
|
|
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
|
+
|
|
62
|
+
### TypeScript Types
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import type {
|
|
66
|
+
AnalysisResult,
|
|
67
|
+
Issue,
|
|
68
|
+
IssueType,
|
|
69
|
+
Location,
|
|
70
|
+
Metrics,
|
|
71
|
+
ScanOptions,
|
|
72
|
+
Report,
|
|
73
|
+
} from '@aiready/core';
|
|
74
|
+
|
|
75
|
+
const result: AnalysisResult = {
|
|
76
|
+
fileName: 'src/utils/helper.ts',
|
|
77
|
+
issues: [
|
|
78
|
+
{
|
|
79
|
+
type: 'duplicate-pattern',
|
|
80
|
+
severity: 'major',
|
|
81
|
+
message: 'Similar pattern found',
|
|
82
|
+
location: {
|
|
83
|
+
file: 'src/utils/helper.ts',
|
|
84
|
+
line: 15,
|
|
85
|
+
column: 5,
|
|
86
|
+
},
|
|
87
|
+
suggestion: 'Extract to shared utility',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
metrics: {
|
|
91
|
+
tokenCost: 250,
|
|
92
|
+
consistencyScore: 0.85,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 📚 API Reference
|
|
98
|
+
|
|
99
|
+
### File Operations
|
|
100
|
+
|
|
101
|
+
- **`scanFiles(options: ScanOptions): Promise<string[]>`** - Scan directory for files matching patterns
|
|
102
|
+
- **`readFileContent(filePath: string): Promise<string>`** - Read file contents
|
|
103
|
+
|
|
104
|
+
### Metrics
|
|
105
|
+
|
|
106
|
+
- **`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
|
+
|
|
110
|
+
### AST Parsing
|
|
111
|
+
|
|
112
|
+
- **`parseTypeScript(code: string): SourceFile`** - Parse TypeScript/JavaScript code to AST
|
|
113
|
+
- **`extractFunctions(ast: SourceFile): FunctionNode[]`** - Extract function declarations
|
|
114
|
+
|
|
115
|
+
### Types
|
|
116
|
+
|
|
117
|
+
All shared TypeScript interfaces and types for analysis results, issues, metrics, and configuration options.
|
|
118
|
+
|
|
119
|
+
## 🔗 Related Packages
|
|
120
|
+
|
|
121
|
+
- **[@aiready/pattern-detect](https://www.npmjs.com/package/@aiready/pattern-detect)** - Semantic duplicate pattern detection
|
|
122
|
+
- **@aiready/context-analyzer** - Token cost and context fragmentation analysis _(coming soon)_
|
|
123
|
+
- **@aiready/doc-drift** - Documentation freshness tracking _(coming soon)_
|
|
124
|
+
|
|
125
|
+
## 📝 License
|
|
126
|
+
|
|
127
|
+
MIT - See [LICENSE](./LICENSE)
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
**Part of the [AIReady](https://github.com/aiready) toolkit** | [Documentation](https://aiready.dev) | [GitHub](https://github.com/caopengau/aiready-core)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Shared utilities for AIReady analysis tools",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,6 +27,11 @@
|
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/caopengau/aiready-core/issues"
|
|
29
29
|
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
30
35
|
"devDependencies": {
|
|
31
36
|
"tsup": "^8.3.5",
|
|
32
37
|
"eslint": "^9.17.0"
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @aiready/core@0.1.0 build /Users/pengcao/projects/aiready/packages/core
|
|
4
|
-
> tsup src/index.ts --format cjs,esm --dts
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
-
[34mCLI[39m tsup v8.5.1
|
|
9
|
-
[34mCLI[39m Target: es2020
|
|
10
|
-
[34mCJS[39m Build start
|
|
11
|
-
[34mESM[39m Build start
|
|
12
|
-
DTS Build start
|
|
13
|
-
|
|
14
|
-
[90m[[90m12:59:20 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
15
|
-
|
|
16
|
-
package.json:12:6:
|
|
17
|
-
[37m 12 │ [32m"types"[37m: "./dist/index.d.ts"
|
|
18
|
-
╵ [32m~~~~~~~[0m
|
|
19
|
-
|
|
20
|
-
The "import" condition comes earlier and will be used for all "import" statements:
|
|
21
|
-
|
|
22
|
-
package.json:11:6:
|
|
23
|
-
[37m 11 │ [32m"import"[37m: "./dist/index.mjs",
|
|
24
|
-
╵ [32m~~~~~~~~[0m
|
|
25
|
-
|
|
26
|
-
The "require" condition comes earlier and will be used for all "require" calls:
|
|
27
|
-
|
|
28
|
-
package.json:10:6:
|
|
29
|
-
[37m 10 │ [32m"require"[37m: "./dist/index.js",
|
|
30
|
-
╵ [32m~~~~~~~~~[0m
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[90m[[90m12:59:20 AM[90m][39m [43m[30m WARN [39m[49m [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe condition "types" here will never be used as it comes after both "import" and "require"[0m [package.json]
|
|
36
|
-
|
|
37
|
-
package.json:12:6:
|
|
38
|
-
[37m 12 │ [32m"types"[37m: "./dist/index.d.ts"
|
|
39
|
-
╵ [32m~~~~~~~[0m
|
|
40
|
-
|
|
41
|
-
The "import" condition comes earlier and will be used for all "import" statements:
|
|
42
|
-
|
|
43
|
-
package.json:11:6:
|
|
44
|
-
[37m 11 │ [32m"import"[37m: "./dist/index.mjs",
|
|
45
|
-
╵ [32m~~~~~~~~[0m
|
|
46
|
-
|
|
47
|
-
The "require" condition comes earlier and will be used for all "require" calls:
|
|
48
|
-
|
|
49
|
-
package.json:10:6:
|
|
50
|
-
[37m 10 │ [32m"require"[37m: "./dist/index.js",
|
|
51
|
-
╵ [32m~~~~~~~~~[0m
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m2.02 KB[39m
|
|
56
|
-
[32mESM[39m ⚡️ Build success in 273ms
|
|
57
|
-
[32mCJS[39m [1mdist/index.js [22m[32m3.42 KB[39m
|
|
58
|
-
[32mCJS[39m ⚡️ Build success in 274ms
|
|
59
|
-
DTS ⚡️ Build success in 435ms
|
|
60
|
-
DTS dist/index.d.ts 2.48 KB
|
|
61
|
-
DTS dist/index.d.mts 2.48 KB
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @aiready/core@0.1.0 test /Users/pengcao/projects/aiready/packages/core
|
|
4
|
-
> vitest run
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[1m[7m[36m RUN [39m[27m[22m [36mv2.1.9 [39m[90m/Users/pengcao/projects/aiready/packages/core[39m
|
|
8
|
-
|
|
9
|
-
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
10
|
-
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
11
|
-
[31m
|
|
12
|
-
No test files found, exiting with code 1[39m
|
|
13
|
-
[?25h[41m[30m ELIFECYCLE [39m[49m [31mTest failed. See above for more details.[39m
|
package/src/index.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export interface AnalysisResult {
|
|
2
|
-
fileName: string;
|
|
3
|
-
issues: Issue[];
|
|
4
|
-
metrics: Metrics;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface Issue {
|
|
8
|
-
type: IssueType;
|
|
9
|
-
severity: 'critical' | 'major' | 'minor' | 'info';
|
|
10
|
-
message: string;
|
|
11
|
-
location: Location;
|
|
12
|
-
suggestion?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type IssueType =
|
|
16
|
-
| 'duplicate-pattern'
|
|
17
|
-
| 'context-fragmentation'
|
|
18
|
-
| 'doc-drift'
|
|
19
|
-
| 'naming-inconsistency'
|
|
20
|
-
| 'dead-code'
|
|
21
|
-
| 'circular-dependency'
|
|
22
|
-
| 'missing-types';
|
|
23
|
-
|
|
24
|
-
export interface Location {
|
|
25
|
-
file: string;
|
|
26
|
-
line: number;
|
|
27
|
-
column?: number;
|
|
28
|
-
endLine?: number;
|
|
29
|
-
endColumn?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface Metrics {
|
|
33
|
-
tokenCost?: number;
|
|
34
|
-
complexityScore?: number;
|
|
35
|
-
consistencyScore?: number;
|
|
36
|
-
docFreshnessScore?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface ScanOptions {
|
|
40
|
-
rootDir: string;
|
|
41
|
-
include?: string[];
|
|
42
|
-
exclude?: string[];
|
|
43
|
-
maxDepth?: number;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Report {
|
|
47
|
-
summary: {
|
|
48
|
-
totalFiles: number;
|
|
49
|
-
totalIssues: number;
|
|
50
|
-
criticalIssues: number;
|
|
51
|
-
majorIssues: number;
|
|
52
|
-
};
|
|
53
|
-
results: AnalysisResult[];
|
|
54
|
-
metrics: {
|
|
55
|
-
overallScore: number;
|
|
56
|
-
tokenCostTotal: number;
|
|
57
|
-
avgConsistency: number;
|
|
58
|
-
};
|
|
59
|
-
}
|
package/src/utils/ast-parser.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Placeholder for AST parsing utilities
|
|
2
|
-
// Will be implemented with specific parsers (TypeScript, Babel, etc.)
|
|
3
|
-
|
|
4
|
-
export interface ASTNode {
|
|
5
|
-
type: string;
|
|
6
|
-
loc?: {
|
|
7
|
-
start: { line: number; column: number };
|
|
8
|
-
end: { line: number; column: number };
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function parseCode(code: string, language: string): ASTNode | null {
|
|
13
|
-
// TODO: Implement language-specific parsing
|
|
14
|
-
// TypeScript: @typescript-eslint/parser
|
|
15
|
-
// JavaScript: @babel/parser
|
|
16
|
-
// Python: tree-sitter-python
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function extractFunctions(ast: ASTNode): ASTNode[] {
|
|
21
|
-
// TODO: Extract function declarations
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function extractImports(ast: ASTNode): string[] {
|
|
26
|
-
// TODO: Extract import statements
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { glob } from 'glob';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
|
-
import { ScanOptions } from '../types';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_EXCLUDE = [
|
|
6
|
-
'**/node_modules/**',
|
|
7
|
-
'**/dist/**',
|
|
8
|
-
'**/build/**',
|
|
9
|
-
'**/.git/**',
|
|
10
|
-
'**/coverage/**',
|
|
11
|
-
'**/*.min.js',
|
|
12
|
-
'**/*.bundle.js',
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
export async function scanFiles(options: ScanOptions): Promise<string[]> {
|
|
16
|
-
const {
|
|
17
|
-
rootDir,
|
|
18
|
-
include = ['**/*.{ts,tsx,js,jsx,py,java}'],
|
|
19
|
-
exclude = DEFAULT_EXCLUDE,
|
|
20
|
-
} = options;
|
|
21
|
-
|
|
22
|
-
const files = await glob(include, {
|
|
23
|
-
cwd: rootDir,
|
|
24
|
-
ignore: exclude,
|
|
25
|
-
absolute: true,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return files;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function readFileContent(filePath: string): Promise<string> {
|
|
32
|
-
return readFile(filePath, 'utf-8');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function getFileExtension(filePath: string): string {
|
|
36
|
-
return filePath.split('.').pop() || '';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function isSourceFile(filePath: string): boolean {
|
|
40
|
-
const ext = getFileExtension(filePath);
|
|
41
|
-
return ['ts', 'tsx', 'js', 'jsx', 'py', 'java', 'go', 'rs'].includes(ext);
|
|
42
|
-
}
|
package/src/utils/metrics.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Estimate token count for text (rough approximation)
|
|
3
|
-
* ~1 token ≈ 4 characters for code
|
|
4
|
-
*/
|
|
5
|
-
export function estimateTokens(text: string): number {
|
|
6
|
-
return Math.ceil(text.length / 4);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Calculate Levenshtein distance between two strings
|
|
11
|
-
* Useful for similarity detection
|
|
12
|
-
*/
|
|
13
|
-
export function levenshteinDistance(str1: string, str2: string): number {
|
|
14
|
-
const len1 = str1.length;
|
|
15
|
-
const len2 = str2.length;
|
|
16
|
-
const matrix: number[][] = [];
|
|
17
|
-
|
|
18
|
-
for (let i = 0; i <= len1; i++) {
|
|
19
|
-
matrix[i] = [i];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
for (let j = 0; j <= len2; j++) {
|
|
23
|
-
matrix[0][j] = j;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
for (let i = 1; i <= len1; i++) {
|
|
27
|
-
for (let j = 1; j <= len2; j++) {
|
|
28
|
-
const cost = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
|
29
|
-
matrix[i][j] = Math.min(
|
|
30
|
-
matrix[i - 1][j] + 1,
|
|
31
|
-
matrix[i][j - 1] + 1,
|
|
32
|
-
matrix[i - 1][j - 1] + cost
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return matrix[len1][len2];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Calculate similarity score (0-1) between two strings
|
|
42
|
-
*/
|
|
43
|
-
export function similarityScore(str1: string, str2: string): number {
|
|
44
|
-
const distance = levenshteinDistance(str1, str2);
|
|
45
|
-
const maxLength = Math.max(str1.length, str2.length);
|
|
46
|
-
return maxLength === 0 ? 1 : 1 - distance / maxLength;
|
|
47
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"rootDir": "./src",
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"resolveJsonModule": true
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules", "dist"]
|
|
20
|
-
}
|