@ridit/lens 0.3.3 → 0.3.4
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/LENS.md +41 -0
- package/README.md +2 -2
- package/dist/index.mjs +3919 -3587
- package/package.json +1 -2
- package/src/components/repo/LensFileMenu.tsx +2 -9
- package/src/components/repo/RepoAnalysis.tsx +241 -50
- package/src/types/repo.ts +15 -3
- package/src/utils/ai.ts +108 -20
- package/src/utils/lensfile.ts +83 -18
package/src/utils/lensfile.ts
CHANGED
|
@@ -7,10 +7,13 @@ export const LENS_FILENAME = "LENS.md";
|
|
|
7
7
|
export type LensFile = {
|
|
8
8
|
overview: string;
|
|
9
9
|
importantFolders: string[];
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
tooling: Record<string, string>;
|
|
11
|
+
keyFiles: string[];
|
|
12
|
+
patterns: string[];
|
|
13
|
+
architecture: string;
|
|
12
14
|
suggestions: string[];
|
|
13
15
|
generatedAt: string;
|
|
16
|
+
lastUpdated: string;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export function lensFilePath(repoPath: string): string {
|
|
@@ -21,36 +24,96 @@ export function lensFileExists(repoPath: string): boolean {
|
|
|
21
24
|
return existsSync(lensFilePath(repoPath));
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
27
|
+
function renderLensFile(data: LensFile): string {
|
|
28
|
+
const toolingLines = Object.entries(data.tooling)
|
|
29
|
+
.map(([k, v]) => `- **${k}**: ${v}`)
|
|
30
|
+
.join("\n");
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
> Generated: ${data.generatedAt}
|
|
32
|
+
return `# Lens
|
|
33
|
+
> Generated: ${data.generatedAt}${data.lastUpdated !== data.generatedAt ? ` | Updated: ${data.lastUpdated}` : ""}
|
|
32
34
|
|
|
33
35
|
## Overview
|
|
34
36
|
${data.overview}
|
|
35
37
|
|
|
38
|
+
## Architecture
|
|
39
|
+
${data.architecture}
|
|
40
|
+
|
|
41
|
+
## Tooling & Conventions
|
|
42
|
+
${toolingLines || "- Not yet determined"}
|
|
43
|
+
|
|
36
44
|
## Important Folders
|
|
37
|
-
${data.importantFolders.map((f) => `- ${f}`).join("\n")}
|
|
45
|
+
${data.importantFolders.map((f) => `- ${f}`).join("\n") || "- None"}
|
|
38
46
|
|
|
39
|
-
##
|
|
40
|
-
${data.
|
|
47
|
+
## Key Files
|
|
48
|
+
${data.keyFiles.map((f) => `- ${f}`).join("\n") || "- None"}
|
|
41
49
|
|
|
42
|
-
##
|
|
43
|
-
${data.
|
|
50
|
+
## Patterns & Idioms
|
|
51
|
+
${data.patterns.map((p) => `- ${p}`).join("\n") || "- None"}
|
|
44
52
|
|
|
45
53
|
## Suggestions
|
|
46
|
-
${data.suggestions.map((s) => `- ${s}`).join("\n")}
|
|
54
|
+
${data.suggestions.map((s) => `- ${s}`).join("\n") || "- None"}
|
|
47
55
|
|
|
48
56
|
<!--lens-json
|
|
49
57
|
${JSON.stringify(data)}
|
|
50
58
|
lens-json-->
|
|
51
59
|
`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function writeLensFile(repoPath: string, result: AnalysisResult): void {
|
|
63
|
+
const now = new Date().toISOString();
|
|
64
|
+
const data: LensFile = {
|
|
65
|
+
overview: result.overview,
|
|
66
|
+
importantFolders: result.importantFolders,
|
|
67
|
+
tooling: result.tooling ?? {},
|
|
68
|
+
keyFiles: result.keyFiles ?? [],
|
|
69
|
+
patterns: result.patterns ?? [],
|
|
70
|
+
architecture: result.architecture ?? "",
|
|
71
|
+
suggestions: result.suggestions,
|
|
72
|
+
generatedAt: now,
|
|
73
|
+
lastUpdated: now,
|
|
74
|
+
};
|
|
75
|
+
writeFileSync(lensFilePath(repoPath), renderLensFile(data), "utf-8");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function patchLensFile(
|
|
79
|
+
repoPath: string,
|
|
80
|
+
patch: Partial<AnalysisResult>,
|
|
81
|
+
): void {
|
|
82
|
+
const existing = readLensFile(repoPath);
|
|
83
|
+
const now = new Date().toISOString();
|
|
84
|
+
|
|
85
|
+
const base: LensFile = existing ?? {
|
|
86
|
+
overview: "",
|
|
87
|
+
importantFolders: [],
|
|
88
|
+
tooling: {},
|
|
89
|
+
keyFiles: [],
|
|
90
|
+
patterns: [],
|
|
91
|
+
architecture: "",
|
|
92
|
+
suggestions: [],
|
|
93
|
+
generatedAt: now,
|
|
94
|
+
lastUpdated: now,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const merged: LensFile = {
|
|
98
|
+
...base,
|
|
99
|
+
lastUpdated: now,
|
|
100
|
+
overview: patch.overview ?? base.overview,
|
|
101
|
+
architecture: patch.architecture ?? base.architecture,
|
|
102
|
+
tooling: { ...base.tooling, ...(patch.tooling ?? {}) },
|
|
103
|
+
importantFolders: dedup([
|
|
104
|
+
...base.importantFolders,
|
|
105
|
+
...(patch.importantFolders ?? []),
|
|
106
|
+
]),
|
|
107
|
+
keyFiles: dedup([...base.keyFiles, ...(patch.keyFiles ?? [])]),
|
|
108
|
+
patterns: dedup([...base.patterns, ...(patch.patterns ?? [])]),
|
|
109
|
+
suggestions: dedup([...base.suggestions, ...(patch.suggestions ?? [])]),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
writeFileSync(lensFilePath(repoPath), renderLensFile(merged), "utf-8");
|
|
113
|
+
}
|
|
52
114
|
|
|
53
|
-
|
|
115
|
+
function dedup(arr: string[]): string[] {
|
|
116
|
+
return [...new Map(arr.map((s) => [s.trim().toLowerCase(), s])).values()];
|
|
54
117
|
}
|
|
55
118
|
|
|
56
119
|
export function readLensFile(repoPath: string): LensFile | null {
|
|
@@ -70,8 +133,10 @@ export function lensFileToAnalysisResult(lf: LensFile): AnalysisResult {
|
|
|
70
133
|
return {
|
|
71
134
|
overview: lf.overview,
|
|
72
135
|
importantFolders: lf.importantFolders,
|
|
73
|
-
|
|
74
|
-
|
|
136
|
+
tooling: lf.tooling,
|
|
137
|
+
keyFiles: lf.keyFiles,
|
|
138
|
+
patterns: lf.patterns,
|
|
139
|
+
architecture: lf.architecture,
|
|
75
140
|
suggestions: lf.suggestions,
|
|
76
141
|
};
|
|
77
142
|
}
|