dev-doc 0.1.0
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 +152 -0
- package/dist/analyzer.d.ts +59 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +285 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/cache.d.ts +51 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +143 -0
- package/dist/cache.js.map +1 -0
- package/dist/chunker.d.ts +18 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +56 -0
- package/dist/chunker.js.map +1 -0
- package/dist/claude.d.ts +39 -0
- package/dist/claude.d.ts.map +1 -0
- package/dist/claude.js +179 -0
- package/dist/claude.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +149 -0
- package/dist/cli.js.map +1 -0
- package/dist/mongodb.d.ts +78 -0
- package/dist/mongodb.d.ts.map +1 -0
- package/dist/mongodb.js +197 -0
- package/dist/mongodb.js.map +1 -0
- package/dist/scanner.d.ts +12 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +60 -0
- package/dist/scanner.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# dev-doc
|
|
2
|
+
|
|
3
|
+
AI-powered codebase analyzer using Claude AI to generate comprehensive documentation and insights about your codebase.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔍 **Smart File Scanning**: Automatically discovers and reads source files from your codebase
|
|
8
|
+
- 📦 **Intelligent Chunking**: Splits large files into manageable chunks for optimal AI processing
|
|
9
|
+
- 🤖 **Claude AI Integration**: Leverages Claude AI for deep code analysis
|
|
10
|
+
- 📊 **Multi-Level Analysis**: Provides both file-level and project-level insights
|
|
11
|
+
- 🎯 **Framework Detection**: Automatically identifies your technology stack
|
|
12
|
+
- 📝 **Structured Output**: Generates Markdown or JSON documentation
|
|
13
|
+
- ⚙️ **Highly Configurable**: Customize ignored directories, file extensions, and more
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g dev-doc
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or use it directly with npx:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx dev-doc ./src
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dev-doc ./src
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### With Options
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
dev-doc ./src \
|
|
39
|
+
--model claude-3-5-sonnet-20241022 \
|
|
40
|
+
--format markdown \
|
|
41
|
+
--ignore test,dist,node_modules \
|
|
42
|
+
--output docs/analysis.md
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### CLI Options
|
|
46
|
+
|
|
47
|
+
- `-k, --api-key <key>`: Claude API key (defaults to env `CLAUDE_API_KEY` or built-in default)
|
|
48
|
+
- `-m, --model <model>`: Claude model to use (default: `claude-3-5-sonnet-20241022`)
|
|
49
|
+
- `-f, --format <format>`: Output format: `markdown` or `json` (default: `markdown`)
|
|
50
|
+
- `-o, --output <file>`: Output file path (default: stdout)
|
|
51
|
+
- `--ignore <dirs>`: Comma-separated directories to ignore (default: `node_modules,.git,dist,build,.next`)
|
|
52
|
+
- `--extensions <exts>`: Comma-separated file extensions (default: `ts,js,tsx,jsx,json,md`)
|
|
53
|
+
- `--max-chars <number>`: Maximum characters per chunk (default: `12000`)
|
|
54
|
+
- `--max-tokens <number>`: Maximum tokens per API request (default: `800`)
|
|
55
|
+
|
|
56
|
+
## Environment Variables
|
|
57
|
+
|
|
58
|
+
Set your Claude API key:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
export CLAUDE_API_KEY="your-api-key-here"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Examples
|
|
65
|
+
|
|
66
|
+
### Analyze Current Directory
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
dev-doc .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Generate JSON Output
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
dev-doc ./src --format json --output analysis.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Custom Configuration
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
dev-doc ./backend \
|
|
82
|
+
--ignore node_modules,dist,tests \
|
|
83
|
+
--extensions ts,js,json \
|
|
84
|
+
--max-chars 10000 \
|
|
85
|
+
--output backend-analysis.md
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Output Format
|
|
89
|
+
|
|
90
|
+
### Markdown Format
|
|
91
|
+
|
|
92
|
+
The Markdown output includes:
|
|
93
|
+
- **Statistics**: Total files and chunks analyzed
|
|
94
|
+
- **Technology Stack**: Detected frameworks and libraries
|
|
95
|
+
- **Project Summary**: High-level architecture and insights
|
|
96
|
+
- **File-by-File Analysis**: Detailed analysis for each file
|
|
97
|
+
|
|
98
|
+
### JSON Format
|
|
99
|
+
|
|
100
|
+
The JSON output contains structured data:
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"summary": "...",
|
|
104
|
+
"framework": "...",
|
|
105
|
+
"fileAnalyses": [...],
|
|
106
|
+
"stats": {
|
|
107
|
+
"totalFiles": 10,
|
|
108
|
+
"totalChunks": 15
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## How It Works
|
|
114
|
+
|
|
115
|
+
1. **File Scanning**: Recursively scans the target directory for source files
|
|
116
|
+
2. **Change Detection**: Compares file hashes with cache to identify changed files
|
|
117
|
+
3. **Caching**: Uses cached results for unchanged files (dramatically faster on subsequent runs)
|
|
118
|
+
4. **Parallel Processing**: Analyzes multiple files concurrently (3 by default)
|
|
119
|
+
5. **Chunking**: Large files are split into manageable chunks (default: 12,000 chars)
|
|
120
|
+
6. **AI Analysis**: Each chunk is sent to Claude AI for analysis
|
|
121
|
+
7. **Summarization**: Project-level summary is generated from all file analyses
|
|
122
|
+
8. **Output**: Results are formatted as Markdown or JSON
|
|
123
|
+
|
|
124
|
+
## Performance
|
|
125
|
+
|
|
126
|
+
The analyzer is optimized for large codebases:
|
|
127
|
+
- **Caching**: Only analyzes changed files on subsequent runs (up to **360x faster**)
|
|
128
|
+
- **Parallel Processing**: Processes multiple files simultaneously
|
|
129
|
+
- **Incremental Updates**: Updates only changed sections
|
|
130
|
+
|
|
131
|
+
See [PERFORMANCE.md](./PERFORMANCE.md) for detailed performance benchmarks and optimization tips.
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Install dependencies
|
|
137
|
+
npm install
|
|
138
|
+
|
|
139
|
+
# Build
|
|
140
|
+
npm run build
|
|
141
|
+
|
|
142
|
+
# Run locally
|
|
143
|
+
npm run dev ./src
|
|
144
|
+
|
|
145
|
+
# Or use ts-node directly
|
|
146
|
+
npx ts-node src/cli.ts ./src
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT
|
|
152
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface AnalysisOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
model?: string;
|
|
4
|
+
maxTokens?: number;
|
|
5
|
+
maxCharsPerChunk?: number;
|
|
6
|
+
ignoreDirs?: string[];
|
|
7
|
+
fileExtensions?: string[];
|
|
8
|
+
outputFormat?: "markdown" | "json";
|
|
9
|
+
useCache?: boolean;
|
|
10
|
+
parallelRequests?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface FileAnalysis {
|
|
13
|
+
path: string;
|
|
14
|
+
relativePath: string;
|
|
15
|
+
analysis: string;
|
|
16
|
+
chunks: number;
|
|
17
|
+
fromCache?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ProjectAnalysis {
|
|
20
|
+
summary: string;
|
|
21
|
+
framework?: string;
|
|
22
|
+
fileAnalyses: FileAnalysis[];
|
|
23
|
+
stats: {
|
|
24
|
+
totalFiles: number;
|
|
25
|
+
totalChunks: number;
|
|
26
|
+
cachedFiles: number;
|
|
27
|
+
analyzedFiles: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Main analyzer class that coordinates scanning, chunking, and AI analysis
|
|
32
|
+
*/
|
|
33
|
+
export declare class CodebaseAnalyzer {
|
|
34
|
+
private claude;
|
|
35
|
+
private options;
|
|
36
|
+
private cache;
|
|
37
|
+
constructor(options: AnalysisOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Analyzes a single file (with caching support)
|
|
40
|
+
*/
|
|
41
|
+
private analyzeFile;
|
|
42
|
+
/**
|
|
43
|
+
* Analyzes files in parallel batches
|
|
44
|
+
*/
|
|
45
|
+
private analyzeFilesParallel;
|
|
46
|
+
/**
|
|
47
|
+
* Analyzes the entire codebase
|
|
48
|
+
*/
|
|
49
|
+
analyze(directory: string): Promise<ProjectAnalysis>;
|
|
50
|
+
/**
|
|
51
|
+
* Formats analysis result as markdown (incremental updates supported)
|
|
52
|
+
*/
|
|
53
|
+
formatMarkdown(analysis: ProjectAnalysis, existingMarkdown?: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Formats analysis result as JSON
|
|
56
|
+
*/
|
|
57
|
+
formatJSON(analysis: ProjectAnalysis): string;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAA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
package/dist/analyzer.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodebaseAnalyzer = void 0;
|
|
4
|
+
const scanner_1 = require("./scanner");
|
|
5
|
+
const chunker_1 = require("./chunker");
|
|
6
|
+
const claude_1 = require("./claude");
|
|
7
|
+
const cache_1 = require("./cache");
|
|
8
|
+
/**
|
|
9
|
+
* Main analyzer class that coordinates scanning, chunking, and AI analysis
|
|
10
|
+
*/
|
|
11
|
+
class CodebaseAnalyzer {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.cache = null;
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.claude = new claude_1.ClaudeClient({
|
|
16
|
+
apiKey: options.apiKey,
|
|
17
|
+
model: options.model,
|
|
18
|
+
maxTokens: options.maxTokens,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Analyzes a single file (with caching support)
|
|
23
|
+
*/
|
|
24
|
+
async analyzeFile(file, framework, index, total) {
|
|
25
|
+
const progress = `[${index + 1}/${total}]`;
|
|
26
|
+
const fileHash = (0, cache_1.calculateFileHash)(file.content);
|
|
27
|
+
// Check cache first
|
|
28
|
+
if (this.options.useCache !== false) {
|
|
29
|
+
const cached = (0, cache_1.getCachedAnalysis)(file.relativePath, this.cache);
|
|
30
|
+
if (cached && !(0, cache_1.hasFileChanged)(file.relativePath, fileHash, this.cache)) {
|
|
31
|
+
console.log(`${progress} ✓ Cached: ${file.relativePath}`);
|
|
32
|
+
return {
|
|
33
|
+
path: file.path,
|
|
34
|
+
relativePath: file.relativePath,
|
|
35
|
+
analysis: cached.analysis,
|
|
36
|
+
chunks: cached.chunks,
|
|
37
|
+
fromCache: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
console.log(`${progress} Analyzing: ${file.relativePath}`);
|
|
42
|
+
try {
|
|
43
|
+
const chunks = (0, chunker_1.chunkFile)(file.relativePath, file.content, {
|
|
44
|
+
maxChars: this.options.maxCharsPerChunk,
|
|
45
|
+
});
|
|
46
|
+
// Analyze each chunk sequentially
|
|
47
|
+
const chunkAnalyses = [];
|
|
48
|
+
for (const chunkInfo of chunks) {
|
|
49
|
+
const chunkOptions = {
|
|
50
|
+
filePath: file.relativePath,
|
|
51
|
+
chunk: chunkInfo.chunk,
|
|
52
|
+
chunkIndex: chunkInfo.index,
|
|
53
|
+
totalChunks: chunkInfo.total,
|
|
54
|
+
projectContext: framework,
|
|
55
|
+
};
|
|
56
|
+
const analysis = await this.claude.analyzeChunk(chunkOptions);
|
|
57
|
+
chunkAnalyses.push(analysis);
|
|
58
|
+
}
|
|
59
|
+
// Combine chunk analyses for this file
|
|
60
|
+
const fileAnalysis = chunkAnalyses.length > 1
|
|
61
|
+
? chunkAnalyses.map((a, idx) => `### Chunk ${idx + 1}/${chunkAnalyses.length}\n\n${a}`).join("\n\n")
|
|
62
|
+
: chunkAnalyses[0];
|
|
63
|
+
const result = {
|
|
64
|
+
path: file.path,
|
|
65
|
+
relativePath: file.relativePath,
|
|
66
|
+
analysis: fileAnalysis,
|
|
67
|
+
chunks: chunks.length,
|
|
68
|
+
fromCache: false,
|
|
69
|
+
};
|
|
70
|
+
// Update cache
|
|
71
|
+
if (this.options.useCache !== false && this.cache) {
|
|
72
|
+
(0, cache_1.updateCacheEntry)(this.cache, file.relativePath, fileHash, fileAnalysis, chunks.length);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(`✗ Error analyzing ${file.relativePath}:`, error instanceof Error ? error.message : error);
|
|
78
|
+
return {
|
|
79
|
+
path: file.path,
|
|
80
|
+
relativePath: file.relativePath,
|
|
81
|
+
analysis: `Error: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
82
|
+
chunks: 0,
|
|
83
|
+
fromCache: false,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Analyzes files in parallel batches
|
|
89
|
+
*/
|
|
90
|
+
async analyzeFilesParallel(files, framework, batchSize = 3) {
|
|
91
|
+
const results = [];
|
|
92
|
+
// Process files in batches
|
|
93
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
94
|
+
const batch = files.slice(i, i + batchSize);
|
|
95
|
+
// Analyze batch in parallel
|
|
96
|
+
const batchPromises = batch.map((file, batchIndex) => this.analyzeFile(file, framework, i + batchIndex + 1, files.length));
|
|
97
|
+
const batchResults = await Promise.all(batchPromises);
|
|
98
|
+
results.push(...batchResults);
|
|
99
|
+
// Small delay between batches to avoid rate limits
|
|
100
|
+
if (i + batchSize < files.length) {
|
|
101
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Analyzes the entire codebase
|
|
108
|
+
*/
|
|
109
|
+
async analyze(directory) {
|
|
110
|
+
console.log(`📂 Scanning codebase: ${directory}`);
|
|
111
|
+
// Load cache if enabled
|
|
112
|
+
if (this.options.useCache !== false) {
|
|
113
|
+
this.cache = (0, cache_1.loadCache)(directory) || (0, cache_1.createCache)(directory);
|
|
114
|
+
console.log(`💾 Cache ${this.cache ? 'loaded' : 'created'}`);
|
|
115
|
+
}
|
|
116
|
+
// Step 1: Scan files
|
|
117
|
+
const files = (0, scanner_1.readCodebase)(directory, {
|
|
118
|
+
ignoreDirs: this.options.ignoreDirs,
|
|
119
|
+
fileExtensions: this.options.fileExtensions,
|
|
120
|
+
});
|
|
121
|
+
console.log(`📄 Found ${files.length} files to analyze`);
|
|
122
|
+
if (files.length === 0) {
|
|
123
|
+
throw new Error("No files found to analyze");
|
|
124
|
+
}
|
|
125
|
+
// Clean cache of removed files
|
|
126
|
+
if (this.cache) {
|
|
127
|
+
(0, cache_1.cleanCache)(this.cache, files.map(f => f.relativePath));
|
|
128
|
+
}
|
|
129
|
+
// Check how many files need analysis
|
|
130
|
+
const filesToAnalyze = [];
|
|
131
|
+
let cachedCount = 0;
|
|
132
|
+
for (const file of files) {
|
|
133
|
+
const hash = (0, cache_1.calculateFileHash)(file.content);
|
|
134
|
+
if ((0, cache_1.hasFileChanged)(file.relativePath, hash, this.cache)) {
|
|
135
|
+
filesToAnalyze.push(file);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
cachedCount++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
console.log(`📊 ${cachedCount} files cached, ${filesToAnalyze.length} files need analysis`);
|
|
142
|
+
// Step 2: Detect framework early (for context) - only if we have files to analyze
|
|
143
|
+
let framework;
|
|
144
|
+
if (filesToAnalyze.length > 0 || !this.cache?.framework) {
|
|
145
|
+
try {
|
|
146
|
+
console.log("🔍 Detecting technology stack...");
|
|
147
|
+
framework = await this.claude.detectFramework(files.slice(0, 10).map(f => ({ path: f.relativePath, content: f.content.slice(0, 500) })));
|
|
148
|
+
console.log("✓ Framework detected");
|
|
149
|
+
if (this.cache) {
|
|
150
|
+
this.cache.framework = framework;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.warn("⚠ Could not detect framework");
|
|
155
|
+
framework = this.cache?.framework;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
framework = this.cache.framework;
|
|
160
|
+
console.log(`✓ Using cached framework detection`);
|
|
161
|
+
}
|
|
162
|
+
// Step 3: Analyze files (parallel or sequential)
|
|
163
|
+
const parallelRequests = this.options.parallelRequests || 3;
|
|
164
|
+
let fileAnalyses;
|
|
165
|
+
if (filesToAnalyze.length > 0) {
|
|
166
|
+
// Analyze new/changed files in parallel batches
|
|
167
|
+
fileAnalyses = await this.analyzeFilesParallel(filesToAnalyze, framework, parallelRequests);
|
|
168
|
+
// Add cached files
|
|
169
|
+
for (const file of files) {
|
|
170
|
+
const hash = (0, cache_1.calculateFileHash)(file.content);
|
|
171
|
+
if (!(0, cache_1.hasFileChanged)(file.relativePath, hash, this.cache)) {
|
|
172
|
+
const cached = (0, cache_1.getCachedAnalysis)(file.relativePath, this.cache);
|
|
173
|
+
if (cached) {
|
|
174
|
+
fileAnalyses.push({
|
|
175
|
+
path: file.path,
|
|
176
|
+
relativePath: file.relativePath,
|
|
177
|
+
analysis: cached.analysis,
|
|
178
|
+
chunks: cached.chunks,
|
|
179
|
+
fromCache: true,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Sort to maintain consistent order
|
|
185
|
+
fileAnalyses.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// All files are cached
|
|
189
|
+
fileAnalyses = files.map(file => {
|
|
190
|
+
const cached = (0, cache_1.getCachedAnalysis)(file.relativePath, this.cache);
|
|
191
|
+
return {
|
|
192
|
+
path: file.path,
|
|
193
|
+
relativePath: file.relativePath,
|
|
194
|
+
analysis: cached.analysis,
|
|
195
|
+
chunks: cached.chunks,
|
|
196
|
+
fromCache: true,
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// Step 4: Generate project summary (only if files changed or summary not cached)
|
|
201
|
+
let summary;
|
|
202
|
+
const needsNewSummary = filesToAnalyze.length > 0 ||
|
|
203
|
+
!this.cache?.summary ||
|
|
204
|
+
(Date.now() - (this.cache?.lastUpdated || 0)) > 86400000; // 24 hours
|
|
205
|
+
if (needsNewSummary) {
|
|
206
|
+
console.log("📊 Generating project summary...");
|
|
207
|
+
const summaryOptions = {
|
|
208
|
+
analyses: fileAnalyses.map(f => f.analysis),
|
|
209
|
+
filePaths: fileAnalyses.map(f => f.relativePath),
|
|
210
|
+
projectContext: framework,
|
|
211
|
+
};
|
|
212
|
+
summary = await this.claude.summarizeProject(summaryOptions);
|
|
213
|
+
if (this.cache) {
|
|
214
|
+
this.cache.summary = summary;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
summary = this.cache.summary;
|
|
219
|
+
console.log("✓ Using cached project summary");
|
|
220
|
+
}
|
|
221
|
+
// Save cache
|
|
222
|
+
if (this.options.useCache !== false && this.cache) {
|
|
223
|
+
(0, cache_1.saveCache)(directory, this.cache);
|
|
224
|
+
console.log("💾 Cache saved");
|
|
225
|
+
}
|
|
226
|
+
const totalChunks = fileAnalyses.reduce((sum, f) => sum + f.chunks, 0);
|
|
227
|
+
const analyzedFiles = fileAnalyses.filter(f => !f.fromCache).length;
|
|
228
|
+
return {
|
|
229
|
+
summary,
|
|
230
|
+
framework,
|
|
231
|
+
fileAnalyses,
|
|
232
|
+
stats: {
|
|
233
|
+
totalFiles: files.length,
|
|
234
|
+
totalChunks,
|
|
235
|
+
cachedFiles: cachedCount,
|
|
236
|
+
analyzedFiles,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Formats analysis result as markdown (incremental updates supported)
|
|
242
|
+
*/
|
|
243
|
+
formatMarkdown(analysis, existingMarkdown) {
|
|
244
|
+
const { summary, framework, fileAnalyses, stats } = analysis;
|
|
245
|
+
// If we have existing markdown and mostly cached files, try incremental update
|
|
246
|
+
if (existingMarkdown && stats.cachedFiles > stats.analyzedFiles) {
|
|
247
|
+
// For now, full rewrite - could be optimized further
|
|
248
|
+
return this.formatMarkdown(analysis);
|
|
249
|
+
}
|
|
250
|
+
let markdown = `# Codebase Analysis\n\n`;
|
|
251
|
+
markdown += `**Generated:** ${new Date().toISOString()}\n\n`;
|
|
252
|
+
markdown += `**Statistics:**\n`;
|
|
253
|
+
markdown += `- Total Files: ${stats.totalFiles}\n`;
|
|
254
|
+
markdown += `- Files Analyzed: ${stats.analyzedFiles}\n`;
|
|
255
|
+
markdown += `- Files from Cache: ${stats.cachedFiles}\n`;
|
|
256
|
+
markdown += `- Total Chunks Analyzed: ${stats.totalChunks}\n\n`;
|
|
257
|
+
if (framework) {
|
|
258
|
+
markdown += `## Technology Stack\n\n${framework}\n\n`;
|
|
259
|
+
}
|
|
260
|
+
markdown += `## Project Summary & API Documentation\n\n${summary}\n\n`;
|
|
261
|
+
// Extract and highlight API endpoints section if present
|
|
262
|
+
if (summary.includes("API") || summary.includes("endpoint") || summary.includes("POST") || summary.includes("GET")) {
|
|
263
|
+
markdown += `---\n\n`;
|
|
264
|
+
}
|
|
265
|
+
markdown += `## File-by-File Analysis\n\n`;
|
|
266
|
+
for (const file of fileAnalyses) {
|
|
267
|
+
const cacheBadge = file.fromCache ? ` <small>(from cache)</small>` : "";
|
|
268
|
+
markdown += `### ${file.relativePath}${cacheBadge}\n\n`;
|
|
269
|
+
if (file.chunks > 1) {
|
|
270
|
+
markdown += `*Analyzed in ${file.chunks} chunks*\n\n`;
|
|
271
|
+
}
|
|
272
|
+
markdown += `${file.analysis}\n\n`;
|
|
273
|
+
markdown += `---\n\n`;
|
|
274
|
+
}
|
|
275
|
+
return markdown;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Formats analysis result as JSON
|
|
279
|
+
*/
|
|
280
|
+
formatJSON(analysis) {
|
|
281
|
+
return JSON.stringify(analysis, null, 2);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.CodebaseAnalyzer = CodebaseAnalyzer;
|
|
285
|
+
//# sourceMappingURL=analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":";;;AAAA,uCAAqD;AACrD,uCAAsC;AACtC,qCAA6E;AAC7E,mCAUiB;AAkCjB;;GAEG;AACH,MAAa,gBAAgB;IAK3B,YAAY,OAAwB;QAF5B,UAAK,GAAqB,IAAI,CAAC;QAGrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC;YAC7B,M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B,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,QAAyB;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF;AA3UD,4CA2UC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface CacheEntry {
|
|
2
|
+
relativePath: string;
|
|
3
|
+
hash: string;
|
|
4
|
+
analysis: string;
|
|
5
|
+
chunks: number;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CacheData {
|
|
9
|
+
version: string;
|
|
10
|
+
directory: string;
|
|
11
|
+
entries: Record<string, CacheEntry>;
|
|
12
|
+
summary?: string;
|
|
13
|
+
framework?: string;
|
|
14
|
+
lastUpdated: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Calculates MD5 hash of file content
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateFileHash(content: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Loads cache from disk
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadCache(directory: string): CacheData | null;
|
|
24
|
+
/**
|
|
25
|
+
* Saves cache to disk
|
|
26
|
+
*/
|
|
27
|
+
export declare function saveCache(directory: string, cache: CacheData): void;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a file has changed by comparing hash
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasFileChanged(relativePath: string, currentHash: string, cache: CacheData | null): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Gets cached analysis for a file
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCachedAnalysis(relativePath: string, cache: CacheData | null): {
|
|
36
|
+
analysis: string;
|
|
37
|
+
chunks: number;
|
|
38
|
+
} | null;
|
|
39
|
+
/**
|
|
40
|
+
* Updates cache with new analysis
|
|
41
|
+
*/
|
|
42
|
+
export declare function updateCacheEntry(cache: CacheData, relativePath: string, hash: string, analysis: string, chunks: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new cache instance
|
|
45
|
+
*/
|
|
46
|
+
export declare function createCache(directory: string): CacheData;
|
|
47
|
+
/**
|
|
48
|
+
* Removes old cache entries for files that no longer exist
|
|
49
|
+
*/
|
|
50
|
+
export declare function cleanCache(cache: CacheData, existingFiles: string[]): void;
|
|
51
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAID;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAoBD;;GAEG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAwB7D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAOnE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,OAAO,CAOT;AAED;;GAEG;AACH,wBAA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