rlm-analyzer 1.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 +226 -0
- package/dist/analyzer.d.ts +58 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +203 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +442 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +118 -0
- package/dist/config.js.map +1 -0
- package/dist/executor.d.ts +71 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +315 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +19 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +336 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/models.d.ts +101 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +202 -0
- package/dist/models.js.map +1 -0
- package/dist/orchestrator.d.ts +61 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +325 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/prompts.d.ts +48 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +220 -0
- package/dist/prompts.js.map +1 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +87 -0
- package/dist/types.js.map +1 -0
- package/package.json +77 -0
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# RLM Analyzer
|
|
2
|
+
|
|
3
|
+
**AI-powered code analysis using Recursive Language Models**
|
|
4
|
+
|
|
5
|
+
Analyze any codebase with AI that can process 100x beyond context limits. Powered by **Gemini 3 Flash** and based on MIT CSAIL research on [Recursive Language Models](https://arxiv.org/abs/2512.24601).
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🔍 **Deep Code Analysis** - Understands entire codebases, not just snippets
|
|
10
|
+
- 🏗️ **Architecture Analysis** - Maps structure, patterns, and data flow
|
|
11
|
+
- 🔒 **Security Scanning** - Identifies vulnerabilities and security patterns
|
|
12
|
+
- ⚡ **Performance Analysis** - Finds bottlenecks and optimization opportunities
|
|
13
|
+
- 🔄 **Refactoring Suggestions** - Identifies code smells and improvements
|
|
14
|
+
- 🔎 **Symbol Search** - Find all usages of functions, classes, variables
|
|
15
|
+
- ❓ **Custom Questions** - Ask anything about your codebase
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Global Installation (Recommended)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g rlm-analyzer
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Local Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install rlm-analyzer
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### 1. Configure API Key
|
|
34
|
+
|
|
35
|
+
Get a free API key from [Google AI Studio](https://makersuite.google.com/app/apikey), then:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Option 1: Use the config command
|
|
39
|
+
rlm config YOUR_GEMINI_API_KEY
|
|
40
|
+
|
|
41
|
+
# Option 2: Set environment variable
|
|
42
|
+
export GEMINI_API_KEY=your_api_key
|
|
43
|
+
|
|
44
|
+
# Option 3: Create .env file in your project
|
|
45
|
+
echo "GEMINI_API_KEY=your_api_key" > .env
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Analyze Your Code
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Get a codebase summary
|
|
52
|
+
rlm summary
|
|
53
|
+
|
|
54
|
+
# Analyze architecture
|
|
55
|
+
rlm arch
|
|
56
|
+
|
|
57
|
+
# Security analysis
|
|
58
|
+
rlm security
|
|
59
|
+
|
|
60
|
+
# Ask a question
|
|
61
|
+
rlm ask "How does authentication work?"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Commands
|
|
65
|
+
|
|
66
|
+
| Command | Description |
|
|
67
|
+
|---------|-------------|
|
|
68
|
+
| `rlm summary` | Get a comprehensive codebase summary |
|
|
69
|
+
| `rlm arch` | Analyze architecture and structure |
|
|
70
|
+
| `rlm deps` | Analyze dependencies and imports |
|
|
71
|
+
| `rlm security` | Security vulnerability analysis |
|
|
72
|
+
| `rlm perf` | Performance analysis |
|
|
73
|
+
| `rlm refactor` | Find refactoring opportunities |
|
|
74
|
+
| `rlm find <symbol>` | Find all usages of a symbol |
|
|
75
|
+
| `rlm explain <file>` | Explain a specific file |
|
|
76
|
+
| `rlm ask "<question>"` | Ask a custom question |
|
|
77
|
+
| `rlm config [key]` | Configure or check API key |
|
|
78
|
+
|
|
79
|
+
## Options
|
|
80
|
+
|
|
81
|
+
| Option | Description |
|
|
82
|
+
|--------|-------------|
|
|
83
|
+
| `--dir, -d <path>` | Directory to analyze (default: current) |
|
|
84
|
+
| `--verbose, -v` | Show detailed turn-by-turn output |
|
|
85
|
+
| `--json` | Output results as JSON |
|
|
86
|
+
| `--help, -h` | Show help |
|
|
87
|
+
|
|
88
|
+
## Examples
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Analyze a specific directory
|
|
92
|
+
rlm arch --dir /path/to/project
|
|
93
|
+
|
|
94
|
+
# Find all usages of a function
|
|
95
|
+
rlm find "handleSubmit"
|
|
96
|
+
|
|
97
|
+
# Explain a specific file
|
|
98
|
+
rlm explain src/auth/login.ts
|
|
99
|
+
|
|
100
|
+
# Ask about the codebase
|
|
101
|
+
rlm ask "What design patterns are used in this codebase?"
|
|
102
|
+
|
|
103
|
+
# Get JSON output for scripting
|
|
104
|
+
rlm summary --json > analysis.json
|
|
105
|
+
|
|
106
|
+
# Verbose mode for debugging
|
|
107
|
+
rlm security -v
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Programmatic Usage
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import {
|
|
114
|
+
analyzeArchitecture,
|
|
115
|
+
analyzeSecurity,
|
|
116
|
+
askQuestion,
|
|
117
|
+
loadFiles,
|
|
118
|
+
} from 'rlm-analyzer';
|
|
119
|
+
|
|
120
|
+
// Analyze architecture
|
|
121
|
+
const result = await analyzeArchitecture('/path/to/project');
|
|
122
|
+
console.log(result.answer);
|
|
123
|
+
|
|
124
|
+
// Ask a custom question
|
|
125
|
+
const answer = await askQuestion(
|
|
126
|
+
'/path/to/project',
|
|
127
|
+
'How does the authentication system work?'
|
|
128
|
+
);
|
|
129
|
+
console.log(answer.answer);
|
|
130
|
+
|
|
131
|
+
// Load and process files manually
|
|
132
|
+
const files = loadFiles('/path/to/project', {
|
|
133
|
+
include: ['.ts', '.tsx'],
|
|
134
|
+
exclude: ['node_modules', 'dist'],
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## How It Works
|
|
139
|
+
|
|
140
|
+
RLM Analyzer uses Recursive Language Models (RLMs) to analyze codebases that exceed traditional context limits:
|
|
141
|
+
|
|
142
|
+
1. **File Loading** - Loads your codebase into a virtual environment
|
|
143
|
+
2. **REPL Execution** - AI writes and executes Python-like code to explore files
|
|
144
|
+
3. **Sub-LLM Calls** - Complex analysis tasks are delegated to specialized sub-queries
|
|
145
|
+
4. **Iterative Refinement** - Multiple turns of analysis until complete
|
|
146
|
+
5. **Final Answer** - Synthesized analysis based on deep code exploration
|
|
147
|
+
|
|
148
|
+
This approach enables analysis of codebases 100x larger than traditional context windows.
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
### API Key Storage
|
|
153
|
+
|
|
154
|
+
Your API key can be stored in multiple locations (checked in order):
|
|
155
|
+
|
|
156
|
+
1. `GEMINI_API_KEY` environment variable
|
|
157
|
+
2. `RLM_API_KEY` environment variable
|
|
158
|
+
3. `.env` file in current directory
|
|
159
|
+
4. `.env.local` file in current directory
|
|
160
|
+
5. `~/.rlm-analyzer/config.json`
|
|
161
|
+
6. `~/.config/rlm-analyzer/config.json`
|
|
162
|
+
|
|
163
|
+
### Global Config File
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Create global config
|
|
167
|
+
mkdir -p ~/.rlm-analyzer
|
|
168
|
+
echo '{"apiKey": "your_api_key"}' > ~/.rlm-analyzer/config.json
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Supported Languages
|
|
172
|
+
|
|
173
|
+
- TypeScript / JavaScript
|
|
174
|
+
- Python
|
|
175
|
+
- Java / Kotlin / Scala
|
|
176
|
+
- Go
|
|
177
|
+
- Rust
|
|
178
|
+
- C / C++
|
|
179
|
+
- C#
|
|
180
|
+
- Ruby
|
|
181
|
+
- PHP
|
|
182
|
+
- Swift
|
|
183
|
+
- Vue / Svelte
|
|
184
|
+
- And more...
|
|
185
|
+
|
|
186
|
+
## Security
|
|
187
|
+
|
|
188
|
+
- API keys are never logged or transmitted except to the Gemini API
|
|
189
|
+
- Code execution happens in a sandboxed environment
|
|
190
|
+
- Dangerous operations (eval, file writes, network calls) are blocked
|
|
191
|
+
- All analysis is read-only
|
|
192
|
+
|
|
193
|
+
## Troubleshooting
|
|
194
|
+
|
|
195
|
+
### "API key not configured"
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Check if key is set
|
|
199
|
+
rlm config
|
|
200
|
+
|
|
201
|
+
# Set your key
|
|
202
|
+
rlm config YOUR_API_KEY
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### "No files found to analyze"
|
|
206
|
+
|
|
207
|
+
Make sure you're in a directory with code files, or specify a directory:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
rlm summary --dir /path/to/code
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Analysis is slow
|
|
214
|
+
|
|
215
|
+
- Large codebases take longer to analyze
|
|
216
|
+
- Use `--verbose` to see progress
|
|
217
|
+
- Consider analyzing specific subdirectories
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT
|
|
222
|
+
|
|
223
|
+
## Credits
|
|
224
|
+
|
|
225
|
+
Based on research from MIT CSAIL:
|
|
226
|
+
- [Recursive Language Models: A Paradigm for Processing Arbitrarily Long Inputs](https://arxiv.org/abs/2512.24601)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Analysis High-Level API
|
|
3
|
+
* Provides easy-to-use functions for common analysis tasks
|
|
4
|
+
*/
|
|
5
|
+
import type { CodeAnalysisOptions, CodeAnalysisResult } from './types.js';
|
|
6
|
+
/** Default maximum file size in bytes (100KB) */
|
|
7
|
+
export declare const DEFAULT_MAX_FILE_SIZE = 100000;
|
|
8
|
+
/** Default analysis type when not specified */
|
|
9
|
+
export declare const DEFAULT_ANALYSIS_TYPE: "summary";
|
|
10
|
+
/**
|
|
11
|
+
* Load files from a directory
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadFiles(directory: string, options?: {
|
|
14
|
+
include?: string[];
|
|
15
|
+
exclude?: string[];
|
|
16
|
+
maxFileSize?: number;
|
|
17
|
+
}): Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Analyze a codebase with custom query
|
|
20
|
+
*/
|
|
21
|
+
export declare function analyzeCodebase(options: CodeAnalysisOptions): Promise<CodeAnalysisResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Analyze architecture
|
|
24
|
+
*/
|
|
25
|
+
export declare function analyzeArchitecture(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Analyze dependencies
|
|
28
|
+
*/
|
|
29
|
+
export declare function analyzeDependencies(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Analyze security
|
|
32
|
+
*/
|
|
33
|
+
export declare function analyzeSecurity(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Analyze performance
|
|
36
|
+
*/
|
|
37
|
+
export declare function analyzePerformance(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Analyze refactoring opportunities
|
|
40
|
+
*/
|
|
41
|
+
export declare function analyzeRefactoring(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Get codebase summary
|
|
44
|
+
*/
|
|
45
|
+
export declare function summarizeCodebase(directory: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Find usages of a symbol
|
|
48
|
+
*/
|
|
49
|
+
export declare function findUsages(directory: string, symbolName: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Explain a specific file
|
|
52
|
+
*/
|
|
53
|
+
export declare function explainFile(filePath: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Ask a custom question about the codebase
|
|
56
|
+
*/
|
|
57
|
+
export declare function askQuestion(directory: string, question: string, options?: Partial<CodeAnalysisOptions>): Promise<CodeAnalysisResult>;
|
|
58
|
+
//# sourceMappingURL=analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAKpB,iDAAiD;AACjD,eAAO,MAAM,qBAAqB,SAAU,CAAC;AAE7C,+CAA+C;AAC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C,CAO7B;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM,GACzC,OAAO,CAAC,kBAAkB,CAAC,CAe7B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM,GACzC,OAAO,CAAC,kBAAkB,CAAC,CAiB7B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM,GACzC,OAAO,CAAC,kBAAkB,CAAC,CAO7B"}
|
package/dist/analyzer.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Analysis High-Level API
|
|
3
|
+
* Provides easy-to-use functions for common analysis tasks
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { CODE_EXTENSIONS, IGNORE_DIRS } from './types.js';
|
|
8
|
+
import { RLMOrchestrator } from './orchestrator.js';
|
|
9
|
+
import { getAnalysisPrompt } from './prompts.js';
|
|
10
|
+
/** Default maximum file size in bytes (100KB) */
|
|
11
|
+
export const DEFAULT_MAX_FILE_SIZE = 100_000;
|
|
12
|
+
/** Default analysis type when not specified */
|
|
13
|
+
export const DEFAULT_ANALYSIS_TYPE = 'summary';
|
|
14
|
+
/**
|
|
15
|
+
* Load files from a directory
|
|
16
|
+
*/
|
|
17
|
+
export function loadFiles(directory, options = {}) {
|
|
18
|
+
const files = {};
|
|
19
|
+
const maxSize = options.maxFileSize || DEFAULT_MAX_FILE_SIZE;
|
|
20
|
+
const includeExts = options.include || CODE_EXTENSIONS;
|
|
21
|
+
const excludeDirs = [...IGNORE_DIRS, ...(options.exclude || [])];
|
|
22
|
+
function shouldInclude(filePath) {
|
|
23
|
+
const ext = path.extname(filePath);
|
|
24
|
+
return includeExts.some(e => ext === e || filePath.endsWith(e));
|
|
25
|
+
}
|
|
26
|
+
function walk(dir) {
|
|
27
|
+
try {
|
|
28
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const fullPath = path.join(dir, entry.name);
|
|
31
|
+
const relativePath = path.relative(directory, fullPath);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (!excludeDirs.includes(entry.name)) {
|
|
34
|
+
walk(fullPath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (entry.isFile() && shouldInclude(entry.name)) {
|
|
38
|
+
try {
|
|
39
|
+
const stats = fs.statSync(fullPath);
|
|
40
|
+
if (stats.size <= maxSize) {
|
|
41
|
+
files[relativePath] = fs.readFileSync(fullPath, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Skip unreadable files
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Skip unreadable directories
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
walk(directory);
|
|
55
|
+
return files;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Analyze a codebase with custom query
|
|
59
|
+
*/
|
|
60
|
+
export async function analyzeCodebase(options) {
|
|
61
|
+
const files = loadFiles(options.directory, {
|
|
62
|
+
include: options.include,
|
|
63
|
+
exclude: options.exclude,
|
|
64
|
+
});
|
|
65
|
+
const fileCount = Object.keys(files).length;
|
|
66
|
+
const analysisType = options.analysisType || DEFAULT_ANALYSIS_TYPE;
|
|
67
|
+
if (fileCount === 0) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
answer: null,
|
|
71
|
+
turns: [],
|
|
72
|
+
executionTimeMs: 0,
|
|
73
|
+
subCallCount: 0,
|
|
74
|
+
filesAnalyzed: [],
|
|
75
|
+
analysisType,
|
|
76
|
+
error: 'No files found to analyze',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const query = options.query || getAnalysisPrompt(analysisType);
|
|
80
|
+
const orchestratorConfig = options.model ? { rootModel: options.model, subModel: options.model } : {};
|
|
81
|
+
const orchestrator = new RLMOrchestrator(orchestratorConfig, options.verbose);
|
|
82
|
+
const result = await orchestrator.processQuery(query, { files, variables: {}, mode: 'code-analysis' }, options.onTurnComplete);
|
|
83
|
+
return {
|
|
84
|
+
...result,
|
|
85
|
+
filesAnalyzed: Object.keys(files),
|
|
86
|
+
analysisType,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Analyze architecture
|
|
91
|
+
*/
|
|
92
|
+
export async function analyzeArchitecture(directory, options = {}) {
|
|
93
|
+
return analyzeCodebase({
|
|
94
|
+
...options,
|
|
95
|
+
directory,
|
|
96
|
+
analysisType: 'architecture',
|
|
97
|
+
query: getAnalysisPrompt('architecture'),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Analyze dependencies
|
|
102
|
+
*/
|
|
103
|
+
export async function analyzeDependencies(directory, options = {}) {
|
|
104
|
+
return analyzeCodebase({
|
|
105
|
+
...options,
|
|
106
|
+
directory,
|
|
107
|
+
analysisType: 'dependencies',
|
|
108
|
+
query: getAnalysisPrompt('dependencies'),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Analyze security
|
|
113
|
+
*/
|
|
114
|
+
export async function analyzeSecurity(directory, options = {}) {
|
|
115
|
+
return analyzeCodebase({
|
|
116
|
+
...options,
|
|
117
|
+
directory,
|
|
118
|
+
analysisType: 'security',
|
|
119
|
+
query: getAnalysisPrompt('security'),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Analyze performance
|
|
124
|
+
*/
|
|
125
|
+
export async function analyzePerformance(directory, options = {}) {
|
|
126
|
+
return analyzeCodebase({
|
|
127
|
+
...options,
|
|
128
|
+
directory,
|
|
129
|
+
analysisType: 'performance',
|
|
130
|
+
query: getAnalysisPrompt('performance'),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Analyze refactoring opportunities
|
|
135
|
+
*/
|
|
136
|
+
export async function analyzeRefactoring(directory, options = {}) {
|
|
137
|
+
return analyzeCodebase({
|
|
138
|
+
...options,
|
|
139
|
+
directory,
|
|
140
|
+
analysisType: 'refactor',
|
|
141
|
+
query: getAnalysisPrompt('refactor'),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get codebase summary
|
|
146
|
+
*/
|
|
147
|
+
export async function summarizeCodebase(directory, options = {}) {
|
|
148
|
+
return analyzeCodebase({
|
|
149
|
+
...options,
|
|
150
|
+
directory,
|
|
151
|
+
analysisType: 'summary',
|
|
152
|
+
query: getAnalysisPrompt('summary'),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Find usages of a symbol
|
|
157
|
+
*/
|
|
158
|
+
export async function findUsages(directory, symbolName, options = {}) {
|
|
159
|
+
const query = `Find all usages of "${symbolName}" in the codebase.
|
|
160
|
+
For each usage, provide:
|
|
161
|
+
1. File path
|
|
162
|
+
2. Line context (the relevant code)
|
|
163
|
+
3. Usage type (definition, import, call, reference)
|
|
164
|
+
|
|
165
|
+
Group by file and explain how the symbol is used in each location.`;
|
|
166
|
+
return analyzeCodebase({
|
|
167
|
+
...options,
|
|
168
|
+
directory,
|
|
169
|
+
analysisType: 'custom',
|
|
170
|
+
query,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Explain a specific file
|
|
175
|
+
*/
|
|
176
|
+
export async function explainFile(filePath, options = {}) {
|
|
177
|
+
const directory = path.dirname(filePath);
|
|
178
|
+
const fileName = path.basename(filePath);
|
|
179
|
+
const query = `Explain the file "${fileName}" in detail:
|
|
180
|
+
1. Purpose and responsibility
|
|
181
|
+
2. Main exports (functions, classes, types)
|
|
182
|
+
3. Dependencies and imports
|
|
183
|
+
4. Key logic and algorithms
|
|
184
|
+
5. How it fits into the broader codebase`;
|
|
185
|
+
return analyzeCodebase({
|
|
186
|
+
...options,
|
|
187
|
+
directory,
|
|
188
|
+
analysisType: 'custom',
|
|
189
|
+
query,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Ask a custom question about the codebase
|
|
194
|
+
*/
|
|
195
|
+
export async function askQuestion(directory, question, options = {}) {
|
|
196
|
+
return analyzeCodebase({
|
|
197
|
+
...options,
|
|
198
|
+
directory,
|
|
199
|
+
analysisType: 'custom',
|
|
200
|
+
query: question,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,iDAAiD;AACjD,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAE7C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAkB,CAAC;AAExD;;GAEG;AACH,MAAM,UAAU,SAAS,CACvB,SAAiB,EACjB,UAII,EAAE;IAEN,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,IAAI,qBAAqB,CA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UAAwC,EAAE;IAE1C,OAAO,eAAe,CAAC;QACrB,GAAG,OAAO;QACV,SAAS;QACT,YAAY,EAAE,QAAQ;QACtB,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* RLM Analyzer CLI
|
|
4
|
+
* Command-line interface for code analysis
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* rlm <command> [options]
|
|
8
|
+
*
|
|
9
|
+
* Commands:
|
|
10
|
+
* summary Get a codebase summary
|
|
11
|
+
* arch Analyze architecture
|
|
12
|
+
* deps Analyze dependencies
|
|
13
|
+
* security Security analysis
|
|
14
|
+
* perf Performance analysis
|
|
15
|
+
* refactor Find refactoring opportunities
|
|
16
|
+
* find Find symbol usages
|
|
17
|
+
* explain Explain a file
|
|
18
|
+
* ask Ask a custom question
|
|
19
|
+
* config Configure API key
|
|
20
|
+
*
|
|
21
|
+
* Options:
|
|
22
|
+
* --dir, -d Directory to analyze (default: current)
|
|
23
|
+
* --verbose, -v Show detailed output
|
|
24
|
+
* --json Output as JSON
|
|
25
|
+
* --help, -h Show help
|
|
26
|
+
*/
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
|